Skip to content

Commit

Permalink
fix(config): tie save-exact/save-prefix together
Browse files Browse the repository at this point in the history
Each affects the other

PR-URL: #2965
Credit: @wraithgar
Close: #2965
Reviewed-by: @nlf
  • Loading branch information
wraithgar authored and ruyadorno committed Mar 25, 2021
1 parent 1415b4b commit 5927193
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/utils/config/definitions.js
Expand Up @@ -1526,7 +1526,10 @@ define('save-exact', {
Dependencies saved to package.json will be configured with an exact
version rather than using npm's default semver range operator.
`,
flatten,
flatten (key, obj, flatOptions) {
// just call the save-prefix flattener, it reads from obj['save-exact']
definitions['save-prefix'].flatten('save-prefix', obj, flatOptions)
},
})

define('save-optional', {
Expand Down Expand Up @@ -1595,6 +1598,7 @@ define('save-prefix', {
`,
flatten (key, obj, flatOptions) {
flatOptions.savePrefix = obj['save-exact'] ? '' : obj['save-prefix']
obj['save-prefix'] = flatOptions.savePrefix
},
})

Expand Down
15 changes: 15 additions & 0 deletions test/lib/utils/config/definitions.js
Expand Up @@ -760,3 +760,18 @@ t.test('save-prefix', t => {
t.strictSame(flat, { savePrefix: '~1.2.3' })
t.end()
})

t.test('save-exact', t => {
const obj = {
'save-exact': true,
'save-prefix': '~1.2.3',
}
const flat = {}
definitions['save-exact']
.flatten('save-exact', { ...obj, 'save-exact': true }, flat)
t.strictSame(flat, { savePrefix: '' })
definitions['save-exact']
.flatten('save-exact', { ...obj, 'save-exact': false }, flat)
t.strictSame(flat, { savePrefix: '~1.2.3' })
t.end()
})
2 changes: 0 additions & 2 deletions test/lib/utils/config/flatten.js
Expand Up @@ -17,7 +17,6 @@ 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',
Expand All @@ -30,7 +29,6 @@ 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',
Expand Down

0 comments on commit 5927193

Please sign in to comment.