Skip to content

Commit 5927193

Browse files
wraithgarruyadorno
authored andcommitted
fix(config): tie save-exact/save-prefix together
Each affects the other PR-URL: #2965 Credit: @wraithgar Close: #2965 Reviewed-by: @nlf
1 parent 1415b4b commit 5927193

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/utils/config/definitions.js

Lines changed: 5 additions & 1 deletion
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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,18 @@ t.test('save-prefix', t => {
760760
t.strictSame(flat, { savePrefix: '~1.2.3' })
761761
t.end()
762762
})
763+
764+
t.test('save-exact', t => {
765+
const obj = {
766+
'save-exact': true,
767+
'save-prefix': '~1.2.3',
768+
}
769+
const flat = {}
770+
definitions['save-exact']
771+
.flatten('save-exact', { ...obj, 'save-exact': true }, flat)
772+
t.strictSame(flat, { savePrefix: '' })
773+
definitions['save-exact']
774+
.flatten('save-exact', { ...obj, 'save-exact': false }, flat)
775+
t.strictSame(flat, { savePrefix: '~1.2.3' })
776+
t.end()
777+
})

test/lib/utils/config/flatten.js

Lines changed: 0 additions & 2 deletions
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)