Skip to content

Commit

Permalink
fix: escape node.__dirname (#8172)
Browse files Browse the repository at this point in the history
  • Loading branch information
inottn authored Oct 20, 2024
1 parent 539b10f commit e616982
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl JavascriptParserPlugin for NodeStuffPlugin {
.push(Box::new(ConstDependency::new(
ident.span.real_lo(),
ident.span.real_hi(),
format!("'{dirname}'").into(),
serde_json::to_string(&dirname)
.expect("should render dirname")
.into(),
None,
)));
return Some(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.dirname = __dirname;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it("should define __dirname", function() {
expect(require("./dir1/dir2/file").dirname).toMatch(/^dir1[\\\/]dir2$/);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
node: {
__dirname: true
}
};

2 comments on commit e616982

@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-10-20 539b10f) Current Change
10000_development-mode + exec 2.12 s ± 25 ms 2.11 s ± 26 ms -0.31 %
10000_development-mode_hmr + exec 668 ms ± 9.3 ms 667 ms ± 15 ms -0.06 %
10000_production-mode + exec 2.66 s ± 24 ms 2.68 s ± 58 ms +0.56 %
arco-pro_development-mode + exec 1.78 s ± 57 ms 1.78 s ± 63 ms -0.39 %
arco-pro_development-mode_hmr + exec 426 ms ± 2.3 ms 426 ms ± 2.6 ms -0.03 %
arco-pro_production-mode + exec 3.23 s ± 79 ms 3.2 s ± 85 ms -0.73 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.25 s ± 71 ms 3.31 s ± 44 ms +1.65 %
threejs_development-mode_10x + exec 1.6 s ± 18 ms 1.61 s ± 22 ms +0.62 %
threejs_development-mode_10x_hmr + exec 763 ms ± 10 ms 756 ms ± 11 ms -0.96 %
threejs_production-mode_10x + exec 4.99 s ± 36 ms 4.98 s ± 35 ms -0.20 %

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

Please sign in to comment.