From 4fc3a53cc87a85097104731ef384cd61d80d2b58 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Thu, 21 Oct 2021 10:06:52 -0700 Subject: [PATCH] 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. --- lib/shrinkwrap.js | 5 +++-- test/arborist/build-ideal-tree.js | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/shrinkwrap.js b/lib/shrinkwrap.js index 93e1cb1a4..00e5b8d34 100644 --- a/lib/shrinkwrap.js +++ b/lib/shrinkwrap.js @@ -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: {}, diff --git a/test/arborist/build-ideal-tree.js b/test/arborist/build-ideal-tree.js index 1e3147405..02cce3e04 100644 --- a/test/arborist/build-ideal-tree.js +++ b/test/arborist/build-ideal-tree.js @@ -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()