Skip to content

Commit 4d141a0

Browse files
fix: skip hidden lockfile save on dry run (#9417)
Backport of #9395 to `release/v11`. Co-authored-by: Puneet Dixit <puneetdixit4321@gmail.com> Co-authored-by: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com>
1 parent 4b67f6e commit 4d141a0

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

workspaces/arborist/lib/arborist/reify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ module.exports = cls => class Reifier extends cls {
239239
this.actualTree = this.idealTree
240240
this.idealTree = null
241241

242-
if (!this.options.global) {
242+
if (!this.options.global && !this.options.dryRun) {
243243
await this.actualTree.meta.save()
244244
const ignoreScripts = !!this.options.ignoreScripts
245245
// if we aren't doing a dry run or ignoring scripts and we actually made changes to the dep

workspaces/arborist/test/arborist/reify.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,26 @@ t.test('save complete lockfile on update-all', async t => {
17071707
t.matchSnapshot(lock(), 'should update, but not drop root metadata')
17081708
})
17091709

1710+
t.test('dry-run update does not save lockfiles', async t => {
1711+
const path = t.testdir({
1712+
'package.json': JSON.stringify({
1713+
name: 'dry-run-update-lockfile-test',
1714+
version: '1.0.0',
1715+
}),
1716+
})
1717+
createRegistry(t, true)
1718+
await reify(path, { add: ['abbrev@1.0.4'] })
1719+
1720+
const lock = filename => fs.readFileSync(resolve(path, filename), 'utf8')
1721+
const packageLock = lock('package-lock.json')
1722+
const hiddenLock = lock('node_modules/.package-lock.json')
1723+
1724+
await reify(path, { update: true, dryRun: true, save: false })
1725+
1726+
t.equal(lock('package-lock.json'), packageLock, 'package-lock.json unchanged')
1727+
t.equal(lock('node_modules/.package-lock.json'), hiddenLock, 'hidden lockfile unchanged')
1728+
})
1729+
17101730
t.test('save proper lockfile with bins when upgrading lockfile', async t => {
17111731
for (const complete of [true, false]) {
17121732
await t.test(`complete=${complete}`, async t => {

0 commit comments

Comments
 (0)