Skip to content

Commit b58cd0a

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.
1 parent 1267a41 commit b58cd0a

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)
@@ -67,6 +70,9 @@ class Definition {
6770
// a textual description of this config, suitable for help output
6871
describe () {
6972
const description = unindent(this.description)
73+
const noEnvExport = this.envExport ? '' : `
74+
This value is not exported to the environment for child processes.
75+
`
7076
const deprecated = !this.deprecated ? ''
7177
: `* DEPRECATED: ${unindent(this.deprecated)}\n`
7278
return wrapAll(`#### \`${this.key}\`
@@ -75,7 +81,7 @@ class Definition {
7581
* Type: ${unindent(this.typeDescription)}
7682
${deprecated}
7783
${description}
78-
`)
84+
${noEnvExport}`)
7985
}
8086
}
8187

lib/utils/config/definitions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,7 @@ define('workspace', {
20432043
default: [],
20442044
type: [String, Array],
20452045
short: 'w',
2046+
envExport: false,
20462047
description: `
20472048
Enable running a command in the context of the configured workspaces of the
20482049
current project while filtering by running only the workspaces defined by
@@ -2060,6 +2061,7 @@ define('workspaces', {
20602061
default: false,
20612062
type: Boolean,
20622063
short: 'ws',
2064+
envExport: false,
20632065
description: `
20642066
Enable running a command in the context of **all** the configured
20652067
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>|--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

@@ -113,6 +114,25 @@ t.test('basic definition', async t => {
113114
hint: '<testparam>',
114115
})
115116
t.equal(hasHint.usage, '--key <testparam>')
117+
118+
const noExported = new Definition('methane', {
119+
envExport: false,
120+
type: String,
121+
typeDescription: 'Greenhouse Gas',
122+
default: 'CH4',
123+
description: `
124+
This is bad for the environment, for our children, do not put it there.
125+
`,
126+
})
127+
t.equal(noExported.envExport, false, 'envExport flag is false')
128+
t.equal(noExported.describe(), `#### \`methane\`
129+
130+
* Default: "CH4"
131+
* Type: Greenhouse Gas
132+
133+
This is bad for the environment, for our children, do not put it there.
134+
135+
This value is not exported to the environment for child processes.`)
116136
})
117137

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

0 commit comments

Comments
 (0)