mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +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>
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { describe } from "bun:test";
|
|
import { itBundled } from "./expectBundled";
|
|
|
|
describe("bundler", () => {
|
|
itBundled("compile/ProcessExecArgvEmpty", {
|
|
compile: true,
|
|
files: {
|
|
"/entry.ts": /* js */ `
|
|
// In compiled executables, execArgv should be empty
|
|
// since arguments like "-a" and "--b" are for the script, not bun
|
|
if (process.execArgv.length !== 0) {
|
|
console.error("FAIL: execArgv should be empty but got:", process.execArgv);
|
|
process.exit(1);
|
|
}
|
|
|
|
// argv should contain all arguments including script arguments
|
|
if (!process.argv.includes("-a") || !process.argv.includes("--b")) {
|
|
console.error("FAIL: argv missing expected arguments:", process.argv);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log("PASS");
|
|
`,
|
|
},
|
|
run: {
|
|
stdout: "PASS",
|
|
args: ["-a", "--b"],
|
|
},
|
|
});
|
|
|
|
itBundled("compile/ProcessExecArgvWithComplexArgs", {
|
|
compile: true,
|
|
files: {
|
|
"/entry.ts": /* js */ `
|
|
// Test with various argument patterns
|
|
if (process.execArgv.length !== 0) {
|
|
console.error("FAIL: execArgv should be empty but got:", process.execArgv);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Check that all arguments are in argv
|
|
const expectedArgs = ["--verbose", "-p", "8080", "--config=test.json", "arg1", "arg2"];
|
|
let missingArgs = [];
|
|
|
|
for (const arg of expectedArgs) {
|
|
if (!process.argv.includes(arg)) {
|
|
missingArgs.push(arg);
|
|
}
|
|
}
|
|
|
|
if (missingArgs.length > 0) {
|
|
console.error("FAIL: argv missing arguments:", missingArgs);
|
|
console.error("Got argv:", process.argv);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log("PASS");
|
|
`,
|
|
},
|
|
run: {
|
|
stdout: "PASS",
|
|
args: ["--verbose", "-p", "8080", "--config=test.json", "arg1", "arg2"],
|
|
},
|
|
});
|
|
});
|