Skip to content

Commit

Permalink
fix: swc minimizer extracted comments should be stable (#6380)
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a authored Apr 26, 2024
1 parent e403e3f commit e4fdc75
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/rspack_plugin_swc_js_minimizer/src/minify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ pub fn minify(

// if not matched comments, we don't need to emit .License.txt file
if !extracted_comments.is_empty() {
extracted_comments.sort();
all_extract_comments
.lock()
.expect("all_extract_comments lock failed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,28 @@ div {
"
`;
exports[`ConfigTestCases optimization minimizer-swc-extract-comments exported tests should keep the extracted license file stable 1`] = `
"/**
* bar
* @license MIT
*/
/**
* baz
* @license MIT
*/
/**
* foo
* @license MIT
*/
/**
* relative
* @license MIT
*/"
`;
exports[`ConfigTestCases plugins chunk-modules exported tests chunk-modules 1`] = `
Object {
"515": Object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require("fs")
const path = require("path")
it("should keep the extracted license file stable", () => {
require("foo")
require("bar")
require("baz")
require("./relative")
expect(fs.readFileSync(path.join(__dirname, "bundle0.js.LICENSE.txt"), "utf8")).toMatchSnapshot()
})

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

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

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

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

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* relative
* @license MIT
*/
module.exports = "relative"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { SwcJsMinimizerRspackPlugin, SwcCssMinimizerRspackPlugin } = require("@rspack/core")

/**
* @type {import("@rspack/core").Configuration}
*/
module.exports = {
optimization: {
minimize: true,
minimizer: [
new SwcJsMinimizerRspackPlugin({
extractComments: {},
format: {
comments: "all"
}
}),
]
}
}

2 comments on commit e4fdc75

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs, self-hosted, Linux, ci ❌ failure
_selftest, ubuntu-latest ✅ success
nx, ubuntu-latest ✅ success
rspress, ubuntu-latest ✅ success
rsbuild, ubuntu-latest ✅ success
compat, ubuntu-latest ✅ success
examples, ubuntu-latest ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-04-26 0c04972) Current Change
10000_development-mode + exec 2.75 s ± 31 ms 2.77 s ± 43 ms +0.72 %
10000_development-mode_hmr + exec 700 ms ± 3.2 ms 688 ms ± 13 ms -1.76 %
10000_production-mode + exec 2.53 s ± 28 ms 2.57 s ± 55 ms +1.43 %
arco-pro_development-mode + exec 2.51 s ± 85 ms 2.5 s ± 65 ms -0.35 %
arco-pro_development-mode_hmr + exec 430 ms ± 1.1 ms 431 ms ± 3.1 ms +0.42 %
arco-pro_development-mode_hmr_intercept-plugin + exec 442 ms ± 2.3 ms 443 ms ± 3.7 ms +0.30 %
arco-pro_development-mode_intercept-plugin + exec 3.25 s ± 76 ms 3.26 s ± 87 ms +0.39 %
arco-pro_production-mode + exec 3.96 s ± 76 ms 3.95 s ± 91 ms -0.40 %
arco-pro_production-mode_intercept-plugin + exec 4.72 s ± 52 ms 4.7 s ± 58 ms -0.37 %
threejs_development-mode_10x + exec 2.05 s ± 20 ms 2.08 s ± 23 ms +1.38 %
threejs_development-mode_10x_hmr + exec 748 ms ± 12 ms 764 ms ± 21 ms +2.09 %
threejs_production-mode_10x + exec 5.23 s ± 19 ms 5.33 s ± 35 ms +1.96 %

Please sign in to comment.