Add NODE_OPTIONS environment variable support

This adds support for the NODE_OPTIONS environment variable, which works
as a fallback to BUN_OPTIONS. This improves Node.js compatibility by
allowing users and tools to set command-line options via NODE_OPTIONS,
which is a standard Node.js feature.

Implementation:
- Added NODE_OPTIONS to src/env_var.zig
- Updated src/bun.zig to check BUN_OPTIONS first, then fall back to
  NODE_OPTIONS using the orelse operator
- BUN_OPTIONS takes precedence when both are set
- Added comprehensive tests for NODE_OPTIONS behavior
- Updated documentation to explain the relationship between the two

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2025-10-29 09:59:04 +00:00
parent eb77bdd286
commit 4a4edae9ad
4 changed files with 64 additions and 1 deletions

View File

@@ -69,3 +69,60 @@ describe("BUN_OPTIONS environment variable", () => {
expect(result.stdout.toString()).toContain("NORMAL");
});
});
describe("NODE_OPTIONS environment variable", () => {
test("basic usage - passes options to bun command", () => {
const result = spawnSync({
cmd: [bunExe()],
env: {
...bunEnv,
NODE_OPTIONS: "--print='NODE_OPTIONS WAS A SUCCESS'",
},
});
expect(result.exitCode).toBe(0);
expect(result.stdout.toString()).toContain("NODE_OPTIONS WAS A SUCCESS");
});
test("multiple options - passes all options to bun command", () => {
const result = spawnSync({
cmd: [bunExe()],
env: {
...bunEnv,
NODE_OPTIONS: "--print='MULTIPLE OPTIONS' --quiet",
},
});
expect(result.exitCode).toBe(0);
expect(result.stdout.toString()).toContain("MULTIPLE OPTIONS");
});
test("BUN_OPTIONS takes precedence over NODE_OPTIONS", () => {
const result = spawnSync({
cmd: [bunExe()],
env: {
...bunEnv,
NODE_OPTIONS: "--print='NODE'",
BUN_OPTIONS: "--print='BUN'",
},
});
expect(result.exitCode).toBe(0);
expect(result.stdout.toString()).toContain("BUN");
expect(result.stdout.toString()).not.toContain("NODE");
});
test("NODE_OPTIONS works when BUN_OPTIONS is not set", () => {
const result = spawnSync({
cmd: [bunExe()],
env: {
...bunEnv,
NODE_OPTIONS: "--print='FALLBACK TO NODE_OPTIONS'",
BUN_OPTIONS: undefined,
},
});
expect(result.exitCode).toBe(0);
expect(result.stdout.toString()).toContain("FALLBACK TO NODE_OPTIONS");
});
});