From c9aa27325c86a037099ccf2b139fbc87270f23aa Mon Sep 17 00:00:00 2001 From: Kenrick Date: Tue, 16 Mar 2021 09:19:58 +0800 Subject: [PATCH] Changed to Object.assign and reverse the config list --- lib/publish.js | 7 ++++++- test/lib/publish.js | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/publish.js b/lib/publish.js index dc5508a513342..486333b7fe790 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -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 diff --git a/test/lib/publish.js b/test/lib/publish.js index 79f6ac171dd4c..acc1a2ad84947 100644 --- a/test/lib/publish.js +++ b/test/lib/publish.js @@ -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({ @@ -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') }, }, })