Repository navigation
Description
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:
node --some-flag --some-other-flag foo bar --baz
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-flagtakes a value, so--some-flag --some-other-flag fooare for node, the script isbar, and--bazis inprocess.argv;--some-other-flagdoes not take a value, so--some-flag --some-other-flagare for node, the script isfoo, andbar --bazis 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:
function splitArgs(allArgs) {
let nodeArgs = [];
let scriptName;
let scriptArgs = [];
let i = 0;
while (i < allArgs.length && allArgs[i][0] === "-") {
nodeArgs.push(allArgs[i]);
if (process.allowedNodeEnvironmentFlags.get(allArgs[i])) nodeArgs.push(allArgs[++i]);
i++;
}
scriptName = allArgs[i++];
while (i < allArgs.length) scriptArgs.push(allArgs[i++]);
return { nodeArgs, scriptName, scriptArgs };
}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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsAwaiting Triage
Activity
targos commentedon Jul 31, 2024
Another issue with
process.allowedNodeEnvironmentFlagsfor your use case is that it doesn't include all flags supported by Node.js, but only those which can be set inNODE_OPTIONSjoyeecheung commentedon Aug 1, 2024
We internally currently have
require('internal/options').getCLIOptionsInfo()which generates something like this to the JS landI 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:
process.allowedNodeEnvironmentFlagsAPI because the V8 flags are very unstable and they were worried about the maintenance burden, see process: add allowedNodeEnvironmentFlags property #19335).defaultIsTrueis an ad-hoc thing for boolean options, there are some options with alternative default values that may be set programically in the C++ land and it may be harder to ensure keeping them represented in JS land. The default values should be left out from a public API for now until we refactor this properly somehow to make the default values more deterministic.--helpand to buildprocess.allowedNodeEnvironmentFlags, but I suspect there might be other future use of this, so copies would be safer).joyeecheung commentedon Aug 1, 2024
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
NODE_OPTIONSin the form ofprocess.allowedNodeEnvironmentFlags. Although the internal API for this was only split out recently in #52451 but it could've been split all along. Is there a specific reason why we chose to provide a more restricted API? I can't seem to find in #19335 maybe @boneskull still remembers (though it's from many years ago)boneskull commentedon Aug 1, 2024
It's for
NODE_OPTIONS, specifically.Because if we're talking about env vars, they all have "values" (even if that value is
'1'), so it didn't matter.@nicolo-ribaudo Take a look at e.g.
c8ormocha, both of which do something like what you're doing.github-actions commentedon Jan 29, 2025
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-staleIssues and PRs exempt from automated stale handling.
label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
github-actions commentedon Feb 28, 2025
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.
For more information on how the project manages feature requests, please consult the feature request management document.