Skip to content

Commit dce4960

Browse files
wraithgarruyadorno
authored andcommitted
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
1 parent 543b0e3 commit dce4960

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/utils/config/definitions.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,9 @@ define('save-prefix', {
15811581
\`npm config set save-prefix='~'\` it would be set to \`~1.2.3\` which
15821582
only allows patch upgrades.
15831583
`,
1584-
flatten,
1584+
flatten (key, obj, flatOptions) {
1585+
flatOptions.savePrefix = obj['save-exact'] ? '' : obj['save-prefix']
1586+
},
15851587
})
15861588

15871589
define('save-prod', {

test/lib/utils/config/definitions.js

+15
Original file line numberDiff line numberDiff line change
@@ -695,3 +695,18 @@ t.test('user-agent', t => {
695695
t.equal(flat.userAgent, expectCI)
696696
t.end()
697697
})
698+
699+
t.test('save-prefix', t => {
700+
const obj = {
701+
'save-exact': true,
702+
'save-prefix': '~1.2.3',
703+
}
704+
const flat = {}
705+
definitions['save-prefix']
706+
.flatten('save-prefix', { ...obj, 'save-exact': true }, flat)
707+
t.strictSame(flat, { savePrefix: '' })
708+
definitions['save-prefix']
709+
.flatten('save-prefix', { ...obj, 'save-exact': false }, flat)
710+
t.strictSame(flat, { savePrefix: '~1.2.3' })
711+
t.end()
712+
})

test/lib/utils/config/flatten.js

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ delete process.env.NODE
66
process.execPath = '/path/to/node'
77

88
const obj = {
9+
'save-exact': true,
10+
'save-prefix': 'ignored',
911
'save-dev': true,
1012
'@foobar:registry': 'https://foo.bar.com/',
1113
'//foo.bar.com:_authToken': 'foobarbazquuxasdf',
@@ -15,6 +17,8 @@ const obj = {
1517
const flat = flatten(obj)
1618
t.strictSame(flat, {
1719
saveType: 'dev',
20+
saveExact: true,
21+
savePrefix: '',
1822
'@foobar:registry': 'https://foo.bar.com/',
1923
'//foo.bar.com:_authToken': 'foobarbazquuxasdf',
2024
npmBin: '/path/to/npm',
@@ -26,6 +30,8 @@ t.strictSame(flat, {
2630
process.env.NODE = '/usr/local/bin/node.exe'
2731
flatten({ 'save-dev': false }, flat)
2832
t.strictSame(flat, {
33+
saveExact: true,
34+
savePrefix: '',
2935
'@foobar:registry': 'https://foo.bar.com/',
3036
'//foo.bar.com:_authToken': 'foobarbazquuxasdf',
3137
npmBin: '/path/to/npm',

0 commit comments

Comments
 (0)