Skip to content

Commit

Permalink
Changed to Object.assign and reverse the config list
Browse files Browse the repository at this point in the history
  • Loading branch information
kenrick95 committed Mar 16, 2021
1 parent dcb0904 commit c9aa273
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/publish.js
Expand Up @@ -137,7 +137,12 @@ class Publish extends BaseCommand {
publishConfigToOpts (publishConfig) {
// create a new object that inherits from the config stack
// then squash the css-case into camelCase opts, like we do
return {...flatten(this.npm.config.list[0]), ...flatten(publishConfig)}
const mergedConfigs = Object.assign(
{},
...[...this.npm.config.list].reverse(),
publishConfig
)
return flatten(mergedConfigs)
}
}
module.exports = Publish
7 changes: 4 additions & 3 deletions test/lib/publish.js
Expand Up @@ -511,6 +511,7 @@ t.test('able to publish after if encountered multiple configs', t => {
t.plan(3)

const registry = 'https://some.registry'
const tag = 'better-tag'
const publishConfig = { registry }
const testDir = t.testdir({
'package.json': JSON.stringify({
Expand All @@ -520,12 +521,12 @@ t.test('able to publish after if encountered multiple configs', t => {
}, null, 2),
})

const configList = [{}, { registry: `https://other.registry` }, defaults]
const configList = [{ tag }, { registry: `https://other.registry`, tag: 'some-tag' }, defaults]

const Publish = requireInject('../../lib/publish.js', {
libnpmpublish: {
publish: () => {
t.pass('publish called')
publish: (manifest, tarData, opts) => {
t.same(opts.defaultTag, tag, 'gets option for expected tag')
},
},
})
Expand Down

0 comments on commit c9aa273

Please sign in to comment.