Skip to content

Commit

Permalink
fix(config): --package-lock-only implies --package-lock, closes #2747
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Aug 24, 2021
1 parent 7d7e037 commit 48198d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/utils/config/definitions.js
Expand Up @@ -1353,7 +1353,11 @@ define('package-lock', {
modules will also be disabled. To remove extraneous modules with
package-locks disabled use \`npm prune\`.
`,
flatten,
flatten: (key, obj, flatOptions) => {
flatten(key, obj, flatOptions)
if (flatOptions.packageLockOnly)
flatOptions.packageLock = true
},
})

define('package-lock-only', {
Expand All @@ -1369,7 +1373,11 @@ define('package-lock-only', {
For \`list\` this means the output will be based on the tree described by the
\`package-lock.json\`, rather than the contents of \`node_modules\`.
`,
flatten,
flatten: (key, obj, flatOptions) => {
flatten(key, obj, flatOptions)
if (flatOptions.packageLockOnly)
flatOptions.packageLock = true
},
})

define('pack-destination', {
Expand Down
21 changes: 21 additions & 0 deletions test/lib/utils/config/definitions.js
Expand Up @@ -832,3 +832,24 @@ t.test('location', t => {
t.strictSame(obj, { global: false, location: 'user' })
t.end()
})

t.test('package-lock-only', t => {
const obj = {
'package-lock': false,
'package-lock-only': true,
}
const flat = {}

definitions['package-lock-only'].flatten('package-lock-only', obj, flat)
definitions['package-lock'].flatten('package-lock', obj, flat)
t.strictSame(flat, { packageLock: true, packageLockOnly: true })

obj['package-lock-only'] = false
delete flat.packageLock
delete flat.packageLockOnly

definitions['package-lock-only'].flatten('package-lock-only', obj, flat)
definitions['package-lock'].flatten('package-lock', obj, flat)
t.strictSame(flat, { packageLock: false, packageLockOnly: false })
t.end()
})

0 comments on commit 48198d5

Please sign in to comment.