-
Notifications
You must be signed in to change notification settings - Fork 50
feat: Allow to configure bundleSizeOptimizations
#428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c87d6f9
feat: Allow to configure `bundleSizeOptimizations`
mydea e435c0d
PR feedback
mydea b08f9ff
fix whitespace tests
mydea efa198e
fix expected checks
mydea a653af5
make bundle size optimization tests less flaky
mydea 2b593f3
fix esbuild plugin
mydea 8df41d8
minor perf refactor
mydea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...es/integration-tests/fixtures/bundle-size-optimizations/bundle-size-optimizations.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* eslint-disable jest/no-standalone-expect */ | ||
| /* eslint-disable jest/expect-expect */ | ||
| import path from "path"; | ||
| import fs from "fs"; | ||
| import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; | ||
|
|
||
| const expectedOutputs: Record<string, Record<string, string>> = { | ||
| esbuild: { | ||
| "bundle1.js": `console.log(1)`, | ||
| "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"})`, | ||
| }, | ||
| rollup: { | ||
| "bundle1.js": `console.log(1 );`, | ||
| "bundle2.js": `console.log({ | ||
| debug: "b", | ||
| trace: "b", | ||
| replayCanvas: "a" , | ||
| replayIframe: "a" , | ||
| replayShadowDom: "a" , | ||
| });`, | ||
| }, | ||
| vite: { | ||
| "bundle1.js": `console.log(1);`, | ||
| "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"});`, | ||
| }, | ||
| webpack4: { | ||
| "bundle1.js": `console.log(1)`, | ||
| "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"})`, | ||
| }, | ||
| webpack5: { | ||
| "bundle1.js": `console.log(1)`, | ||
| "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"});`, | ||
| }, | ||
| }; | ||
|
|
||
| function checkBundle(bundler: string, bundlePath: string): void { | ||
| const actualPath = path.join(__dirname, "out", bundler, bundlePath); | ||
|
|
||
| // We replace multiple whitespaces with a single space for consistency | ||
| const actual = fs.readFileSync(actualPath, "utf-8").replace(/\s+/gim, " "); | ||
| const expected = expectedOutputs[bundler]?.[bundlePath]?.replace(/\s+/gim, " "); | ||
|
|
||
| expect(actual).toContain(expected); | ||
| } | ||
|
|
||
| test("esbuild bundle", () => { | ||
| checkBundle("esbuild", "bundle1.js"); | ||
| checkBundle("esbuild", "bundle2.js"); | ||
| }); | ||
|
|
||
| test("rollup bundle", () => { | ||
| checkBundle("rollup", "bundle1.js"); | ||
| checkBundle("rollup", "bundle2.js"); | ||
| }); | ||
|
|
||
| test("vite bundle", () => { | ||
| checkBundle("vite", "bundle1.js"); | ||
| checkBundle("vite", "bundle2.js"); | ||
| }); | ||
|
|
||
| testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { | ||
| checkBundle("webpack4", "bundle1.js"); | ||
| checkBundle("webpack4", "bundle2.js"); | ||
| }); | ||
|
|
||
| test("webpack 5 bundle", () => { | ||
| checkBundle("webpack5", "bundle1.js"); | ||
| checkBundle("webpack5", "bundle2.js"); | ||
| }); |
9 changes: 9 additions & 0 deletions
9
packages/integration-tests/fixtures/bundle-size-optimizations/input/bundle1.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| if (__SENTRY_DEBUG__ && Math.random() > 0.5) { | ||
| console.log("was > 0.5"); | ||
| } | ||
|
|
||
| if (__SENTRY_DEBUG__ && __RRWEB_EXCLUDE_CANVAS__) { | ||
| console.log("debug & exclude"); | ||
| } | ||
|
|
||
| console.log(__RRWEB_EXCLUDE_CANVAS__ ? 1 : 2); |
7 changes: 7 additions & 0 deletions
7
packages/integration-tests/fixtures/bundle-size-optimizations/input/bundle2.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| console.log({ | ||
| debug: __SENTRY_DEBUG__ ? "a" : "b", | ||
| trace: __SENTRY_TRACE__ ? "a" : "b", | ||
| replayCanvas: __RRWEB_EXCLUDE_CANVAS__ ? "a" : "b", | ||
| replayIframe: __RRWEB_EXCLUDE_IFRAME__ ? "a" : "b", | ||
| replayShadowDom: __RRWEB_EXCLUDE_SHADOW_DOM__ ? "a" : "b", | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is nice!