Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member

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.


* `option` {string}
* Returns: {any}
Comment thread
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'));

@jasnell jasnell Jan 29, 2023 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 object. For instance,

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 process.options is not; as well as just being a bit easier.

```

```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
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
process.getOptionValue = getOptionValue;
process.getOptionValue = function getOptionValue(option) {
require('internal/validators').validateString(option, 'option');
return getOptionValue(option);
};

}

function addReadOnlyProcessAlias(name, option, enumerable = true) {
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-process-getOptionValue.js
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']);