Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
f86041cb68 fix(bundler): don't inline NODE_ENV/BUN_ENV when env is "disable"
`Bun.build({ env: "disable" })` was still inlining `process.env.NODE_ENV`
and `process.env.BUN_ENV` because the NODE_ENV define block only checked
for `load_all_without_inlining`, not `disable`.

Closes #20183

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-19 09:20:23 +00:00
2 changed files with 20 additions and 1 deletions

View File

@@ -1483,7 +1483,7 @@ pub fn definesFromTransformOptions(
);
}
if (behavior != .load_all_without_inlining) {
if (behavior != .load_all_without_inlining and behavior != .disable) {
const quoted_node_env: string = brk: {
if (NODE_ENV) |node_env| {
if (node_env.len > 0) {

View File

@@ -65,6 +65,25 @@ for (let backend of ["api", "cli"] as const) {
},
});
// Test disable mode also prevents NODE_ENV and BUN_ENV from being inlined (#20183)
itBundled("env/disable-node-env", {
backend: backend,
dotenv: "disable",
files: {
"/a.js": `
console.log(process.env.NODE_ENV);
console.log(process.env.BUN_ENV);
`,
},
run: {
env: {
NODE_ENV: "production",
BUN_ENV: "production",
},
stdout: "production\nproduction\n",
},
});
// TODO: make this work as expected with process.env isntead of relying on the initial env vars.
// Test pattern matching - only vars with prefix are inlined
if (backend === "cli")