Skip to content

Commit e04f12f

Browse files
kenrick95isaacs
authored andcommitted
fix(publish): handle case where multiple config list is present
When not handled, when there are multiple entries in this.npm.config.list, it causes crash as described in #2834 The change here merge everything in this.npm.config.list, because as I observed, the default config is present only at the last entry. Fix: #2834 Co-authored-by: @wraithgar PR-URL: #2865 Credit: @kenrick95 Close: #2865 Reviewed-by: @isaacs, @wraithgar
1 parent 540cbb8 commit e04f12f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

lib/publish.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class Publish extends BaseCommand {
141141
publishConfigToOpts (publishConfig) {
142142
// create a new object that inherits from the config stack
143143
// then squash the css-case into camelCase opts, like we do
144-
return flatten({...this.npm.config.list[0], ...publishConfig})
144+
return flatten({...flatten(this.npm.config.list[0]), ...publishConfig})
145145
}
146146
}
147147
module.exports = Publish

test/lib/publish.js

+45
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,48 @@ t.test('read registry only from publishConfig', t => {
473473
t.end()
474474
})
475475
})
476+
477+
t.test('able to publish after if encountered multiple configs', t => {
478+
t.plan(3)
479+
480+
const registry = 'https://some.registry'
481+
const tag = 'better-tag'
482+
const publishConfig = { registry }
483+
const testDir = t.testdir({
484+
'package.json': JSON.stringify({
485+
name: 'my-cool-pkg',
486+
version: '1.0.0',
487+
publishConfig,
488+
}, null, 2),
489+
})
490+
491+
const configList = [
492+
{ ...defaults, tag },
493+
{ ...defaults, registry: `https://other.registry`, tag: 'some-tag' },
494+
defaults,
495+
]
496+
497+
const Publish = requireInject('../../lib/publish.js', {
498+
libnpmpublish: {
499+
publish: (manifest, tarData, opts) => {
500+
t.same(opts.defaultTag, tag, 'gets option for expected tag')
501+
},
502+
},
503+
})
504+
const publish = new Publish({
505+
config: {
506+
list: configList,
507+
getCredentialsByURI: (uri) => {
508+
t.same(uri, registry, 'gets credentials for expected registry')
509+
return { token: 'some.registry.token' }
510+
},
511+
},
512+
})
513+
514+
publish.exec([testDir], (er) => {
515+
if (er)
516+
throw er
517+
t.pass('got to callback')
518+
t.end()
519+
})
520+
})

0 commit comments

Comments
 (0)