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

Commit d310bd3

Browse files
committed
fix: always set originalLockfileVersion when doing shrinkwrap reset
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.
1 parent d9c603e commit d310bd3

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

lib/shrinkwrap.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,10 @@ class Shrinkwrap {
380380
reset () {
381381
this.tree = null
382382
this[_awaitingUpdate] = new Map()
383-
this.originalLockfileVersion = this.lockfileVersion
383+
const lockfileVersion = this.lockfileVersion || defaultLockfileVersion
384+
this.originalLockfileVersion = lockfileVersion
384385
this.data = {
385-
lockfileVersion: this.lockfileVersion || defaultLockfileVersion,
386+
lockfileVersion,
386387
requires: true,
387388
packages: {},
388389
dependencies: {},

test/arborist/build-ideal-tree.js

+27
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,33 @@ t.test('force a new mkdirp (but not semver major)', async t => {
611611
t.equal(arb.idealTree.children.get('minimist').package.version, '1.2.5')
612612
})
613613

614+
t.test('empty update should not trigger old lockfile', async t => {
615+
const path = t.testdir({
616+
'package.json': JSON.stringify({
617+
name: 'empty-update',
618+
version: '1.0.0',
619+
}),
620+
'package-lock.json': JSON.stringify({
621+
name: 'empty-update',
622+
version: '1.0.0',
623+
lockfileVersion: 2,
624+
requires: true,
625+
packages: {
626+
'': {
627+
name: 'empty-update',
628+
version: '1.0.0',
629+
},
630+
},
631+
}),
632+
})
633+
const checkLogs = warningTracker()
634+
635+
const arb = newArb(path)
636+
await arb.reify({ update: true })
637+
638+
t.strictSame(checkLogs(), [])
639+
})
640+
614641
t.test('no fix available', async t => {
615642
const path = resolve(fixtures, 'audit-mkdirp/mkdirp-unfixable')
616643
const checkLogs = warningTracker()

test/shrinkwrap.js

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ t.test('starting out with a reset lockfile is an empty lockfile', t =>
7575
dependencies: {},
7676
packages: {},
7777
})
78+
t.equal(sw.originalLockfileVersion, 2)
7879
t.equal(sw.loadedFromDisk, true)
7980
t.equal(sw.filename, resolve(fixture, 'package-lock.json'))
8081
}))

0 commit comments

Comments
 (0)