Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dedupe-extracted-comments-linear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"minimizer-webpack-plugin": patch
---

deduplicate extracted comments in linear time, so builds stay fast when an asset contains many distinct preserved comments
16 changes: 16 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ jobs:
if: matrix.node-version == '14.x' || matrix.node-version == '16.x'
run: npm install -D --no-save cssnano@^6 --force

- name: Pin terser to the locked version (Node 10/12/14)
# npm 6 (bundled with Node <= 14) can't read the lockfileVersion 3
# package-lock.json, so the install step re-resolves `terser` to the
# latest match of its range instead of the locked version (and
# rewrites package-lock.json to v1 in the process). A newer terser
# changes the minified output, which breaks the snapshots. Read the
# locked version from the pristine committed lockfile and reinstall
# that exact version so these rows match the snapshots.
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x'
shell: bash
run: |
git show HEAD:package-lock.json > pristine-package-lock.json
TERSER_VERSION="$(node -e "process.stdout.write(require('./pristine-package-lock.json').packages['node_modules/terser'].version)")"
rm -f pristine-package-lock.json
npm install -D --no-save --ignore-scripts --force "terser@${TERSER_VERSION}"

- name: Install webpack ${{ matrix.webpack-version }}
if: matrix.webpack-version != 'latest'
run: npm i webpack@${{ matrix.webpack-version }}
Expand Down
20 changes: 16 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
// The bundled CSS minimizers (`cssnano@7`, `@swc/css`, `lightningcss`,
// `esbuild@0.27`) require modern Node and don't reliably install on the
// Windows agents. Skip the dedicated CSS test file outright on rows that
// can't run them so we don't end up with stale or missing snapshots.
// can't run them so we don't end up with stale or missing snapshots. The
// `@swc/html` minimizers require Node >= 14, so the dedicated swc-html file
// is skipped on older Node for the same reason.
const NODE_MAJOR = Number(process.versions.node.split(".")[0]);
const IS_WINDOWS = process.platform === "win32";
const RUN_CSS_TESTS = NODE_MAJOR >= 18 && !IS_WINDOWS;
const RUN_SWC_HTML_TESTS = NODE_MAJOR >= 14;

const testPathIgnorePatterns = [];

if (!RUN_CSS_TESTS) {
testPathIgnorePatterns.push("/test/css-minify-option\\.test\\.js$");
}

if (!RUN_SWC_HTML_TESTS) {
testPathIgnorePatterns.push("/test/swc-html-minify-option\\.test\\.js$");
}

module.exports = {
testEnvironment: "node",
Expand All @@ -13,7 +26,6 @@ module.exports = {
// routinely take longer than that.
testTimeout: 60000,
coveragePathIgnorePatterns: ["src/serialize-javascript.js"],
testPathIgnorePatterns: RUN_CSS_TESTS
? []
: ["/test/css-minify-option\\.test\\.js$"],
snapshotSerializers: ["<rootDir>/test/helpers/snapshotHashSerializer.js"],
testPathIgnorePatterns,
};
89 changes: 53 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"serialize-javascript": "^7.0.5",
"typescript": "^6.0.3",
"uglify-js": "^3.19.3",
"webpack": "^5.101.0",
"webpack": "^5.107.2",
"webpack-cli": "^4.10.0",
"worker-loader": "^3.0.8"
},
Expand Down
10 changes: 8 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ async function terserMinify(

// Redefine the comments function to extract and preserve
// comments according to the two conditions
const seenComments = new Set(extractedComments);

return (astNode, comment) => {
if (
/** @type {{ extract: ExtractCommentsFunction }} */
Expand All @@ -234,7 +236,8 @@ async function terserMinify(
: `//${comment.value}`;

// Don't include duplicate comments
if (!extractedComments.includes(commentText)) {
if (!seenComments.has(commentText)) {
seenComments.add(commentText);
extractedComments.push(commentText);
}
}
Expand Down Expand Up @@ -477,6 +480,8 @@ async function uglifyJsMinify(

// Redefine the comments function to extract and preserve
// comments according to the two conditions
const seenComments = new Set(extractedComments);

return (astNode, comment) => {
if (
/** @type {{ extract: ExtractCommentsFunction }} */
Expand All @@ -488,7 +493,8 @@ async function uglifyJsMinify(
: `//${comment.value}`;

// Don't include duplicate comments
if (!extractedComments.includes(commentText)) {
if (!seenComments.has(commentText)) {
seenComments.add(commentText);
extractedComments.push(commentText);
}
}
Expand Down
Loading
Loading