Skip to content

Commit 2a1e11f

Browse files
committed
feat: move nerfDart list into @npmcli/config
1 parent cab74ff commit 2a1e11f

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

lib/commands/config.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,11 @@ const { spawn } = require('node:child_process')
44
const { EOL } = require('node:os')
55
const localeCompare = require('@isaacs/string-locale-compare')('en')
66
const pkgJson = require('@npmcli/package-json')
7-
const { defaults, definitions } = require('@npmcli/config/lib/definitions')
7+
const { defaults, definitions, nerfDarts } = require('@npmcli/config/lib/definitions')
88
const { log, output } = require('proc-log')
99
const BaseCommand = require('../base-cmd.js')
1010
const { redact } = require('@npmcli/redact')
1111

12-
// These are the configs that we can nerf-dart. Not all of them currently even
13-
// *have* config definitions so we have to explicitly validate them here.
14-
// This is used to validate during "npm config set"
15-
const nerfDarts = [
16-
'_auth',
17-
'_authToken',
18-
'_password',
19-
'certfile',
20-
'email',
21-
'keyfile',
22-
'username',
23-
]
2412
// These are the config values to swap with "protected". It does not catch
2513
// every single sensitive thing a user may put in the npmrc file but it gets
2614
// the common ones. This is distinct from nerfDarts because that is used to
@@ -125,7 +113,7 @@ class Config extends BaseCommand {
125113
const action = argv[2]
126114
switch (action) {
127115
case 'set':
128-
// todo: complete with valid values, if possible.
116+
// TODO: complete with valid values, if possible.
129117
if (argv.length > 3) {
130118
return []
131119
}

lib/npm.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { resolve, dirname, join } = require('node:path')
22
const Config = require('@npmcli/config')
33
const which = require('which')
44
const fs = require('node:fs/promises')
5-
const { definitions, flatten, shorthands } = require('@npmcli/config/lib/definitions')
5+
const { definitions, flatten, nerfDarts, shorthands } = require('@npmcli/config/lib/definitions')
66
const usage = require('./utils/npm-usage.js')
77
const LogFile = require('./utils/log-file.js')
88
const Timers = require('./utils/timers.js')
@@ -68,6 +68,7 @@ class Npm {
6868
npmPath: this.#npmRoot,
6969
definitions,
7070
flatten,
71+
nerfDarts,
7172
shorthands,
7273
argv: [...process.argv, ...argv],
7374
excludeNpmCwd,

workspaces/config/lib/definitions/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,22 @@ const shorthands = {
5858
...definitionProps.shorthands,
5959
}
6060

61+
// These are the configs that we can nerf-dart. Only _auth even has a config definition so we have to explicitly validate them here.
62+
// This is used to validate during "npm config set" and to not warn on loading unknown configs when we see these.
63+
const nerfDarts = [
64+
'_auth', // Has a config
65+
'_authToken', // Does not have a config
66+
'_password', // Does not have a config
67+
'certfile', // Does not have a config
68+
'email', // Does not have a config
69+
'keyfile', // Does not have a config
70+
'username', // Does not have a config
71+
]
72+
6173
module.exports = {
6274
defaults: definitionProps.defaults,
6375
definitions,
6476
flatten,
77+
nerfDarts,
6578
shorthands,
6679
}

workspaces/config/lib/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Config {
6161
definitions,
6262
shorthands,
6363
flatten,
64+
nerfDarts = [],
6465
npmPath,
6566

6667
// options just to override in tests, mostly
@@ -71,8 +72,9 @@ class Config {
7172
cwd = process.cwd(),
7273
excludeNpmCwd = false,
7374
}) {
74-
// turn the definitions into nopt's weirdo syntax
75+
this.nerfDarts = nerfDarts
7576
this.definitions = definitions
77+
// turn the definitions into nopt's weirdo syntax
7678
const types = {}
7779
const defaults = {}
7880
this.deprecated = {}
@@ -572,7 +574,6 @@ class Config {
572574
}
573575

574576
#checkDeprecated (key) {
575-
// XXX(npm9+) make this throw an error
576577
if (this.deprecated[key]) {
577578
log.warn('config', key, this.deprecated[key])
578579
}

0 commit comments

Comments
 (0)