Skip to content

Commit c3e3de0

Browse files
authored
fix: js api module readable identifier (#10929)
1 parent a4eeed4 commit c3e3de0

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

crates/rspack_binding_api/src/module.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,11 @@ impl Module {
304304
impl Module {
305305
#[napi]
306306
pub fn readable_identifier(&mut self) -> napi::Result<String> {
307-
let (_, module) = self.as_ref()?;
307+
let (compilation, module) = self.as_ref()?;
308308
Ok(
309309
module
310-
.get_context()
311-
.map(|ctx| module.readable_identifier(ctx.as_ref()).to_string())
312-
.unwrap_or_default(),
310+
.readable_identifier(&compilation.options.context)
311+
.to_string(),
313312
)
314313
}
315314

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("bar");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "foo";
2+
import "./bar"

packages/rspack-test-tools/tests/configCases/normal-module/readable-identifier/node_modules/foo/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/rspack-test-tools/tests/configCases/normal-module/readable-identifier/node_modules/foo/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const path = require("path");
2+
3+
class Plugin {
4+
/**
5+
* @param {import("@rspack/core").Compiler} compiler
6+
*/
7+
apply(compiler) {
8+
compiler.hooks.finishMake.tap("PLUGIN", compilation => {
9+
for (const module of compilation.modules) {
10+
if (module.resource === path.join(__dirname, "bar.js")) {
11+
expect(module.readableIdentifier()).toBe("./bar.js");
12+
}
13+
if (module.resource === path.join(__dirname, "node_modules/foo/index.js")) {
14+
expect(module.readableIdentifier()).toBe("./node_modules/foo/index.js");
15+
}
16+
}
17+
});
18+
}
19+
}
20+
21+
/** @type {import("@rspack/core").Configuration} */
22+
module.exports = {
23+
entry: "./index.js",
24+
plugins: [new Plugin()]
25+
};

0 commit comments

Comments
 (0)