Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): tie save-exact/save-prefix together #2965

Merged
merged 1 commit into from Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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