fix: improve unknown config warning with .npmrc section hint by umeshmore45 · Pull Request #8995 · npm/cli · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/lib/content/configuring-npm/npmrc.md
2 changes: 1 addition & 1 deletion tap-snapshots/test/lib/commands/config.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,6 @@ registry = "https://some.registry"

exports[`test/lib/commands/config.js TAP config list with publishConfig local > warns about unknown config 1`] = `
Array [
"Unknown publishConfig config /"other/". This will stop working in the next major version of npm.",
"Unknown publishConfig config /"other/". This will stop working in the next major version of npm. See \`npm help npmrc\` for supported config options.",
]
`
2 changes: 1 addition & 1 deletion test/lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ t.test('respects publishConfig.registry, runs appropriate scripts', async t => {
t.equal(fs.existsSync(path.join(prefix, 'scripts-prepublish')), false, 'did not run prepublish')
t.equal(fs.existsSync(path.join(prefix, 'scripts-publish')), true, 'ran publish')
t.equal(fs.existsSync(path.join(prefix, 'scripts-postpublish')), true, 'ran postpublish')
t.same(logs.warn, ['Unknown publishConfig config "other". This will stop working in the next major version of npm.'])
t.same(logs.warn, ['Unknown publishConfig config "other". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.'])
})

t.test('re-loads publishConfig.registry if added during script process', async t => {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/commands/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ t.test('publishConfig no spec', async t => {
t.equal(joinedOutput(), '- test-package')
t.same(logs.warn, [
'using --force Recommended protections disabled.',
'Unknown publishConfig config "other". This will stop working in the next major version of npm.',
'Unknown publishConfig config "other". This will stop working in the next major version of npm. See `npm help npmrc` for supported config options.',
])
})

Expand Down
7 changes: 5 additions & 2 deletions workspaces/config/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,16 @@ class Config {
if (internalEnv.includes(key)) {
return
}
const hint = where !== 'cli'
? ' See `npm help npmrc` for supported config options.'
: ''
if (!key.includes(':')) {
this.queueWarning(key, `Unknown ${where} config "${where === 'cli' ? '--' : ''}${key}". This will stop working in the next major version of npm.`)
this.queueWarning(key, `Unknown ${where} config "${where === 'cli' ? '--' : ''}${key}". This will stop working in the next major version of npm.${hint}`)
return
}
const baseKey = key.split(':').pop()
if (!this.definitions[baseKey] && !this.nerfDarts.includes(baseKey)) {
this.queueWarning(baseKey, `Unknown ${where} config "${baseKey}" (${key}). This will stop working in the next major version of npm.`)
this.queueWarning(baseKey, `Unknown ${where} config "${baseKey}" (${key}). This will stop working in the next major version of npm.${hint}`)
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions workspaces/config/test/index.js
Loading