Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
fix: always set originalLockfileVersion when doing shrinkwrap reset
Browse files Browse the repository at this point in the history
Fix: npm/cli#3899

A shrinkwrap reset without specifying a lockfile version was triggering
an old lockfile warning due to the originalLockfileVersion not being set
prior to checking whether the lockfile was old.
  • Loading branch information
lukekarrys committed Oct 21, 2021
1 parent d9c603e commit 4fc3a53
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/shrinkwrap.js
Expand Up @@ -380,9 +380,10 @@ class Shrinkwrap {
reset () {
this.tree = null
this[_awaitingUpdate] = new Map()
this.originalLockfileVersion = this.lockfileVersion
const lockfileVersion = this.lockfileVersion || defaultLockfileVersion
this.originalLockfileVersion = lockfileVersion
this.data = {
lockfileVersion: this.lockfileVersion || defaultLockfileVersion,
lockfileVersion,
requires: true,
packages: {},
dependencies: {},
Expand Down
27 changes: 27 additions & 0 deletions test/arborist/build-ideal-tree.js
Expand Up @@ -611,6 +611,33 @@ t.test('force a new mkdirp (but not semver major)', async t => {
t.equal(arb.idealTree.children.get('minimist').package.version, '1.2.5')
})

t.test('empty update should not trigger old lockfile', async t => {
const path = t.testdir({
'package.json': JSON.stringify({
name: 'empty-update',
version: '1.0.0',
}),
'package-lock.json': JSON.stringify({
name: 'empty-update',
version: '1.0.0',
lockfileVersion: 2,
requires: true,
packages: {
'': {
name: 'empty-update',
version: '1.0.0',
}
}
})
})
const checkLogs = warningTracker()

const arb = newArb(path)
await arb.reify({ update: true })

t.strictSame(checkLogs(), [])
})

t.test('no fix available', async t => {
const path = resolve(fixtures, 'audit-mkdirp/mkdirp-unfixable')
const checkLogs = warningTracker()
Expand Down

0 comments on commit 4fc3a53

Please sign in to comment.