Skip to content

Commit

Permalink
fix(misc): fix run-many for invalid projects (#13232)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Nov 17, 2022
1 parent 7467e71 commit ab3ceb4
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions packages/nx/src/command-line/run-many.ts
Expand Up @@ -9,6 +9,7 @@ import { ProjectGraph, ProjectGraphProjectNode } from '../config/project-graph';
import { createProjectGraphAsync } from '../project-graph/project-graph';
import { TargetDependencyConfig } from '../config/workspace-json-project-json';
import { readNxJson } from '../config/configuration';
import { output } from '../utils/output';

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

// --all is default now, if --projects is provided, it'll override the --all
if (nxArgs.all && nxArgs.projects.length === 0) {
Expand All @@ -64,14 +67,18 @@ export function projectsToRun(
}
} else {
for (const nameOrGlob of nxArgs.projects) {
const project = projectGraph.nodes[nameOrGlob];

if (project) {
selectedProjects.set(project.name, project);
if (validProjects.has(nameOrGlob)) {
selectedProjects.set(nameOrGlob, projectGraph.nodes[nameOrGlob]);
continue;
} else if (projectGraph.nodes[nameOrGlob]) {
invalidProjects.push(nameOrGlob);
continue;
}

const matchedProjectNames = minimatch.match(validProjects, nameOrGlob);
const matchedProjectNames = minimatch.match(
validProjectNames,
nameOrGlob
);

if (matchedProjectNames.length === 0) {
throw new Error(`No projects matching: ${nameOrGlob}`);
Expand All @@ -84,6 +91,13 @@ export function projectsToRun(
);
});
}

if (invalidProjects.length > 0) {
output.warn({
title: `the following do not have configuration for "${nxArgs.target}"`,
bodyLines: invalidProjects.map((name) => `- ${name}`),
});
}
}

for (const nameOrGlob of nxArgs.exclude ?? []) {
Expand All @@ -109,12 +123,12 @@ export function projectsToRun(
function runnableForTarget(
projects: Record<string, ProjectGraphProjectNode>,
target: string
): string[] {
const runnable: string[] = [];
): Set<string> {
const runnable = new Set<string>();
for (let projectName in projects) {
const project = projects[projectName];
if (projectHasTarget(project, target)) {
runnable.push(projectName);
runnable.add(projectName);
}
}
return runnable;
Expand Down

1 comment on commit ab3ceb4

@vercel
Copy link

@vercel vercel bot commented on ab3ceb4 Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.