mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Fixes #19652 ## Summary Fixes a crash that occurred when using the `--production` flag with `bun build`, particularly on Windows where assertions are enabled in release builds. ## Root Cause The crash occurred because an assertion for `jsx.development` was running **before** `jsx.development` was properly configured. The problematic sequence was: 1. Set `NODE_ENV=production` in env map 2. Call `configureDefines()` which reads `NODE_ENV` and calls `setProduction(true)`, setting `jsx.development=false` 3. ❌ **Assert `jsx.development` is false** (assertion fired here, before line 203 below) 4. Set `jsx.development = !production` on line 203 (too late) ## Changes This PR reorders the code to move the assertion **after** `jsx.development` is properly set: 1. Set both `BUN_ENV` and `NODE_ENV` to `"production"` in env map 2. Call `configureDefines()` 3. Set `jsx.development = !production` (now happens first) 4. ✅ **Assert `jsx.development` is false** (now runs after it's set) Also adds `BUN_ENV=production` to match the behavior of setting `NODE_ENV`. ## Test Plan Added regression test in `test/regression/issue/19652.test.ts` that verifies `bun build --production` doesn't crash. The test: - ✅ Passes on this branch - ❌ Would fail on main (assertion failure) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
20 lines
498 B
TypeScript
20 lines
498 B
TypeScript
import { expect, test } from "bun:test";
|
|
import { bunEnv, bunExe, tempDir } from "harness";
|
|
|
|
test("bun build --production does not crash (issue #19652)", async () => {
|
|
using dir = tempDir("19652", {
|
|
"tsconfig.json": "{}",
|
|
"index.js": `console.log("hello");`,
|
|
});
|
|
|
|
const result = Bun.spawnSync({
|
|
cmd: [bunExe(), "build", "index.js", "--production"],
|
|
env: bunEnv,
|
|
cwd: String(dir),
|
|
stdout: "inherit",
|
|
stderr: "inherit",
|
|
});
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
});
|