mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
```ts
// a.js
console.log({
argv: process.argv,
execArgv: process.execArgv,
});
```
```diff
$> node a.js -a --b
{
argv: [
'/opt/homebrew/Cellar/node/24.2.0/bin/node',
'/tmp/a.js',
'-a',
'--b'
],
execArgv: []
}
$> bun a.js -a --b
{
argv: [ "/Users/pfg/.bun/bin/bun", "/tmp/a.js",
"-a", "--b"
],
execArgv: [],
}
$> bun build --compile a.js --outfile=a
[5ms] bundle 1 modules
[87ms] compile
$> ./a -a --b
{
argv: [ "bun", "/$bunfs/root/a", "-a", "--b" ],
- execArgv: [ "-a", "--b" ],
+ execArgv: [],
}
```
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
|
|
import { join } from "path";
|
|
|
|
test("process.execArgv should be empty in compiled executables", async () => {
|
|
const dir = tempDirWithFiles("process-execargv-compile", {
|
|
"check-execargv.js": `
|
|
console.log(JSON.stringify({
|
|
argv: process.argv,
|
|
execArgv: process.execArgv,
|
|
}));
|
|
`,
|
|
});
|
|
|
|
// First test regular execution - execArgv should be empty for script args
|
|
{
|
|
await using proc = Bun.spawn({
|
|
cmd: [bunExe(), join(dir, "check-execargv.js"), "-a", "--b"],
|
|
env: bunEnv,
|
|
cwd: dir,
|
|
stdout: "pipe",
|
|
});
|
|
|
|
const result = JSON.parse(await proc.stdout.text());
|
|
expect(result.execArgv).toEqual([]);
|
|
expect(result.argv).toContain("-a");
|
|
expect(result.argv).toContain("--b");
|
|
}
|
|
|
|
// Build compiled executable
|
|
{
|
|
await using buildProc = Bun.spawn({
|
|
cmd: [bunExe(), "build", "--compile", "check-execargv.js", "--outfile=check-execargv"],
|
|
env: bunEnv,
|
|
cwd: dir,
|
|
});
|
|
|
|
expect(await buildProc.exited).toBe(0);
|
|
}
|
|
|
|
// Test compiled executable - execArgv should be empty
|
|
{
|
|
await using proc = Bun.spawn({
|
|
cmd: [join(dir, "check-execargv"), "-a", "--b"],
|
|
env: bunEnv,
|
|
cwd: dir,
|
|
stdout: "pipe",
|
|
});
|
|
|
|
const result = JSON.parse(await proc.stdout.text());
|
|
|
|
// The fix: execArgv should be empty in compiled executables
|
|
expect(result.execArgv).toEqual([]);
|
|
|
|
// argv should still contain all arguments
|
|
expect(result.argv).toContain("-a");
|
|
expect(result.argv).toContain("--b");
|
|
}
|
|
});
|