Skip to content

Commit 1317a36

Browse files
authored
fix(bundle): don't use createRequire when targeting browser in Deno.bundle (#31534)
Fixes #31524 Missed a code path in the original fix
1 parent b18b834 commit 1317a36

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

cli/tools/bundle/provider.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ impl BundleProvider for CliBundleProvider {
173173
super::process_result(
174174
&result,
175175
&bundler.cwd,
176-
true,
176+
crate::tools::bundle::should_replace_require_shim(
177+
bundle_flags.platform,
178+
),
177179
bundle_flags.minify,
178180
bundler.input,
179181
bundle_flags.output_dir.as_ref().map(Path::new),
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"tempDir": true,
3+
"tests": {
4+
"api": {
5+
"steps": [
6+
{
7+
"args": "run --unstable-bundle bundle.ts",
8+
"output": "[WILDCARD]"
9+
},
10+
{
11+
"args": "run -A has-createrequire.ts bundle.js",
12+
"output": "false\n"
13+
}
14+
]
15+
},
16+
"cli": {
17+
"steps": [
18+
{
19+
"args": "bundle --platform browser --output bundle.js foo.cjs",
20+
"output": "[WILDCARD]"
21+
},
22+
{
23+
"args": "run -A has-createrequire.ts bundle.js",
24+
"output": "false\n"
25+
}
26+
]
27+
}
28+
}
29+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
await Deno.bundle({
2+
entrypoints: ["./foo.cjs"],
3+
platform: "browser",
4+
outputPath: "bundle.js",
5+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let arch;
2+
if (typeof globalThis.window !== "undefined") {
3+
const os = require("node:os");
4+
arch = os.arch;
5+
} else {
6+
arch = "browser";
7+
}
8+
module.exports = {
9+
hi: "hi",
10+
arch,
11+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const file = Deno.args[0];
2+
3+
const contents = Deno.readTextFileSync(file);
4+
5+
if (contents.includes("createRequire")) {
6+
console.log("true");
7+
} else {
8+
console.log("false");
9+
}

0 commit comments

Comments
 (0)