Skip to content

Commit

Permalink
fix(compas): prevent infinite recursion while loading configs
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkdev98 committed Aug 29, 2023
1 parent 4624452 commit 9eb4607
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/compas/src/shared/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,20 @@ APP_NAME=${dirname}
export async function configResolveProjectConfig() {
debugTimeStart("config.resolveProjectConfig");

const loadedPaths = [];

async function loadRelativeConfig(relativeDirectory) {
debugPrint(`Resolving config in '${relativeDirectory}'.`);

const configPath = pathJoin(relativeDirectory, "config/compas.json");
const configPath = path.resolve(
pathJoin(relativeDirectory, "config/compas.json"),
);

// Prevent recursion when two projects reference each other.
if (loadedPaths.includes(configPath)) {
return;
}
loadedPaths.push(configPath);

let rawConfig = {};
if (existsSync(configPath)) {
Expand Down Expand Up @@ -135,9 +145,13 @@ export async function configResolveProjectConfig() {
const projects = [];

for (const subProject of value.projects ?? []) {
projects.push(
await loadRelativeConfig(pathJoin(relativeDirectory, subProject)),
const config = await loadRelativeConfig(
pathJoin(relativeDirectory, subProject),
);

if (!isNil(config)) {
projects.push(config);
}
}

// @ts-expect-error
Expand Down

0 comments on commit 9eb4607

Please sign in to comment.