Skip to content

Commit ab3ceb4

Browse files
authored
fix(misc): fix run-many for invalid projects (#13232)
1 parent 7467e71 commit ab3ceb4

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

packages/nx/src/command-line/run-many.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ProjectGraph, ProjectGraphProjectNode } from '../config/project-graph';
99
import { createProjectGraphAsync } from '../project-graph/project-graph';
1010
import { TargetDependencyConfig } from '../config/workspace-json-project-json';
1111
import { readNxJson } from '../config/configuration';
12+
import { output } from '../utils/output';
1213

1314
export async function runMany(
1415
args: { [k: string]: any },
@@ -56,6 +57,8 @@ export function projectsToRun(
5657
): ProjectGraphProjectNode[] {
5758
const selectedProjects = new Map<string, ProjectGraphProjectNode>();
5859
const validProjects = runnableForTarget(projectGraph.nodes, nxArgs.target);
60+
const validProjectNames = Array.from(validProjects.keys());
61+
const invalidProjects: string[] = [];
5962

6063
// --all is default now, if --projects is provided, it'll override the --all
6164
if (nxArgs.all && nxArgs.projects.length === 0) {
@@ -64,14 +67,18 @@ export function projectsToRun(
6467
}
6568
} else {
6669
for (const nameOrGlob of nxArgs.projects) {
67-
const project = projectGraph.nodes[nameOrGlob];
68-
69-
if (project) {
70-
selectedProjects.set(project.name, project);
70+
if (validProjects.has(nameOrGlob)) {
71+
selectedProjects.set(nameOrGlob, projectGraph.nodes[nameOrGlob]);
72+
continue;
73+
} else if (projectGraph.nodes[nameOrGlob]) {
74+
invalidProjects.push(nameOrGlob);
7175
continue;
7276
}
7377

74-
const matchedProjectNames = minimatch.match(validProjects, nameOrGlob);
78+
const matchedProjectNames = minimatch.match(
79+
validProjectNames,
80+
nameOrGlob
81+
);
7582

7683
if (matchedProjectNames.length === 0) {
7784
throw new Error(`No projects matching: ${nameOrGlob}`);
@@ -84,6 +91,13 @@ export function projectsToRun(
8491
);
8592
});
8693
}
94+
95+
if (invalidProjects.length > 0) {
96+
output.warn({
97+
title: `the following do not have configuration for "${nxArgs.target}"`,
98+
bodyLines: invalidProjects.map((name) => `- ${name}`),
99+
});
100+
}
87101
}
88102

89103
for (const nameOrGlob of nxArgs.exclude ?? []) {
@@ -109,12 +123,12 @@ export function projectsToRun(
109123
function runnableForTarget(
110124
projects: Record<string, ProjectGraphProjectNode>,
111125
target: string
112-
): string[] {
113-
const runnable: string[] = [];
126+
): Set<string> {
127+
const runnable = new Set<string>();
114128
for (let projectName in projects) {
115129
const project = projects[projectName];
116130
if (projectHasTarget(project, target)) {
117-
runnable.push(projectName);
131+
runnable.add(projectName);
118132
}
119133
}
120134
return runnable;

0 commit comments

Comments
 (0)