Skip to content

Commit

Permalink
fix: npm config warn on workspaces
Browse files Browse the repository at this point in the history
When a workspace/workspaces config option is defined, we should log a
warning message to be explicit about not supporting workspaces in the
context of the `npm config` command.

PR-URL: #2950
Credit: @ruyadorno
Close: #2950
Reviewed-by: @wraithgar
  • Loading branch information
ruyadorno committed Mar 24, 2021
1 parent e544f8c commit 7b45e9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Config extends BaseCommand {
}

execWorkspaces (args, filters, cb) {
this.npm.log.warn('config', 'This command does not support workspaces.')
this.exec(args, cb)
}

Expand Down
12 changes: 11 additions & 1 deletion test/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const cliConfig = {

const npm = {
log: {
warn: () => null,
info: () => null,
enableProgress: () => null,
disableProgress: () => null,
Expand Down Expand Up @@ -94,8 +95,17 @@ t.test('config no args', t => {
})

t.test('config ignores workspaces', t => {
npm.log.warn = (title, msg) => {
t.equal(title, 'config', 'should warn with expected title')
t.equal(
msg,
'This command does not support workspaces.',
'should warn with unsupported option msg'
)
}
config.execWorkspaces([], [], (err) => {
t.match(err, /usage instructions/, 'should not error out when workspaces are defined')
npm.log.warn = () => null
t.end()
})
})
Expand Down Expand Up @@ -396,7 +406,7 @@ t.test('config set invalid key', t => {
npm.config.validate = npmConfigValidate
delete npm.config.save
delete npm.config.set
delete npm.log.warn
npm.log.warn = () => null
})

config.exec(['set', 'foo', 'bar'], (err) => {
Expand Down

0 comments on commit 7b45e9d

Please sign in to comment.