Skip to content

Commit d2963c6

Browse files
nlffritzy
authored andcommitted
feat: explicitly validate config within the cli
BREAKING CHANGE: the presence of auth related settings that are not scoped to a specific registry found in a config file is no longer supported and will throw errors
1 parent cee3fd9 commit d2963c6

File tree

19 files changed

+68
-54
lines changed

19 files changed

+68
-54
lines changed

lib/base-command.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class BaseCommand {
1111
constructor (npm) {
1212
this.wrapWidth = 80
1313
this.npm = npm
14+
15+
if (!this.skipConfigValidation) {
16+
this.npm.config.validate()
17+
}
1418
}
1519

1620
get name () {
@@ -25,6 +29,10 @@ class BaseCommand {
2529
return this.constructor.ignoreImplicitWorkspace
2630
}
2731

32+
get skipConfigValidation () {
33+
return this.constructor.skipConfigValidation
34+
}
35+
2836
get usage () {
2937
const usage = [
3038
`${this.constructor.description}`,

lib/commands/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class Config extends BaseCommand {
6363

6464
static ignoreImplicitWorkspace = false
6565

66+
static skipConfigValidation = true
67+
6668
async completion (opts) {
6769
const argv = opts.conf.argv.remain
6870
if (argv[1] !== 'config') {

tap-snapshots/test/lib/utils/exit-handler.js.test.cjs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,34 @@
77
'use strict'
88
exports[`test/lib/utils/exit-handler.js TAP handles unknown error with logs and debug file > debug file contents 1`] = `
99
0 timing npm:load:whichnode Completed in {TIME}ms
10-
15 timing config:load Completed in {TIME}ms
11-
16 timing npm:load:configload Completed in {TIME}ms
12-
17 timing npm:load:mkdirpcache Completed in {TIME}ms
13-
18 timing npm:load:mkdirplogs Completed in {TIME}ms
14-
19 verbose title npm
15-
20 verbose argv
16-
21 timing npm:load:setTitle Completed in {TIME}ms
17-
23 timing npm:load:display Completed in {TIME}ms
18-
24 verbose logfile logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-
19-
25 verbose logfile {CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log
20-
26 timing npm:load:logFile Completed in {TIME}ms
21-
27 timing npm:load:timers Completed in {TIME}ms
22-
28 timing npm:load:configScope Completed in {TIME}ms
23-
29 timing npm:load Completed in {TIME}ms
24-
30 silly logfile done cleaning log files
25-
31 verbose stack Error: Unknown error
26-
32 verbose cwd {CWD}
27-
33 verbose Foo 1.0.0
28-
34 verbose node v1.0.0
29-
35 verbose npm v1.0.0
30-
36 error code ECODE
31-
37 error ERR SUMMARY Unknown error
32-
38 error ERR DETAIL Unknown error
33-
39 verbose exit 1
34-
41 timing npm Completed in {TIME}ms
35-
42 verbose code 1
36-
43 error A complete log of this run can be found in:
37-
43 error {CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log
10+
13 timing config:load Completed in {TIME}ms
11+
14 timing npm:load:configload Completed in {TIME}ms
12+
15 timing npm:load:mkdirpcache Completed in {TIME}ms
13+
16 timing npm:load:mkdirplogs Completed in {TIME}ms
14+
17 verbose title npm
15+
18 verbose argv
16+
19 timing npm:load:setTitle Completed in {TIME}ms
17+
21 timing npm:load:display Completed in {TIME}ms
18+
22 verbose logfile logs-max:10 dir:{CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-
19+
23 verbose logfile {CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log
20+
24 timing npm:load:logFile Completed in {TIME}ms
21+
25 timing npm:load:timers Completed in {TIME}ms
22+
26 timing npm:load:configScope Completed in {TIME}ms
23+
27 timing npm:load Completed in {TIME}ms
24+
28 silly logfile done cleaning log files
25+
29 verbose stack Error: Unknown error
26+
30 verbose cwd {CWD}
27+
31 verbose Foo 1.0.0
28+
32 verbose node v1.0.0
29+
33 verbose npm v1.0.0
30+
34 error code ECODE
31+
35 error ERR SUMMARY Unknown error
32+
36 error ERR DETAIL Unknown error
33+
37 verbose exit 1
34+
39 timing npm Completed in {TIME}ms
35+
40 verbose code 1
36+
41 error A complete log of this run can be found in:
37+
41 error {CWD}/test/lib/utils/tap-testdir-exit-handler-handles-unknown-error-with-logs-and-debug-file/cache/_logs/{DATE}-debug-0.log
3838
`
3939

4040
exports[`test/lib/utils/exit-handler.js TAP handles unknown error with logs and debug file > logs 1`] = `

test/fixtures/mock-npm.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class MockNpm {
216216
}
217217
},
218218
list: [{ ...realConfig.defaults, ...config }],
219+
validate: () => {},
219220
}
220221

221222
if (t && config.loglevel) {

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ t.test('loading as main module will load the cli', t => {
1111
const cwd = t.testdir()
1212
const { spawn } = require('child_process')
1313
const LS = require('../lib/commands/ls.js')
14-
const ls = new LS({})
14+
const ls = new LS({ config: { validate: () => {} } })
1515
const p = spawn(process.execPath, [index, 'ls', '-h', '--cache', cwd])
1616
const out = []
1717
p.stdout.on('data', c => out.push(c))

test/lib/arborist-cmd.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ t.test('arborist-cmd', async t => {
4444

4545
class TestCmd extends ArboristCmd {}
4646

47-
const cmd = new TestCmd()
48-
cmd.npm = { localPrefix: path }
47+
const cmd = new TestCmd({ localPrefix: path, config: { validate: () => {} } })
4948

5049
// check filtering for a single workspace name
5150
cmd.exec = async function (args) {
@@ -97,8 +96,7 @@ t.test('handle getWorkspaces raising an error', async t => {
9796
},
9897
})
9998
class TestCmd extends ArboristCmd {}
100-
const cmd = new TestCmd()
101-
cmd.npm = { localPrefix: t.testdir() }
99+
const cmd = new TestCmd({ localPrefix: t.testdir(), config: { validate: () => {} } })
102100

103101
await t.rejects(
104102
cmd.execWorkspaces(['foo'], ['a']),

test/lib/commands/adduser.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,7 @@ t.test('legacy', async t => {
2727
const { npm, home } = await loadMockNpm(t, {
2828
config: { 'auth-type': 'legacy' },
2929
homeDir: {
30-
// These all get cleaned up by config.setCredentialsByURI
3130
'.npmrc': [
32-
'_token=user',
33-
'_password=user',
34-
'username=user',
35-
'_auth=user',
36-
'_authtoken=user',
37-
'-authtoken=user',
38-
'_authToken=user',
3931
'//registry.npmjs.org/:_authToken=user',
4032
'//registry.npmjs.org/:always-auth=user',
4133
'//registry.npmjs.org/:[email protected]',

test/lib/commands/bugs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const Bugs = t.mock('../../../lib/commands/bugs.js', {
6262
'../../../lib/utils/open-url.js': openUrl,
6363
})
6464

65-
const bugs = new Bugs({ flatOptions: {} })
65+
const bugs = new Bugs({ flatOptions: {}, config: { validate: () => {} } })
6666

6767
t.test('usage', (t) => {
6868
t.match(bugs.usage, 'bugs', 'usage has command name in it')

test/lib/commands/explain.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const npm = {
66
output: (...args) => {
77
OUTPUT.push(args)
88
},
9+
config: {
10+
validate: () => {},
11+
},
912
}
1013
const { resolve } = require('path')
1114

test/lib/commands/explore.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ const getExplore = (windows) => {
6767
output: out => {
6868
output.push(out)
6969
},
70+
config: {
71+
validate: () => {},
72+
},
7073
}
7174
return new Explore(npm)
7275
}

0 commit comments

Comments
 (0)