Skip to content

Commit

Permalink
fix(node-stuff): use more conventional shim method (#7587)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Aug 15, 2024
1 parent 8e283eb commit 378b75e
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl JavascriptParserPlugin for NodeStuffPlugin {
"node-module" => {
// `ExternalModuleDependency` extends `CachedConstDependency` in webpack.
// We need to create two separate dependencies in Rspack.
let external_dep = ExternalModuleDependency::new(
let external_url_dep = ExternalModuleDependency::new(
"url".to_string(),
vec![(
"fileURLToPath".to_string(),
Expand All @@ -40,18 +40,27 @@ impl JavascriptParserPlugin for NodeStuffPlugin {
None,
);

let external_path_dep = ExternalModuleDependency::new(
"path".to_string(),
vec![("dirname".to_string(), "__webpack_dirname__".to_string())],
None,
);

let const_dep = CachedConstDependency::new(
ident.span.real_lo(),
ident.span.real_hi(),
DIR_NAME.into(),
"__webpack_fileURLToPath__(import.meta.url + '/..').slice(0, -1)"
"__webpack_dirname__(__webpack_fileURLToPath__(import.meta.url))"
.to_string()
.into(),
);

parser
.presentational_dependencies
.push(Box::new(external_dep));
.push(Box::new(external_url_dep));
parser
.presentational_dependencies
.push(Box::new(external_path_dep));
parser.presentational_dependencies.push(Box::new(const_dep));
return Some(true);
}
Expand Down

2 comments on commit 378b75e

@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-08-15 5271a8b) Current Change
10000_development-mode + exec 2.31 s ± 16 ms 2.34 s ± 34 ms +1.36 %
10000_development-mode_hmr + exec 697 ms ± 6.7 ms 724 ms ± 6.3 ms +3.81 %
10000_production-mode + exec 2.85 s ± 37 ms 3.03 s ± 22 ms +6.18 %
arco-pro_development-mode + exec 1.88 s ± 77 ms 1.91 s ± 75 ms +1.98 %
arco-pro_development-mode_hmr + exec 433 ms ± 2.7 ms 439 ms ± 3.3 ms +1.55 %
arco-pro_production-mode + exec 3.43 s ± 72 ms 3.48 s ± 95 ms +1.70 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.49 s ± 75 ms 3.58 s ± 50 ms +2.56 %
threejs_development-mode_10x + exec 1.68 s ± 15 ms 1.72 s ± 14 ms +2.27 %
threejs_development-mode_10x_hmr + exec 797 ms ± 1.8 ms 824 ms ± 8.3 ms +3.37 %
threejs_production-mode_10x + exec 5.48 s ± 28 ms 5.55 s ± 28 ms +1.29 %

Threshold exceeded: ["10000_production-mode + exec"]

@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 ❌ failure
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rsbuild ✅ success
examples ❌ failure

Please sign in to comment.