GeezerVison is showing github.com — fix: dedupe extracted comments in linear time (#682) · webpack/minimizer-webpack-plugin@06bda34
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +5Lines changed: 5 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +--- | | 2 | +"minimizer-webpack-plugin": patch | | 3 | +--- | | 4 | + | | 5 | +deduplicate extracted comments in linear time, so builds stay fast when an asset contains many distinct preserved comments |
Collapse file Copy file name to clipboardExpand all lines: .github/workflows/nodejs.yml +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -118,6 +118,22 @@ jobs: | 118 | 118 | if: matrix.node-version == '14.x' || matrix.node-version == '16.x' | 119 | 119 | run: npm install -D --no-save cssnano@^6 --force | 120 | 120 |
| | 121 | + - name: Pin terser to the locked version (Node 10/12/14) | | 122 | + # npm 6 (bundled with Node <= 14) can't read the lockfileVersion 3 | | 123 | + # package-lock.json, so the install step re-resolves `terser` to the | | 124 | + # latest match of its range instead of the locked version (and | | 125 | + # rewrites package-lock.json to v1 in the process). A newer terser | | 126 | + # changes the minified output, which breaks the snapshots. Read the | | 127 | + # locked version from the pristine committed lockfile and reinstall | | 128 | + # that exact version so these rows match the snapshots. | | 129 | + if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x' | | 130 | + shell: bash | | 131 | + run: | | | 132 | + git show HEAD:package-lock.json > pristine-package-lock.json | | 133 | + TERSER_VERSION="$(node -e "process.stdout.write(require('./pristine-package-lock.json').packages['node_modules/terser'].version)")" | | 134 | + rm -f pristine-package-lock.json | | 135 | + npm install -D --no-save --ignore-scripts --force "terser@${TERSER_VERSION}" | | 136 | +
| 121 | 137 | - name: Install webpack ${{ matrix.webpack-version }} | 122 | 138 | if: matrix.webpack-version != 'latest' | 123 | 139 | run: npm i webpack@${{ matrix.webpack-version }} | |
Collapse file Copy file name to clipboard +16-4Lines changed: 16 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // The bundled CSS minimizers (`cssnano@7`, `@swc/css`, `lightningcss`, | 2 | 2 | | 3 | 3 | // Windows agents. Skip the dedicated CSS test file outright on rows that | 4 | | -// can't run them so we don't end up with stale or missing snapshots. | | 4 | +// can't run them so we don't end up with stale or missing snapshots. The | | 5 | +// `@swc/html` minimizers require Node >= 14, so the dedicated swc-html file | | 6 | +// is skipped on older Node for the same reason. | 5 | 7 | const NODE_MAJOR = Number(process.versions.node.split(".")[0]); | 6 | 8 | const IS_WINDOWS = process.platform === "win32"; | 7 | 9 | const RUN_CSS_TESTS = NODE_MAJOR >= 18 && !IS_WINDOWS; | | 10 | +const RUN_SWC_HTML_TESTS = NODE_MAJOR >= 14; | | 11 | + | | 12 | +const testPathIgnorePatterns = []; | | 13 | + | | 14 | +if (!RUN_CSS_TESTS) { | | 15 | + testPathIgnorePatterns.push("/test/css-minify-option\\.test\\.js$"); | | 16 | +} | | 17 | + | | 18 | +if (!RUN_SWC_HTML_TESTS) { | | 19 | + testPathIgnorePatterns.push("/test/swc-html-minify-option\\.test\\.js$"); | | 20 | +} | 8 | 21 |
| 9 | 22 | module.exports = { | 10 | 23 | testEnvironment: "node", | @@ -13,7 +26,6 @@ module.exports = { | 13 | 26 | // routinely take longer than that. | 14 | 27 | testTimeout: 60000, | 15 | 28 | coveragePathIgnorePatterns: ["src/serialize-javascript.js"], | 16 | | - testPathIgnorePatterns: RUN_CSS_TESTS | 17 | | - ? [] | 18 | | - : ["/test/css-minify-option\\.test\\.js$"], | | 29 | + snapshotSerializers: ["<rootDir>/test/helpers/snapshotHashSerializer.js"], | | 30 | + testPathIgnorePatterns, | 19 | 31 | }; |
Collapse file Copy file name to clipboardExpand all lines: package-lock.json +53-36Lines changed: 53 additions & 36 deletions Collapse file Copy file name to clipboardExpand all lines: package.json +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 116 | 116 | "serialize-javascript": "^7.0.5", | 117 | 117 | "typescript": "^6.0.3", | 118 | 118 | "uglify-js": "^3.19.3", | 119 | | - "webpack": "^5.101.0", | | 119 | + "webpack": "^5.107.2", | 120 | 120 | "webpack-cli": "^4.10.0", | 121 | 121 | "worker-loader": "^3.0.8" | 122 | 122 | }, | |
Collapse file Copy file name to clipboardExpand all lines: src/utils.js +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -223,6 +223,8 @@ async function terserMinify( | 223 | 223 |
| 224 | 224 | // Redefine the comments function to extract and preserve | 225 | 225 | // comments according to the two conditions | | 226 | + const seenComments = new Set(extractedComments); | | 227 | + | 226 | 228 | return (astNode, comment) => { | 227 | 229 | if ( | 228 | 230 | /** @type {{ extract: ExtractCommentsFunction }} */ | @@ -234,7 +236,8 @@ async function terserMinify( | 234 | 236 | : `//${comment.value}`; | 235 | 237 |
| 236 | 238 | // Don't include duplicate comments | 237 | | - if (!extractedComments.includes(commentText)) { | | 239 | + if (!seenComments.has(commentText)) { | | 240 | + seenComments.add(commentText); | 238 | 241 | extractedComments.push(commentText); | 239 | 242 | } | 240 | 243 | } | @@ -477,6 +480,8 @@ async function uglifyJsMinify( | 477 | 480 |
| 478 | 481 | // Redefine the comments function to extract and preserve | 479 | 482 | // comments according to the two conditions | | 483 | + const seenComments = new Set(extractedComments); | | 484 | + | 480 | 485 | return (astNode, comment) => { | 481 | 486 | if ( | 482 | 487 | /** @type {{ extract: ExtractCommentsFunction }} */ | @@ -488,7 +493,8 @@ async function uglifyJsMinify( | 488 | 493 | : `//${comment.value}`; | 489 | 494 |
| 490 | 495 | // Don't include duplicate comments | 491 | | - if (!extractedComments.includes(commentText)) { | | 496 | + if (!seenComments.has(commentText)) { | | 497 | + seenComments.add(commentText); | 492 | 498 | extractedComments.push(commentText); | 493 | 499 | } | 494 | 500 | } | |
|