Skip to content

Commit

Permalink
Support monorepos with no package.json at the repository root
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Oct 2, 2023
1 parent ceb8500 commit fe64c3a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions node-src/lib/findChangedDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ export const findChangedDependencies = async (ctx: Context) => {
{ rootPath, rootManifestPath, rootLockfilePath },
'No manifest or lockfile found at the root of the repository'
);
throw new Error(
`Could not find ${PACKAGE_JSON}, ${PACKAGE_LOCK} or ${YARN_LOCK} at the root of the repository`
);
}

ctx.log.debug({ rootPath, rootManifestPath, rootLockfilePath }, `Found manifest and lockfile`);

// Handle monorepos with multiple package.json files.
// Handle monorepos with (multiple) nested package.json files.
const nestedManifestPaths = await findFiles(`**/${PACKAGE_JSON}`);
const pathPairs = await Promise.all(
nestedManifestPaths.map(async (manifestPath) => {
Expand All @@ -54,7 +51,13 @@ export const findChangedDependencies = async (ctx: Context) => {
return [manifestPath, lockfilePath || rootLockfilePath];
})
);
pathPairs.unshift([rootManifestPath, rootLockfilePath]);

if (rootManifestPath && rootLockfilePath) {
pathPairs.unshift([rootManifestPath, rootLockfilePath]);
} else if (!pathPairs.length) {
throw new Error(`Could not find any pairs of ${PACKAGE_JSON} + ${PACKAGE_LOCK} / ${YARN_LOCK}`);
}

ctx.log.debug({ pathPairs }, `Found ${pathPairs.length} manifest/lockfile pairs to check`);

const tracedPairs = pathPairs.filter(([manifestPath, lockfilePath]) => {
Expand Down

0 comments on commit fe64c3a

Please sign in to comment.