diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index c9f08de776e46..38893dbd91eb3 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -239,7 +239,7 @@ module.exports = cls => class Reifier extends cls { this.actualTree = this.idealTree this.idealTree = null - if (!this.options.global) { + if (!this.options.global && !this.options.dryRun) { await this.actualTree.meta.save() const ignoreScripts = !!this.options.ignoreScripts // if we aren't doing a dry run or ignoring scripts and we actually made changes to the dep diff --git a/workspaces/arborist/test/arborist/reify.js b/workspaces/arborist/test/arborist/reify.js index 545c650eea553..90ff99f38b90f 100644 --- a/workspaces/arborist/test/arborist/reify.js +++ b/workspaces/arborist/test/arborist/reify.js @@ -1707,6 +1707,26 @@ t.test('save complete lockfile on update-all', async t => { t.matchSnapshot(lock(), 'should update, but not drop root metadata') }) +t.test('dry-run update does not save lockfiles', async t => { + const path = t.testdir({ + 'package.json': JSON.stringify({ + name: 'dry-run-update-lockfile-test', + version: '1.0.0', + }), + }) + createRegistry(t, true) + await reify(path, { add: ['abbrev@1.0.4'] }) + + const lock = filename => fs.readFileSync(resolve(path, filename), 'utf8') + const packageLock = lock('package-lock.json') + const hiddenLock = lock('node_modules/.package-lock.json') + + await reify(path, { update: true, dryRun: true, save: false }) + + t.equal(lock('package-lock.json'), packageLock, 'package-lock.json unchanged') + t.equal(lock('node_modules/.package-lock.json'), hiddenLock, 'hidden lockfile unchanged') +}) + t.test('save proper lockfile with bins when upgrading lockfile', async t => { for (const complete of [true, false]) { await t.test(`complete=${complete}`, async t => {