-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ext/node): resolve exports even if parent module filename isn't p…
…resent (#26553) Fixes #26505 I'm not exactly sure how this case comes about (I tried to write tests for it but couldn't manage to reproduce it), but what happens is the parent filename ends up null, and we bail out of resolving the specifier in package exports. I've checked, and in node the parent filename is also null (so that's not a bug on our part), but node continues to resolve even in that case. So this PR should match node's behavior more closely than we currently do.
- Loading branch information
1 parent
d284d1c
commit 68cee70
Showing
8 changed files
with
55 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
tests/registry/npm/@denotest/cjs-multiple-exports/1.0.0/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@denotest/cjs-multiple-exports", | ||
"version": "1.0.0", | ||
"exports": { | ||
".": "./src/index.js", | ||
"./add": "./src/add.js" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
tests/registry/npm/@denotest/cjs-multiple-exports/1.0.0/src/add.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function add(a, b) { | ||
return a + b; | ||
}; |
3 changes: 3 additions & 0 deletions
3
tests/registry/npm/@denotest/cjs-multiple-exports/1.0.0/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
hello: "world" | ||
}; |
13 changes: 13 additions & 0 deletions
13
tests/specs/node/require_export_from_parent_with_no_filename/__test__.jsonc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"tempDir": true, | ||
"steps": [ | ||
{ | ||
"args": "install", | ||
"output": "[WILDCARD]" | ||
}, | ||
{ | ||
"args": "run -A main.cjs", | ||
"output": "3\n" | ||
} | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/specs/node/require_export_from_parent_with_no_filename/main.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const path = require("node:path"); | ||
const Module = require("node:module"); | ||
function requireFromString(code, filename) { | ||
const paths = Module._nodeModulePaths((0, path.dirname)(filename)); | ||
const m = new Module(filename, module.parent); | ||
m.paths = paths; | ||
m._compile(code, filename); | ||
return m.exports; | ||
} | ||
|
||
const code = ` | ||
const add = require("@denotest/cjs-multiple-exports/add"); | ||
console.log(add(1, 2)); | ||
`; | ||
requireFromString(code, "fake.js"); |
5 changes: 5 additions & 0 deletions
5
tests/specs/node/require_export_from_parent_with_no_filename/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"@denotest/cjs-multiple-exports": "1.0.0" | ||
} | ||
} |