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
  • Loading branch information
wraithgar committed Mar 25, 2021
1 parent 2b3d1f9 commit fb1ec1e
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
Original file line number Diff line number Diff line change
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-prefix']
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
Original file line number Diff line number Diff line change
Expand Up @@ -754,3 +754,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
Original file line number Diff line number Diff line change
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 fb1ec1e

Please sign in to comment.