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 5ecaf92
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/utils/config/definitions.js
Expand Up @@ -1526,7 +1526,11 @@ 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) {
flatOptions.saveExact = obj['save-exact']
flatOptions.savePrefix = obj['save-exact'] ? '' : obj['save-prefix']
obj['save-prefix'] = flatOptions.savePrefix
},
})

define('save-optional', {
Expand Down Expand Up @@ -1594,7 +1598,8 @@ define('save-prefix', {
only allows patch upgrades.
`,
flatten (key, obj, flatOptions) {
flatOptions.savePrefix = obj['save-exact'] ? '' : obj['save-prefix']
// just call the save-exact flattener, it reads from obj['save-prefix']
definitions['save-exact'].flatten('save-exact', obj, flatOptions)
},
})

Expand Down
4 changes: 2 additions & 2 deletions test/lib/utils/config/definitions.js
Expand Up @@ -748,9 +748,9 @@ t.test('save-prefix', t => {
const flat = {}
definitions['save-prefix']
.flatten('save-prefix', { ...obj, 'save-exact': true }, flat)
t.strictSame(flat, { savePrefix: '' })
t.strictSame(flat, { saveExact: true, savePrefix: '' })
definitions['save-prefix']
.flatten('save-prefix', { ...obj, 'save-exact': false }, flat)
t.strictSame(flat, { savePrefix: '~1.2.3' })
t.strictSame(flat, { saveExact: false, savePrefix: '~1.2.3' })
t.end()
})

0 comments on commit 5ecaf92

Please sign in to comment.