Skip to content

Commit

Permalink
fix(config): flatten savePrefix properly
Browse files Browse the repository at this point in the history
It needs to take save-exact into consideration

Closes: #2932
  • Loading branch information
wraithgar committed Mar 24, 2021
1 parent 581b60b commit d001365
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/utils/config/definitions.js
Expand Up @@ -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', {
Expand Down
6 changes: 6 additions & 0 deletions test/lib/utils/config/flatten.js
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit d001365

Please sign in to comment.