From 9499d591f9c86fabe34ebde9159b7a2118bf2075 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Mon, 9 Oct 2023 14:32:14 +0200 Subject: [PATCH] Avoid falling back to nonexistent root lockfile --- node-src/lib/findChangedDependencies.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/node-src/lib/findChangedDependencies.ts b/node-src/lib/findChangedDependencies.ts index 6418b892d..abf4f0820 100644 --- a/node-src/lib/findChangedDependencies.ts +++ b/node-src/lib/findChangedDependencies.ts @@ -40,18 +40,21 @@ export const findChangedDependencies = async (ctx: Context) => { // Handle monorepos with (multiple) nested package.json files. const nestedManifestPaths = await findFiles(`**/${PACKAGE_JSON}`); - const pathPairs = await Promise.all( - nestedManifestPaths.map(async (manifestPath) => { + let pathPairs = await Promise.all( + nestedManifestPaths.map(async (manifestPath: string) => { const dirname = path.dirname(manifestPath); - const [lockfilePath] = await findFiles( + // Fall back to the root lockfile if we can't find one in the same directory. + const [lockfilePath = rootLockfilePath] = await findFiles( `${dirname}/${YARN_LOCK}`, `${dirname}/${PACKAGE_LOCK}` ); - // Fall back to the root lockfile if we can't find one in the same directory. - return [manifestPath, lockfilePath || rootLockfilePath]; + return lockfilePath && [manifestPath, lockfilePath]; }) ); + // Deal with missing rootLockfilePath which may have been used as fallback. + pathPairs = pathPairs.filter(Boolean); + if (rootManifestPath && rootLockfilePath) { pathPairs.unshift([rootManifestPath, rootLockfilePath]); } else if (!pathPairs.length) {