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

fix: always set originalLockfileVersion when doing shrinkwrap reset #339

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/shrinkwrap.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions test/shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ t.test('starting out with a reset lockfile is an empty lockfile', t =>
dependencies: {},
packages: {},
})
t.equal(sw.originalLockfileVersion, 2)
t.equal(sw.loadedFromDisk, true)
t.equal(sw.filename, resolve(fixture, 'package-lock.json'))
}))
Expand Down