1
0
Fork 0
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:
Nathan Whitaker 2024-09-21 16:10:38 -07:00 committed by GitHub
parent 4b022103a1
commit 9be8dce0c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 67 additions and 1 deletions

View file

@ -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 {

View file

@ -0,0 +1,3 @@
module.exports = {
hello: "bad"
};

View file

@ -0,0 +1,3 @@
module.exports = {
hello: "from node"
};

View file

@ -0,0 +1,3 @@
export default {
hello: "default export"
}

View file

@ -0,0 +1,13 @@
{
"name": "@denotest/conditional-exports",
"version": "1.0.0",
"type": "module",
"exports": {
".": {
"node": "./good.cjs",
"require": "./bad.js",
"default": "./index.js"
},
"./*": "./*"
}
}

View 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];
});

View file

@ -0,0 +1 @@
module.exports = require('./dist/package.cjs.js')

View file

@ -0,0 +1 @@
export * from "./index.js";

View file

@ -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"
}
}

View file

@ -0,0 +1,13 @@
{
"tempDir": true,
"steps": [
{
"args": "install",
"output": "[WILDCARD]"
},
{
"args": "run -A ./main.ts",
"output": "from node\n"
}
]
}

View file

@ -0,0 +1,3 @@
{
"nodeModulesDir": "manual"
}

View file

@ -0,0 +1,3 @@
import { hello } from "@denotest/mjs-reexport-cjs";
console.log(hello);

View file

@ -0,0 +1,5 @@
{
"dependencies": {
"@denotest/mjs-reexport-cjs": "*"
}
}