Skip to content

Commit e97c588

Browse files
authored
fix(core): errors thrown when creating projects should prevent running targets (#22807)
1 parent 705b8e2 commit e97c588

File tree

1 file changed

+20
-33
lines changed
  • packages/nx/src/project-graph/plugins

1 file changed

+20
-33
lines changed

packages/nx/src/project-graph/plugins/utils.ts

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ export async function runCreateNodesInParallel(
5656
): Promise<CreateNodesResultWithContext[]> {
5757
performance.mark(`${plugin.name}:createNodes - start`);
5858

59-
const promises: Array<
60-
CreateNodesResultWithContext | Promise<CreateNodesResultWithContext>
61-
> = configFiles.map((file) => {
59+
const errors: CreateNodesError[] = [];
60+
const results: CreateNodesResultWithContext[] = [];
61+
62+
const promises: Array<Promise<void>> = configFiles.map((file) => {
6263
performance.mark(`${plugin.name}:createNodes:${file} - start`);
6364
// Result is either static or a promise, using Promise.resolve lets us
6465
// handle both cases with same logic
@@ -68,11 +69,14 @@ export async function runCreateNodesInParallel(
6869
return value
6970
.catch((e) => {
7071
performance.mark(`${plugin.name}:createNodes:${file} - end`);
71-
return new CreateNodesError({
72-
error: e,
73-
pluginName: plugin.name,
74-
file,
75-
});
72+
errors.push(
73+
new CreateNodesError({
74+
error: e,
75+
pluginName: plugin.name,
76+
file,
77+
})
78+
);
79+
return null;
7680
})
7781
.then((r) => {
7882
performance.mark(`${plugin.name}:createNodes:${file} - end`);
@@ -82,42 +86,25 @@ export async function runCreateNodesInParallel(
8286
`${plugin.name}:createNodes:${file} - end`
8387
);
8488

85-
return { ...r, pluginName: plugin.name, file };
89+
// Existing behavior is to ignore null results of
90+
// createNodes function.
91+
if (r) {
92+
results.push(r);
93+
}
8694
});
8795
});
88-
const results = await Promise.all(promises).then((results) => {
96+
97+
await Promise.all(promises).then(() => {
8998
performance.mark(`${plugin.name}:createNodes - end`);
9099
performance.measure(
91100
`${plugin.name}:createNodes`,
92101
`${plugin.name}:createNodes - start`,
93102
`${plugin.name}:createNodes - end`
94103
);
95-
return results;
96104
});
97105

98-
const [errors, successful] = partition<
99-
CreateNodesError,
100-
CreateNodesResultWithContext
101-
>(results, (r): r is CreateNodesError => r instanceof CreateNodesError);
102-
103106
if (errors.length > 0) {
104-
throw new AggregateCreateNodesError(plugin.name, errors, successful);
107+
throw new AggregateCreateNodesError(plugin.name, errors, results);
105108
}
106109
return results;
107110
}
108-
109-
function partition<T, T2 = T>(
110-
arr: Array<T | T2>,
111-
test: (item: T | T2) => item is T
112-
): [T[], T2[]] {
113-
const pass: T[] = [];
114-
const fail: T2[] = [];
115-
for (const item of arr) {
116-
if (test(item)) {
117-
pass.push(item);
118-
} else {
119-
fail.push(item as any as T2);
120-
}
121-
}
122-
return [pass, fail];
123-
}

0 commit comments

Comments
 (0)