diff --git a/src/options.zig b/src/options.zig index 91dd09cb53..3cc113073d 100644 --- a/src/options.zig +++ b/src/options.zig @@ -1511,7 +1511,6 @@ pub fn definesFromTransformOptions( })); } - // Set process.isBun to true for DCE when target is bun if (!user_defines.contains("process.isBun")) { _ = try environment_defines.getOrPutValue("process.isBun", .init(.{ .valueless = false, diff --git a/test/bundler/esbuild/dce.test.ts b/test/bundler/esbuild/dce.test.ts index 0e67d3a550..a2d8a565a8 100644 --- a/test/bundler/esbuild/dce.test.ts +++ b/test/bundler/esbuild/dce.test.ts @@ -3401,4 +3401,29 @@ describe("bundler", () => { // "/project/node_modules/pkg/styles.css": `button { color: red }`, // }, // }); + + itBundled("dce/ProcessIsBunTargetBun", { + files: { + "/entry.js": /* js */ ` + if (process.isBun) { + console.log("BUN_CODE"); + function bunOnlyFunction() { + return "bun-specific"; + } + console.log(bunOnlyFunction()); + } else { + console.log("NODE_CODE"); + function nodeOnlyFunction() { + return "node-specific"; + } + console.log(nodeOnlyFunction()); + } + `, + }, + target: "bun", + dce: true, + run: { + stdout: "BUN_CODE\nbun-specific", + }, + }); });