babashka / nbb

Scripting in Clojure on Node.js using SCI
Eclipse Public License 1.0
863 stars 52 forks source link

nbb intercepts some cli args and sends them to node and to the program #371

Closed kanaka closed 2 hours ago

kanaka commented 2 hours ago

version

1.3.195

platform

Ubuntu 22.04 and node v20.11.1

problem

nbb is passing some command line arguments to node before also passing them to the program itself. This is probably a misbehavior but if it's intentional, then there should be a way to avoid this using the "--" separator.

repro

$ cat args.cljs
(prn :args *command-line-args*)
$ ./node_modules/.bin/nbb args.cljs  --arg1 val1 a b c
:args ("--arg1" "val1" "a" "b" "c")
$ ./node_modules/.bin/nbb args.cljs --env-file .env --arg1 val1 a b c
node: .env: not found
$ ./node_modules/.bin/nbb args.cljs -- --env-file .env --arg1 val1 a b c
node: .env: not found
$ touch .env
$ ./node_modules/.bin/nbb args.cljs --env-file .env --arg1 val1 a b c
:args ("--env-file" ".env" "--arg1" "val1" "a" "b" "c")

expected behavior

The --env-file option should only apply to the program and not be passed to node. Or, if that's intended, then at least the "--" separator should stop that behavior.

borkdude commented 2 hours ago

@kanaka I think this is a bug in Node.js itself. Given this script:

scratch.mjs:

console.log(process.argv);

and when I call it with:

node scratch.mjs --env-file .env

I see:

$ node scratch.mjs --env-file .env
node: .env: not found
borkdude commented 2 hours ago

Note that nbb doesn't call node, node calls nbb. So there's nothing I can do about this.

borkdude commented 2 hours ago

This seems to be fixed in a later version of Node. I tested with 22.9.0 and there it works.

kanaka commented 2 hours ago

Yeah, I had just discovered the same thing. Thanks for the quick followup.