From d44108a8768505cc44227a25e7a6160f85f576db Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Sun, 29 Jan 2023 20:49:33 +0900 Subject: [PATCH] lib: expose getOptionValue via process Add `process.getOptionValue` that exposes `getOptionValue` in `internal/options`. Fixes: https://github.com/nodejs/node/issues/36935 --- doc/api/process.md | 43 ++++++++++++++++++++ lib/internal/process/pre_execution.js | 2 + test/parallel/test-process-getOptionValue.js | 11 +++++ 3 files changed, 56 insertions(+) create mode 100644 test/parallel/test-process-getOptionValue.js diff --git a/doc/api/process.md b/doc/api/process.md index 4a4a60c2735d..6b8f74efe55e 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -2009,6 +2009,49 @@ if (process.getgroups) { This function is only available on POSIX platforms (i.e. not Windows or Android). +## `process.getOptionValue(option)` + + + +> Stability: 1 - Experimental + +* `option` {string} +* Returns: {any} + +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')); +``` + +```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()`