fix(compile): apply BUN_OPTIONS env var to standalone executables (#26346)

## Summary
- Fixed `BUN_OPTIONS` environment variable not being applied as runtime
options for standalone executables (`bun build --compile`). Previously,
args from `BUN_OPTIONS` were incorrectly passed through to
`process.argv` instead of being parsed as Bun runtime options
(`process.execArgv`).
- Removed `BUN_CPU_PROFILE`, `BUN_CPU_PROFILE_DIR`, and
`BUN_CPU_PROFILE_NAME` env vars since `BUN_OPTIONS="--cpu-prof
--cpu-prof-dir=... --cpu-prof-name=..."` now works correctly with
standalone executables.
- Made `cpu_prof.name` and `cpu_prof.dir` non-optional with empty string
defaults.

fixes #21496

## Test plan
- [x] Added tests for `BUN_OPTIONS` with standalone executables (no
`compile-exec-argv`)
- [x] Added tests for `BUN_OPTIONS` combined with `--compile-exec-argv`
- [x] Added tests for `BUN_OPTIONS` with user passthrough args
- [x] Verified existing `compile-argv` tests still pass
- [x] Verified existing `bun-options` tests still pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude Bot <claude-bot@bun.sh>
This commit is contained in:
Dylan Conway
2026-01-23 00:24:18 -08:00
committed by GitHub
parent e8b2455f11
commit d8d8182e8e
8 changed files with 181 additions and 34 deletions

View File

@@ -276,4 +276,115 @@ describe("bundler", () => {
stdout: /APP_HELP:my custom help/,
},
});
// Test that BUN_OPTIONS env var is applied to standalone executables
itBundled("compile/BunOptionsEnvApplied", {
compile: true,
backend: "cli",
files: {
"/entry.ts": /* js */ `
console.log("execArgv:", JSON.stringify(process.execArgv));
console.log("argv:", JSON.stringify(process.argv));
if (process.execArgv.findIndex(arg => arg === "--smol") === -1) {
console.error("FAIL: --smol not found in execArgv:", process.execArgv);
process.exit(1);
}
// BUN_OPTIONS args should NOT appear in process.argv
for (const arg of process.argv) {
if (arg === "--smol") {
console.error("FAIL: --smol leaked into process.argv:", process.argv);
process.exit(1);
}
}
console.log("SUCCESS: BUN_OPTIONS applied to standalone executable");
`,
},
run: {
env: { BUN_OPTIONS: "--smol" },
stdout: /SUCCESS: BUN_OPTIONS applied to standalone executable/,
},
});
// Test BUN_OPTIONS combined with compile-exec-argv
itBundled("compile/BunOptionsEnvWithCompileExecArgv", {
compile: {
execArgv: ["--conditions=production"],
},
backend: "cli",
files: {
"/entry.ts": /* js */ `
console.log("execArgv:", JSON.stringify(process.execArgv));
console.log("argv:", JSON.stringify(process.argv));
if (process.execArgv.findIndex(arg => arg === "--conditions=production") === -1) {
console.error("FAIL: --conditions=production not found in execArgv:", process.execArgv);
process.exit(1);
}
if (process.execArgv.findIndex(arg => arg === "--smol") === -1) {
console.error("FAIL: --smol not found in execArgv:", process.execArgv);
process.exit(1);
}
// Neither BUN_OPTIONS nor compile-exec-argv args should be in process.argv
for (const arg of process.argv) {
if (arg === "--smol" || arg === "--conditions=production") {
console.error("FAIL: exec option leaked into process.argv:", arg);
process.exit(1);
}
}
console.log("SUCCESS: BUN_OPTIONS and compile-exec-argv both applied");
`,
},
run: {
env: { BUN_OPTIONS: "--smol" },
stdout: /SUCCESS: BUN_OPTIONS and compile-exec-argv both applied/,
},
});
// Test BUN_OPTIONS with user passthrough args
itBundled("compile/BunOptionsEnvWithPassthroughArgs", {
compile: true,
backend: "cli",
files: {
"/entry.ts": /* js */ `
console.log("execArgv:", JSON.stringify(process.execArgv));
console.log("argv:", JSON.stringify(process.argv));
if (process.execArgv.findIndex(arg => arg === "--smol") === -1) {
console.error("FAIL: --smol not found in execArgv:", process.execArgv);
process.exit(1);
}
if (process.argv.findIndex(arg => arg === "user-arg1") === -1) {
console.error("FAIL: user-arg1 not found in argv:", process.argv);
process.exit(1);
}
if (process.argv.findIndex(arg => arg === "user-arg2") === -1) {
console.error("FAIL: user-arg2 not found in argv:", process.argv);
process.exit(1);
}
// BUN_OPTIONS args should NOT be in process.argv
for (const arg of process.argv) {
if (arg === "--smol") {
console.error("FAIL: --smol leaked into process.argv:", process.argv);
process.exit(1);
}
}
console.log("SUCCESS: BUN_OPTIONS separated from passthrough args");
`,
},
run: {
env: { BUN_OPTIONS: "--smol" },
args: ["user-arg1", "user-arg2"],
stdout: /SUCCESS: BUN_OPTIONS separated from passthrough args/,
},
});
});