Skip to content

Commit

Permalink
fix: escape node.__dirname (web-infra-dev#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
}
};

0 comments on commit e616982

Please sign in to comment.