-
-
Notifications
You must be signed in to change notification settings - Fork 36k
process: generate list of allowed env flags programmatically #22638
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aec3668
process: generate list of allowed env flags programmatically
addaleax f05091c
fixup! process: generate list of allowed env flags programmatically
addaleax 0002b1e
lib: generate allowedNodeEnvironmentFlags lazily
addaleax 1f37916
fixup! process: generate list of allowed env flags programmatically
addaleax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
process: generate list of allowed env flags programmatically
Avoids having a separate, second source of truth on this matter.
- Loading branch information
commit aec3668e1cb41f846fa8dfebd42ab58b9c870dec
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -663,9 +663,42 @@ | |
| const test = Function.call.bind(RegExp.prototype.test); | ||
|
|
||
| const { | ||
| allowedV8EnvironmentFlags, | ||
| allowedNodeEnvironmentFlags | ||
| } = process.binding('config'); | ||
| getOptions, | ||
| types: { kV8Option }, | ||
| envSettings: { kAllowedInEnvironment } | ||
| } = internalBinding('options'); | ||
| const { options, aliases } = getOptions(); | ||
| const allowedV8EnvironmentFlags = | ||
| [...options].filter(([name, info]) => | ||
| info.type === kV8Option && | ||
| info.envVarSettings === kAllowedInEnvironment) | ||
| .map(([name]) => name); | ||
| const allowedNodeEnvironmentFlags = | ||
| [...options].filter(([name, info]) => | ||
| info.type !== kV8Option && | ||
| info.envVarSettings === kAllowedInEnvironment) | ||
| .map(([name]) => name); | ||
|
|
||
| for (const [ from, expansion ] of aliases) { | ||
| let isAccepted = true; | ||
| for (const to of expansion) { | ||
| if (!to.startsWith('-')) continue; | ||
| if (aliases.get(to)) { | ||
| expansion.push(...aliases.get(to)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: retrieving the value multiple times is not necessary. |
||
| continue; | ||
| } | ||
| isAccepted = options.get(to).envVarSettings === kAllowedInEnvironment; | ||
| if (!isAccepted) break; | ||
| } | ||
| if (isAccepted) { | ||
| let canonical = from; | ||
| if (canonical.endsWith('=')) | ||
| canonical = canonical.substr(0, canonical.length - 1); | ||
| if (canonical.endsWith(' <arg>')) | ||
| canonical = canonical.substr(0, canonical.length - 4); | ||
| allowedNodeEnvironmentFlags.push(canonical); | ||
| } | ||
| } | ||
|
|
||
| const trimLeadingDashes = (flag) => replace(flag, leadingDashesRegex, ''); | ||
|
|
||
|
|
@@ -703,6 +736,9 @@ | |
| // permutations of a flag, including present/missing leading | ||
| // dash(es) and/or underscores-for-dashes in the case of V8-specific | ||
| // flags. Strips any values after `=`, inclusive. | ||
| // TODO(addaleax): It might be more flexible to run the option parser | ||
| // on a dummy option set and see whether it rejects the argument or | ||
| // not. | ||
| if (typeof key === 'string') { | ||
| key = replace(key, trailingValuesRegex, ''); | ||
| if (test(leadingDashesRegex, key)) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to pass through filter options into
getOptionsinstead of doing the filtering here.Since it has a string option at the moment, it would likely be best to accept an object for the options instead.
Another alternative to the current way would be to only iterate once over the entries (this is also nicer to read for me):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve gone with the second option for now, but yes, ultimately it might be better to do this in C++ land.