From 7bd873ad15bc66644fd7fb5e590722129473e285 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 14 Dec 2022 00:05:50 +0100 Subject: [PATCH] cli: handle failure to read lockfile during analysis Signed-off-by: Patrik Oldsberg --- packages/cli/src/lib/monorepo/PackageGraph.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/lib/monorepo/PackageGraph.ts b/packages/cli/src/lib/monorepo/PackageGraph.ts index 8aa7fc9416..a1fc95e669 100644 --- a/packages/cli/src/lib/monorepo/PackageGraph.ts +++ b/packages/cli/src/lib/monorepo/PackageGraph.ts @@ -240,12 +240,21 @@ export class PackageGraph extends Map { if (changedFiles.includes('yarn.lock') && options.analyzeLockfile) { // Load the lockfile in the working tree and the one at the ref and diff them - const thisLockfile = await Lockfile.load( - paths.resolveTargetRoot('yarn.lock'), - ); - const otherLockfile = Lockfile.parse( - await readFileAtRef('yarn.lock', options.ref), - ); + let thisLockfile: Lockfile; + let otherLockfile: Lockfile; + try { + thisLockfile = await Lockfile.load( + paths.resolveTargetRoot('yarn.lock'), + ); + otherLockfile = Lockfile.parse( + await readFileAtRef('yarn.lock', options.ref), + ); + } catch (error) { + console.warn( + `Failed to read lockfiles, assuming all packages have changed, ${error}`, + ); + return Array.from(this.values()); + } const diff = thisLockfile.diff(otherLockfile); // Create a simplified dependency graph only keeps track of package names