-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Programmatically expose whether a cli flag takes an argument or not #54144
Comments
Another issue with |
We internally currently have [Object: null prototype] {
options: SafeMap(182) [Map] {
'--disable-wasm-trap-handler' => [Object: null prototype] {
helpText: 'Disable trap-handler-based WebAssembly bound checks. V8 will insert inline bound checks when compiling WebAssembly which may slow down performance.',
envVarSettings: 0,
type: 2,
defaultIsTrue: false
},
'--track-heap-objects' => [Object: null prototype] {
helpText: 'track heap object allocations for heap snapshots',
envVarSettings: 0,
type: 2,
defaultIsTrue: false
},
...
},
aliases: SafeMap(24) [Map] {
'--debug-port' => [ '--inspect-port' ],
'-p' => [ '--print' ],
'--loader' => [ '--experimental-loader' ],
...
} I think it would be a good idea just expose some APIs to 'node:util' to return a copy/subset of the options map and maybe a different API to return a copy of the aliases too. Some caveats come to mind:
|
Actually now I looked at it it seems strange why we didn't just expose something similar to the JS land but chose to provide a set that's very specific to the ones allowed in |
It's for Because if we're talking about env vars, they all have "values" (even if that value is @nicolo-ribaudo Take a look at e.g. |
What is the problem this feature will solve?
I am trying to build a wrapper around the Node.js CLI, and for that I need to know which flags are meant to be passed to Node.js and which one should be passed to the script.
I was hoping that
process.allowedNodeEnvironmentFlags
would help with this, but unfortunately it's not enough. Consider this two commands:And assume that
process.allowedNodeEnvironmentFlags
includes--some-flag
and--some-other-flag
. What are the arguments being passed to node, and what to the script? which script?There are two possible answers:
--some-other-flag
takes a value, so--some-flag --some-other-flag foo
are for node, the script isbar
, and--baz
is inprocess.argv
;--some-other-flag
does not take a value, so--some-flag --some-other-flag
are for node, the script isfoo
, andbar --baz
is inprocess.argv
.What is the feature you are proposing to solve the problem?
Make
process.allowedNodeEnvironmentFlags
a map with boolean values telling whether the flag takes a value or not. The logic to use it would then become:For backward compatibility, this map should still have a no-op
.add
method.What alternatives have you considered?
I can hard-code the list. However, this means that for every new release I have to check if there is any change in the supported flags, and I have to maintain multiple lists one per version.
The maintenance cost for Node.js is much lower, given that new flags already have to be added to
process.allowedNodeEnvironmentFlags
anyway.The text was updated successfully, but these errors were encountered: