diff options
author | Gar <gar+gh@danger.computer> | 2021-03-24 17:40:21 +0300 |
---|---|---|
committer | Ruy Adorno <ruyadorno@hotmail.com> | 2021-03-24 17:52:54 +0300 |
commit | dce4960ef6d52af128affe7755b2ca72de913b6c (patch) | |
tree | d7eab73ed9420bce24cd75be6ded97f9c72ac239 | |
parent | 543b0e39bcb94fc408804b01ca9c0d7b960b2681 (diff) |
fix(config): flatten savePrefix properly
It needs to take save-exact into consideration
Closes: https://github.com/npm/cli/issues/2932
PR-URL: https://github.com/npm/cli/pull/2937
Credit: @wraithgar
Close: #2937
Reviewed-by: @ruyadorno
-rw-r--r-- | lib/utils/config/definitions.js | 4 | ||||
-rw-r--r-- | test/lib/utils/config/definitions.js | 15 | ||||
-rw-r--r-- | test/lib/utils/config/flatten.js | 6 |
3 files changed, 24 insertions, 1 deletions
diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js index a6ecbcd0c..5001efb46 100644 --- a/lib/utils/config/definitions.js +++ b/lib/utils/config/definitions.js @@ -1581,7 +1581,9 @@ define('save-prefix', { \`npm config set save-prefix='~'\` it would be set to \`~1.2.3\` which only allows patch upgrades. `, - flatten, + flatten (key, obj, flatOptions) { + flatOptions.savePrefix = obj['save-exact'] ? '' : obj['save-prefix'] + }, }) define('save-prod', { diff --git a/test/lib/utils/config/definitions.js b/test/lib/utils/config/definitions.js index 3169feefb..830468c43 100644 --- a/test/lib/utils/config/definitions.js +++ b/test/lib/utils/config/definitions.js @@ -695,3 +695,18 @@ t.test('user-agent', t => { t.equal(flat.userAgent, expectCI) t.end() }) + +t.test('save-prefix', t => { + const obj = { + 'save-exact': true, + 'save-prefix': '~1.2.3', + } + const flat = {} + definitions['save-prefix'] + .flatten('save-prefix', { ...obj, 'save-exact': true }, flat) + t.strictSame(flat, { savePrefix: '' }) + definitions['save-prefix'] + .flatten('save-prefix', { ...obj, 'save-exact': false }, flat) + t.strictSame(flat, { savePrefix: '~1.2.3' }) + t.end() +}) diff --git a/test/lib/utils/config/flatten.js b/test/lib/utils/config/flatten.js index 9fac0820c..6fc91b484 100644 --- a/test/lib/utils/config/flatten.js +++ b/test/lib/utils/config/flatten.js @@ -6,6 +6,8 @@ delete process.env.NODE process.execPath = '/path/to/node' const obj = { + 'save-exact': true, + 'save-prefix': 'ignored', 'save-dev': true, '@foobar:registry': 'https://foo.bar.com/', '//foo.bar.com:_authToken': 'foobarbazquuxasdf', @@ -15,6 +17,8 @@ const obj = { const flat = flatten(obj) t.strictSame(flat, { saveType: 'dev', + saveExact: true, + savePrefix: '', '@foobar:registry': 'https://foo.bar.com/', '//foo.bar.com:_authToken': 'foobarbazquuxasdf', npmBin: '/path/to/npm', @@ -26,6 +30,8 @@ t.strictSame(flat, { process.env.NODE = '/usr/local/bin/node.exe' flatten({ 'save-dev': false }, flat) t.strictSame(flat, { + saveExact: true, + savePrefix: '', '@foobar:registry': 'https://foo.bar.com/', '//foo.bar.com:_authToken': 'foobarbazquuxasdf', npmBin: '/path/to/npm', |