Repository navigation
lib: expose getOptionValue via process #46404
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2009,6 +2009,49 @@ if (process.getgroups) { | |
| This function is only available on POSIX platforms (i.e. not Windows or | ||
| Android). | ||
|
|
||
| ## `process.getOptionValue(option)` | ||
|
|
||
| <!-- YAML | ||
| added: REPLACEME | ||
| --> | ||
|
|
||
| > Stability: 1 - Experimental | ||
|
|
||
| * `option` {string} | ||
| * Returns: {any} | ||
|
jasnell marked this conversation as resolved.
|
||
|
|
||
| The `process.getOptionValue()` method returns the parsed value of | ||
| that command line option. This method respects [`NODE_OPTIONS`][] value. | ||
|
|
||
| For example, assuming the following script for `process-getoptionvalue.js`: | ||
|
|
||
| ```mjs | ||
| import process from 'node:process'; | ||
|
|
||
| console.log('--pending-deprecation:', process.getOptionValue('--pending-deprecation')); | ||
| console.log('--conditions:', process.getOptionValue('--conditions')); | ||
|
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. Consider this non-blocking but an alternative approach to implementing this would be to use constants on a process.options.pendingDeprecation
process.options.conditions
// ... or even
process.options['pending-deprecation']
process.options['conditions']I think this would help with @panva's concern in relation to experimental status since individual constants can be marked experimental while the |
||
| ``` | ||
|
|
||
| ```cjs | ||
| const process = require('node:process'); | ||
|
|
||
| console.log('--pending-deprecation:', process.getOptionValue('--pending-deprecation')); | ||
| console.log('--conditions:', process.getOptionValue('--conditions')); | ||
| ``` | ||
|
|
||
| Launching the Node.js process as: | ||
|
|
||
| ```console | ||
| $ node --pending-deprecation -C additional process-getoptionvalue.js | ||
| ``` | ||
|
|
||
| Would generate the output: | ||
|
|
||
| ```text | ||
| --pending-deprecation: true | ||
| --conditions: [ 'additional' ] | ||
| ``` | ||
|
|
||
| ## `process.getuid()` | ||
|
|
||
| <!-- YAML | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -178,6 +178,8 @@ function patchProcessObject(expandArgv1) { | |||||||||||
| addReadOnlyProcessAlias('traceDeprecation', '--trace-deprecation'); | ||||||||||||
| addReadOnlyProcessAlias('_breakFirstLine', '--inspect-brk', false); | ||||||||||||
| addReadOnlyProcessAlias('_breakNodeFirstLine', '--inspect-brk-node', false); | ||||||||||||
|
|
||||||||||||
| process.getOptionValue = getOptionValue; | ||||||||||||
|
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.
Suggested change
|
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function addReadOnlyProcessAlias(name, option, enumerable = true) { | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| 'use strict'; | ||
|
|
||
| // Flags: --pending-deprecation -C additional | ||
|
|
||
| require('../common'); | ||
| const assert = require('node:assert'); | ||
|
|
||
| // This test ensures that process.getOptionValue is exposed on process variable. | ||
|
|
||
| assert.strictEqual(process.getOptionValue('--pending-deprecation'), true); | ||
| assert.deepStrictEqual(process.getOptionValue('--conditions'), ['additional']); |
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.
Given the experimental nature of many of the individual options, wouldn't this be Experimental forever? Ergo, cannot be relied upon.