mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
## Summary Fix a bug in `appendOptionsEnv` where bare flags (no `=`) that aren't the last option get a trailing space appended, causing the argument parser to not recognize them. For example, `BUN_OPTIONS="--cpu-prof --cpu-prof-dir=profiles"` would parse `--cpu-prof` as `"--cpu-prof "` (trailing space), so CPU profiling was never enabled. ## Root Cause When `appendOptionsEnv` encounters a `--flag` followed by whitespace, it advances past the whitespace looking for a possible quoted value (e.g. `--flag "quoted"`). If no quote is found and there's no `=`, it falls through without resetting `j`, so the emitted argument includes the trailing whitespace. ## Fix Save `end_of_flag = j` after scanning the flag name. Add an `else` branch that resets `j = end_of_flag` when no value (quote or `=`) is found after the whitespace. This is a 3-line change. Also fixes a separate bug in `BunCPUProfiler.zig` where `--cpu-prof-dir` with an absolute path would hit a debug assertion (`path.append` on an already-rooted path with an absolute input). Changed to `path.join` which handles both relative and absolute paths correctly. ## Tests - `test/cli/env/bun-options.test.ts`: Two new tests verifying `--cpu-prof --cpu-prof-dir=<abs-path>` produces a `.cpuprofile` file, for both normal and standalone compiled executables.