Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): support matching projects specifiers in dependsOn #16675

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions packages/nx/src/tasks-runner/create-task-graph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1443,4 +1443,62 @@ describe('createTaskGraph', () => {
},
});
});

it('should handle glob patterns in dependsOn', () => {
const graph: ProjectGraph = {
nodes: {
app1: {
name: 'app1',
type: 'app',
data: {
root: 'app1-root',
files: [],
targets: {
build: {
executor: 'nx:run-commands',
dependsOn: [{ target: 'build', projects: 'lib*' }],
},
},
},
},
lib1: {
name: 'lib1',
type: 'lib',
data: {
root: 'lib1-root',
files: [],
targets: {
build: {
executor: 'nx:run-commands',
},
},
},
},
lib2: {
name: 'lib2',
type: 'lib',
data: {
root: 'lib2-root',
files: [],
targets: {
build: {
executor: 'nx:run-commands',
},
},
},
},
},
dependencies: {
app1: [],
},
};
const taskGraph = createTaskGraph(graph, {}, ['app1'], ['build'], null, {});
expect(taskGraph.tasks).toHaveProperty('app1:build');
expect(taskGraph.tasks).toHaveProperty('lib1:build');
expect(taskGraph.tasks).toHaveProperty('lib2:build');
expect(taskGraph.dependencies['app1:build']).toEqual([
'lib1:build',
'lib2:build',
]);
});
});
37 changes: 26 additions & 11 deletions packages/nx/src/tasks-runner/create-task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
import { Task, TaskGraph } from '../config/task-graph';
import { TargetDependencies } from '../config/nx-json';
import { TargetDependencyConfig } from '../devkit-exports';
import { findMatchingProjects } from '../utils/find-matching-projects';
import { output } from '../utils/output';

export class ProcessTasks {
private readonly seen = new Set<string>();
Expand Down Expand Up @@ -168,20 +170,33 @@ export class ProcessTasks {
// Since we need to maintain support for dependencies, it is more coherent
// that we also support self.
// TODO(@agentender): Remove this part in v17
const projectName =
const matchingProjects =
/** LERNA SUPPORT START - Remove in v17 */
projectSpecifier === 'self' &&
!this.projectGraph.nodes[projectSpecifier]
? task.target.project
: projectSpecifier;
? [task.target.project]
: /** LERNA SUPPORT END */
findMatchingProjects([projectSpecifier], this.projectGraph.nodes);

this.processTasksForSingleProject(
task,
projectName,
dependencyConfig,
configuration,
taskOverrides,
overrides
);
if (matchingProjects.length === 0) {
output.warn({
title: `\`dependsOn\` is misconfigured for ${task.target.project}:${task.target.target}`,
bodyLines: [
`Project pattern "${projectSpecifier}" does not match any projects.`,
],
});
}

for (const projectName of matchingProjects) {
this.processTasksForSingleProject(
task,
projectName,
dependencyConfig,
configuration,
taskOverrides,
overrides
);
}
}
}
}
Expand Down
19 changes: 0 additions & 19 deletions packages/nx/src/tasks-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@ export function getDependencyConfigs(
[]
);
for (const dependencyConfig of dependencyConfigs) {
const specifiers =
typeof dependencyConfig.projects === 'string'
? [dependencyConfig.projects]
: dependencyConfig.projects;
for (const specifier of specifiers ?? []) {
if (
!(specifier in projectGraph.nodes) &&
// Todo(@agentender): Remove the check for self / dependencies in v17
!['self', 'dependencies'].includes(specifier)
) {
output.error({
title: `dependsOn is improperly configured for ${project}:${target}`,
bodyLines: [
`${specifier} in dependsOn.projects is invalid. It should be "self", "dependencies", or a project name.`,
],
});
process.exit(1);
}
}
if (dependencyConfig.projects && dependencyConfig.dependencies) {
output.error({
title: `dependsOn is improperly configured for ${project}:${target}`,
Expand Down