Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(config): flatten savePrefix properly
It needs to take save-exact into consideration

Closes: #2932

PR-URL: #2937
Credit: @wraithgar
Close: #2937
Reviewed-by: @ruyadorno
  • Loading branch information
wraithgar authored and ruyadorno committed Mar 24, 2021
commit dce4960ef6d52af128affe7755b2ca72de913b6c
4 changes: 3 additions & 1 deletion lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
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
15 changes: 15 additions & 0 deletions test/lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
6 changes: 6 additions & 0 deletions test/lib/utils/config/flatten.js
Original file line number Diff line number Diff line change
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