Skip to content

Commit 7b177e4

Browse files
committed
Add a 'envExport' flag for config definitions
It defaults to true, but setting it to any falsey value will tell `@npmcli/config` not to export it into the environment, and will also put a remark in the documentation that it is not exported. PR-URL: #3014 Credit: @isaacs Close: #3014 Reviewed-by: @nlf
1 parent 61da39b commit 7b177e4

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

docs/content/using-npm/config.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,8 @@ Valid values for the `workspace` config are either: - Workspace names - Path
13331333
to a workspace directory - Path to a parent workspace directory (will result
13341334
to selecting all of the nested workspaces)
13351335

1336+
This value is not exported to the environment for child processes.
1337+
13361338
#### `workspaces`
13371339

13381340
* Default: false
@@ -1341,6 +1343,8 @@ to selecting all of the nested workspaces)
13411343
Enable running a command in the context of **all** the configured
13421344
workspaces.
13431345

1346+
This value is not exported to the environment for child processes.
1347+
13441348
#### `yes`
13451349

13461350
* Default: null

lib/utils/config/definition.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const allowed = [
2525
'type',
2626
'typeDescription',
2727
'usage',
28+
'envExport',
2829
]
2930

3031
const {
@@ -39,6 +40,8 @@ const {
3940
class Definition {
4041
constructor (key, def) {
4142
this.key = key
43+
// if it's set falsey, don't export it, otherwise we do by default
44+
this.envExport = true
4245
Object.assign(this, def)
4346
this.validate()
4447
if (!this.defaultDescription)
@@ -68,6 +71,9 @@ class Definition {
6871
// a textual description of this config, suitable for help output
6972
describe () {
7073
const description = unindent(this.description)
74+
const noEnvExport = this.envExport ? '' : `
75+
This value is not exported to the environment for child processes.
76+
`
7177
const deprecated = !this.deprecated ? ''
7278
: `* DEPRECATED: ${unindent(this.deprecated)}\n`
7379
return wrapAll(`#### \`${this.key}\`
@@ -76,7 +82,7 @@ class Definition {
7682
* Type: ${unindent(this.typeDescription)}
7783
${deprecated}
7884
${description}
79-
`)
85+
${noEnvExport}`)
8086
}
8187
}
8288

lib/utils/config/definitions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,6 +2044,7 @@ define('workspace', {
20442044
type: [String, Array],
20452045
hint: '<workspace-name>',
20462046
short: 'w',
2047+
envExport: false,
20472048
description: `
20482049
Enable running a command in the context of the configured workspaces of the
20492050
current project while filtering by running only the workspaces defined by
@@ -2061,6 +2062,7 @@ define('workspaces', {
20612062
default: false,
20622063
type: Boolean,
20632064
short: 'ws',
2065+
envExport: false,
20642066
description: `
20652067
Enable running a command in the context of **all** the configured
20662068
workspaces.

tap-snapshots/test-lib-utils-config-describe-all.js-TAP.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,8 @@ Valid values for the \`workspace\` config are either: - Workspace names - Path
12121212
to a workspace directory - Path to a parent workspace directory (will result
12131213
to selecting all of the nested workspaces)
12141214
1215+
This value is not exported to the environment for child processes.
1216+
12151217
#### \`workspaces\`
12161218
12171219
* Default: false
@@ -1220,6 +1222,8 @@ to selecting all of the nested workspaces)
12201222
Enable running a command in the context of **all** the configured
12211223
workspaces.
12221224
1225+
This value is not exported to the environment for child processes.
1226+
12231227
#### \`yes\`
12241228
12251229
* Default: null

test/lib/utils/config/definition.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ t.test('basic definition', async t => {
2525
usage: '--key <key>',
2626
typeDescription: 'Number or String',
2727
description: 'just a test thingie',
28+
envExport: true,
2829
})
2930
t.matchSnapshot(def.describe(), 'human-readable description')
3031

@@ -119,6 +120,25 @@ t.test('basic definition', async t => {
119120
description: 'asdf',
120121
})
121122
t.equal(optionalBool.usage, '--key')
123+
124+
const noExported = new Definition('methane', {
125+
envExport: false,
126+
type: String,
127+
typeDescription: 'Greenhouse Gas',
128+
default: 'CH4',
129+
description: `
130+
This is bad for the environment, for our children, do not put it there.
131+
`,
132+
})
133+
t.equal(noExported.envExport, false, 'envExport flag is false')
134+
t.equal(noExported.describe(), `#### \`methane\`
135+
136+
* Default: "CH4"
137+
* Type: Greenhouse Gas
138+
139+
This is bad for the environment, for our children, do not put it there.
140+
141+
This value is not exported to the environment for child processes.`)
122142
})
123143

124144
t.test('missing fields', async t => {

0 commit comments

Comments
 (0)