mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 04:49:06 +00:00
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:
57
test/cli/env/bun-options.test.ts
vendored
57
test/cli/env/bun-options.test.ts
vendored
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user