Skip to content

Commit

Permalink
fix: transform nested webpack require with innerGraph enabled (#8908)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng authored Dec 31, 2024
1 parent c2d74d5 commit 5cc9bae
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ impl JavascriptParserPlugin for CompatibilityPlugin {
decl: &swc_core::ecma::ast::VarDeclarator,
_statement: &swc_core::ecma::ast::VarDecl,
) -> Option<bool> {
if let Some(ident) = decl.name.as_ident()
&& ident.sym.as_str() == RuntimeGlobals::REQUIRE.name()
{
let ident = decl.name.as_ident()?;

if ident.sym.as_str() == RuntimeGlobals::REQUIRE.name() {
let start = ident.span().real_lo();
let end = ident.span().real_hi();
self.tag_nested_require_data(
Expand All @@ -111,7 +111,17 @@ impl JavascriptParserPlugin for CompatibilityPlugin {
end,
);
return Some(true);
} else if ident.sym == RuntimeGlobals::EXPORTS.name() {
self.tag_nested_require_data(
parser,
ident.sym.to_string(),
"__nested_webpack_exports__".to_string(),
ident.span().real_lo(),
ident.span().real_hi(),
);
return Some(true);
}

None
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("./lib");
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var __webpack_exports__ = {};
__webpack_exports__.e = 42;

it("rename top level (avoid override by inner graph top level symbol)", () => {
expect(__webpack_exports__.e).toBe(42);
const lib2 = require("./lib2");
expect(lib2.a).toBe(1)
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const a = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
mode: "production",
optimization: {
innerGraph: true,
}
}

1 comment on commit 5cc9bae

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 5cc9bae Dec 31, 2024

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-12-31 d3ce023) Current Change
10000_big_production-mode_disable-minimize + exec 37.6 s ± 466 ms 37.6 s ± 169 ms -0.00 %
10000_development-mode + exec 1.92 s ± 37 ms 1.84 s ± 23 ms -4.07 %
10000_development-mode_hmr + exec 676 ms ± 5.4 ms 674 ms ± 3.6 ms -0.31 %
10000_production-mode + exec 2.51 s ± 30 ms 2.46 s ± 42 ms -1.65 %
arco-pro_development-mode + exec 1.79 s ± 81 ms 1.75 s ± 64 ms -2.03 %
arco-pro_development-mode_hmr + exec 376 ms ± 1.8 ms 377 ms ± 0.93 ms +0.18 %
arco-pro_production-mode + exec 3.68 s ± 93 ms 3.55 s ± 86 ms -3.47 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.7 s ± 141 ms 3.59 s ± 67 ms -2.79 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.65 s ± 90 ms 3.56 s ± 125 ms -2.34 %
threejs_development-mode_10x + exec 1.51 s ± 26 ms 1.51 s ± 48 ms -0.11 %
threejs_development-mode_10x_hmr + exec 780 ms ± 37 ms 754 ms ± 11 ms -3.27 %
threejs_production-mode_10x + exec 5.38 s ± 170 ms 5.35 s ± 120 ms -0.52 %
10000_big_production-mode_disable-minimize + rss memory 9495 MiB ± 179 MiB 9512 MiB ± 59.2 MiB +0.18 %
10000_development-mode + rss memory 663 MiB ± 18.7 MiB 690 MiB ± 11.7 MiB +4.03 %
10000_development-mode_hmr + rss memory 1447 MiB ± 510 MiB 1471 MiB ± 250 MiB +1.65 %
10000_production-mode + rss memory 615 MiB ± 25.8 MiB 684 MiB ± 31.7 MiB +11.29 %
arco-pro_development-mode + rss memory 572 MiB ± 28.2 MiB 605 MiB ± 43 MiB +5.80 %
arco-pro_development-mode_hmr + rss memory 617 MiB ± 73.9 MiB 634 MiB ± 68.2 MiB +2.72 %
arco-pro_production-mode + rss memory 751 MiB ± 58.2 MiB 741 MiB ± 72.9 MiB -1.33 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 762 MiB ± 32.1 MiB 742 MiB ± 42.5 MiB -2.63 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 746 MiB ± 62.1 MiB 749 MiB ± 50.4 MiB +0.41 %
threejs_development-mode_10x + rss memory 609 MiB ± 20.9 MiB 616 MiB ± 28.2 MiB +1.09 %
threejs_development-mode_10x_hmr + rss memory 1167 MiB ± 34.9 MiB 1143 MiB ± 266 MiB -2.02 %
threejs_production-mode_10x + rss memory 863 MiB ± 49.7 MiB 894 MiB ± 32.3 MiB +3.50 %

Please sign in to comment.