oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
72.83k stars 2.64k forks source link

bun --eval ignores first command line arg #12209

Open cjmalloy opened 2 months ago

cjmalloy commented 2 months ago

What version of Bun is running?

1.1.17+bb66bba1b

What platform is your computer?

Linux 5.4.0-186-generic x86_64 x86_64

What steps can reproduce the bug?

chris@eggnog:~$ bun -e "console.log(process.argv)" 1 2 3
[ "/home/chris/.bun/bin/bun", "/home/chris/[eval]", "2", "3" ]
chris@eggnog:~$ node -e "console.log(process.argv)" 1 2 3
[ '/home/chris/.nvm/versions/node/v20.14.0/bin/node', '1', '2', '3' ]
chris@eggnog:~$ bun --version
1.1.17

What is the expected behavior?

Should match node and not ignore the first argument.

What do you see instead?

First argument missing.

Additional information

Similarly for bun --print.

My workaround is to just include a placeholder arg and modify argv:

chris@eggnog:~$ bun -e "process.argv.splice(1, 1); console.log(process.argv)" skip 1 2 3
[ "/home/chris/.bun/bin/bun", "1", "2", "3" ]
chris@eggnog:~$ node -e "process.argv.splice(1, 1); console.log(process.argv)" skip 1 2 3
[ '/home/chris/.nvm/versions/node/v20.14.0/bin/node', '1', '2', '3' ]
mookums commented 2 months ago

Is this available? I can work on this.

svallory commented 1 week ago

+1 to getting this fixed. Still an issue in 1.1.24 :(

svallory commented 1 week ago

As a workaround, I just found out that taking code from stdin works :)

> echo "console.log(Bun.argv)" | bun run - 1 2 3
[ "/Users/svallory/.proto/tools/bun/1.1.24/bun", "/Volumes/projects/dfx/[stdin]",
  "1", "2", "3"
]