Skip to content

Commit a0c6123

Browse files
committed
fix(config): tie save-exact/save-prefix together
Each affects the other
1 parent 2b3d1f9 commit a0c6123

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/utils/config/definitions.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,10 @@ define('save-exact', {
15261526
Dependencies saved to package.json will be configured with an exact
15271527
version rather than using npm's default semver range operator.
15281528
`,
1529-
flatten,
1529+
flatten (key, obj, flatOptions) {
1530+
// just call the save-prefix flattener, it reads from obj['save-exact']
1531+
definitions['save-prefix'].flatten('save-prefix', obj, flatOptions)
1532+
},
15301533
})
15311534

15321535
define('save-optional', {
@@ -1595,6 +1598,7 @@ define('save-prefix', {
15951598
`,
15961599
flatten (key, obj, flatOptions) {
15971600
flatOptions.savePrefix = obj['save-exact'] ? '' : obj['save-prefix']
1601+
obj['save-prefix'] = flatOptions.savePrefix
15981602
},
15991603
})
16001604

test/lib/utils/config/definitions.js

+15
Original file line numberDiff line numberDiff line change
@@ -754,3 +754,18 @@ t.test('save-prefix', t => {
754754
t.strictSame(flat, { savePrefix: '~1.2.3' })
755755
t.end()
756756
})
757+
758+
t.test('save-exact', t => {
759+
const obj = {
760+
'save-exact': true,
761+
'save-prefix': '~1.2.3',
762+
}
763+
const flat = {}
764+
definitions['save-exact']
765+
.flatten('save-exact', { ...obj, 'save-exact': true }, flat)
766+
t.strictSame(flat, { savePrefix: '' })
767+
definitions['save-exact']
768+
.flatten('save-exact', { ...obj, 'save-exact': false }, flat)
769+
t.strictSame(flat, { savePrefix: '~1.2.3' })
770+
t.end()
771+
})

test/lib/utils/config/flatten.js

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const obj = {
1717
const flat = flatten(obj)
1818
t.strictSame(flat, {
1919
saveType: 'dev',
20-
saveExact: true,
2120
savePrefix: '',
2221
'@foobar:registry': 'https://foo.bar.com/',
2322
'//foo.bar.com:_authToken': 'foobarbazquuxasdf',
@@ -30,7 +29,6 @@ t.strictSame(flat, {
3029
process.env.NODE = '/usr/local/bin/node.exe'
3130
flatten({ 'save-dev': false }, flat)
3231
t.strictSame(flat, {
33-
saveExact: true,
3432
savePrefix: '',
3533
'@foobar:registry': 'https://foo.bar.com/',
3634
'//foo.bar.com:_authToken': 'foobarbazquuxasdf',

0 commit comments

Comments
 (0)