mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(node): Include "node" condition during CJS re-export analysis (#25785)
Fixes #25777. We were missing the "node" condition, so we were resolving to the wrong conditional export, causing our analysis to be incorrect.
This commit is contained in:
parent
4b022103a1
commit
9be8dce0c7
13 changed files with 67 additions and 1 deletions
|
@ -196,7 +196,7 @@ impl<TCjsCodeAnalyzer: CjsCodeAnalyzer, TNodeResolverEnv: NodeResolverEnv>
|
|||
&referrer,
|
||||
// FIXME(bartlomieju): check if these conditions are okay, probably
|
||||
// should be `deno-require`, because `deno` is already used in `esm_resolver.rs`
|
||||
&["deno", "require", "default"],
|
||||
&["deno", "node", "require", "default"],
|
||||
NodeResolutionMode::Execution,
|
||||
);
|
||||
let reexport_specifier = match result {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
hello: "bad"
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
hello: "from node"
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
export default {
|
||||
hello: "default export"
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "@denotest/conditional-exports",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"node": "./good.cjs",
|
||||
"require": "./bad.js",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./*": "./*"
|
||||
}
|
||||
}
|
7
tests/registry/npm/@denotest/mjs-reexport-cjs/1.0.0/dist/package.cjs.js
vendored
Normal file
7
tests/registry/npm/@denotest/mjs-reexport-cjs/1.0.0/dist/package.cjs.js
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
const pkg = require("@denotest/conditional-exports-node");
|
||||
|
||||
Object.keys(pkg).forEach(function (k) {
|
||||
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = pkg[k];
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
module.exports = require('./dist/package.cjs.js')
|
|
@ -0,0 +1 @@
|
|||
export * from "./index.js";
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "@denotest/mjs-reexport-cjs",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@denotest/conditional-exports-node": "*"
|
||||
},
|
||||
"exports": {
|
||||
"node": "./index.mjs",
|
||||
"default": "./index.js"
|
||||
}
|
||||
}
|
13
tests/specs/node/cjs_reexport_node_condition/__test__.jsonc
Normal file
13
tests/specs/node/cjs_reexport_node_condition/__test__.jsonc
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"tempDir": true,
|
||||
"steps": [
|
||||
{
|
||||
"args": "install",
|
||||
"output": "[WILDCARD]"
|
||||
},
|
||||
{
|
||||
"args": "run -A ./main.ts",
|
||||
"output": "from node\n"
|
||||
}
|
||||
]
|
||||
}
|
3
tests/specs/node/cjs_reexport_node_condition/deno.json
Normal file
3
tests/specs/node/cjs_reexport_node_condition/deno.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"nodeModulesDir": "manual"
|
||||
}
|
3
tests/specs/node/cjs_reexport_node_condition/main.ts
Normal file
3
tests/specs/node/cjs_reexport_node_condition/main.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { hello } from "@denotest/mjs-reexport-cjs";
|
||||
|
||||
console.log(hello);
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"@denotest/mjs-reexport-cjs": "*"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue