Skip to content

Commit bc80cc5

Browse files
FrozenPandazjaysoo
authored andcommitted
fix(core): fix plugin error indexes (#29936)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> The errors were misaligned to the plugin index they pertained to. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> The errors are not misaligned to the plugin index they pertain to. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
1 parent 02253cc commit bc80cc5

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

packages/nx/src/project-graph/error-types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,12 @@ export function formatAggregateCreateNodesError(
280280
const errorBodyLines = [
281281
`${
282282
error.errors.length > 1 ? `${error.errors.length} errors` : 'An error'
283-
} occurred while processing files for the ${pluginName} plugin.`,
283+
} occurred while processing files for the ${pluginName} plugin${
284+
error.pluginIndex
285+
? ` (Defined at nx.json#plugins[${error.pluginIndex}])`
286+
: ''
287+
}`,
288+
`.`,
284289
];
285290
const errorStackLines = [];
286291

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ async function loadSpecifiedNxPlugins(
159159
const cleanupFunctions: Array<() => void> = [];
160160
const ret = [
161161
await Promise.all(
162-
plugins.map(async (plugin) => {
162+
plugins.map(async (plugin, index) => {
163163
const pluginPath = typeof plugin === 'string' ? plugin : plugin.plugin;
164164
performance.mark(`Load Nx Plugin: ${pluginPath} - start`);
165165

@@ -170,6 +170,7 @@ async function loadSpecifiedNxPlugins(
170170

171171
cleanupFunctions.push(cleanup);
172172
const res = await loadedPluginPromise;
173+
res.index = index;
173174
performance.mark(`Load Nx Plugin: ${pluginPath} - end`);
174175
performance.measure(
175176
`Load Nx Plugin: ${pluginPath}`,

packages/nx/src/project-graph/plugins/loaded-nx-plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { isIsolationEnabled } from './isolation/enabled';
2020
import { isDaemonEnabled } from '../../daemon/client/client';
2121

2222
export class LoadedNxPlugin {
23+
index?: number;
2324
readonly name: string;
2425
readonly createNodes?: [
2526
filePattern: string,

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ import { performance } from 'perf_hooks';
1616

1717
import { LoadedNxPlugin } from '../plugins/loaded-nx-plugin';
1818
import {
19-
MergeNodesError,
20-
ProjectConfigurationsError,
21-
ProjectsWithNoNameError,
22-
MultipleProjectsWithSameNameError,
19+
AggregateCreateNodesError,
20+
formatAggregateCreateNodesError,
21+
isAggregateCreateNodesError,
2322
isMultipleProjectsWithSameNameError,
2423
isProjectsWithNoNameError,
25-
ProjectWithNoNameError,
26-
ProjectWithExistingNameError,
2724
isProjectWithExistingNameError,
2825
isProjectWithNoNameError,
29-
isAggregateCreateNodesError,
30-
AggregateCreateNodesError,
31-
formatAggregateCreateNodesError,
26+
MergeNodesError,
27+
MultipleProjectsWithSameNameError,
28+
ProjectConfigurationsError,
29+
ProjectsWithNoNameError,
30+
ProjectWithExistingNameError,
31+
ProjectWithNoNameError,
3232
} from '../error-types';
3333
import { CreateNodesResult } from '../plugins/public-api';
3434
import { isGlobPattern } from '../../utils/globs';
@@ -377,7 +377,13 @@ export async function createProjectConfigurationsWithPlugins(
377377
// We iterate over plugins first - this ensures that plugins specified first take precedence.
378378
for (const [
379379
index,
380-
{ createNodes: createNodesTuple, include, exclude, name: pluginName },
380+
{
381+
index: pluginIndex,
382+
createNodes: createNodesTuple,
383+
include,
384+
exclude,
385+
name: pluginName,
386+
},
381387
] of plugins.entries()) {
382388
const [pattern, createNodes] = createNodesTuple ?? [];
383389

@@ -403,8 +409,10 @@ export async function createProjectConfigurationsWithPlugins(
403409
e
404410
: // This represents a single plugin erroring out with a hard error.
405411
new AggregateCreateNodesError([[null, e]], []);
412+
if (pluginIndex) {
413+
error.pluginIndex = pluginIndex;
414+
}
406415
formatAggregateCreateNodesError(error, pluginName);
407-
error.pluginIndex = index;
408416
// This represents a single plugin erroring out with a hard error.
409417
errors.push(error);
410418
// The plugin didn't return partial results, so we return an empty array.
@@ -458,7 +466,7 @@ function mergeCreateNodesResults(
458466
plugin: string,
459467
file: string,
460468
result: CreateNodesResult,
461-
index?: number
469+
pluginIndex?: number
462470
])[][],
463471
nxJsonConfiguration: NxJsonConfiguration,
464472
errors: (
@@ -477,7 +485,7 @@ function mergeCreateNodesResults(
477485
> = {};
478486

479487
for (const result of results.flat()) {
480-
const [pluginName, file, nodes, index] = result;
488+
const [pluginName, file, nodes, pluginIndex] = result;
481489

482490
const { projects: projectNodes, externalNodes: pluginExternalNodes } =
483491
nodes;
@@ -506,7 +514,7 @@ function mergeCreateNodesResults(
506514
file,
507515
pluginName,
508516
error,
509-
pluginIndex: index,
517+
pluginIndex,
510518
})
511519
);
512520
}

packages/nx/src/project-graph/utils/retrieve-workspace-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export async function retrieveProjectConfigurations(
7878
workspaceRoot,
7979
nxJson,
8080
pluginConfigFiles,
81-
plugins
81+
pluginsWithCreateNodes
8282
);
8383
}
8484

0 commit comments

Comments
 (0)