From 14818638394bbc62409aac12f0fe21350db678c8 Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Sat, 23 Dec 2023 15:01:01 +0800 Subject: [PATCH] fix: don't emit package-lock.json when package.json does not exist --- workspaces/arborist/lib/arborist/reify.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/workspaces/arborist/lib/arborist/reify.js b/workspaces/arborist/lib/arborist/reify.js index 0981afdae6ece..9fa04b6515ee9 100644 --- a/workspaces/arborist/lib/arborist/reify.js +++ b/workspaces/arborist/lib/arborist/reify.js @@ -1447,6 +1447,10 @@ module.exports = cls => class Reifier extends cls { } } + const isObjectEmpty = (obj) => { + return Object.keys(obj).length === 0 && obj.constructor === Object + } + // before now edge specs could be changing, affecting the `requires` field // in the package lock, so we hold off saving to the very last action if (this[_usePackageLock]) { @@ -1457,10 +1461,12 @@ module.exports = cls => class Reifier extends cls { } // TODO this ignores options.save - await this.idealTree.meta.save({ - format: (this[_formatPackageLock] && format) ? format - : this[_formatPackageLock], - }) + if (!isObjectEmpty(this.idealTree.package)) { + await this.idealTree.meta.save({ + format: (this[_formatPackageLock] && format) ? format + : this[_formatPackageLock], + }) + } } process.emit('timeEnd', 'reify:save')