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 d32d53d
Show file tree
Hide file tree
Showing 4 changed files with 40 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
10 changes: 10 additions & 0 deletions test/arborist/build-ideal-tree.js
Expand Up @@ -611,6 +611,16 @@ 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 = resolve(fixtures, 'empty-update')
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
14 changes: 14 additions & 0 deletions test/fixtures/empty-update/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test/fixtures/empty-update/package.json
@@ -0,0 +1,13 @@
{
"name": "empty-update",
"version": "1.0.0",
"description": "",
"main": "index.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

0 comments on commit d32d53d

Please sign in to comment.