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): flatten savePrefix properly #2937

Merged
merged 1 commit into from Mar 24, 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
4 changes: 3 additions & 1 deletion lib/utils/config/definitions.js
Expand Up @@ -1581,7 +1581,9 @@ define('save-prefix', {
\`npm config set save-prefix='~'\` it would be set to \`~1.2.3\` which
only allows patch upgrades.
`,
flatten,
flatten (key, obj, flatOptions) {
flatOptions.savePrefix = obj['save-exact'] ? '' : obj['save-prefix']
},
})

define('save-prod', {
Expand Down
15 changes: 15 additions & 0 deletions test/lib/utils/config/definitions.js
Expand Up @@ -695,3 +695,18 @@ t.test('user-agent', t => {
t.equal(flat.userAgent, expectCI)
t.end()
})

t.test('save-prefix', t => {
const obj = {
'save-exact': true,
'save-prefix': '~1.2.3',
}
const flat = {}
definitions['save-prefix']
.flatten('save-prefix', { ...obj, 'save-exact': true }, flat)
t.strictSame(flat, { savePrefix: '' })
definitions['save-prefix']
.flatten('save-prefix', { ...obj, 'save-exact': false }, flat)
t.strictSame(flat, { savePrefix: '~1.2.3' })
t.end()
})
6 changes: 6 additions & 0 deletions test/lib/utils/config/flatten.js
Expand Up @@ -6,6 +6,8 @@ delete process.env.NODE
process.execPath = '/path/to/node'

const obj = {
'save-exact': true,
'save-prefix': 'ignored',
'save-dev': true,
'@foobar:registry': 'https://foo.bar.com/',
'//foo.bar.com:_authToken': 'foobarbazquuxasdf',
Expand All @@ -15,6 +17,8 @@ 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',
npmBin: '/path/to/npm',
Expand All @@ -26,6 +30,8 @@ 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',
npmBin: '/path/to/npm',
Expand Down