Skip to content

Commit

Permalink
chore(core): refactor -> minimatch
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Jun 13, 2024
1 parent 3e153f3 commit 398d276
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ function shouldSkipInitialTargetRun(
project: string,
target: string
): boolean {
const allTargetNames = new Set<string>();
for (const projectName in projectGraph.nodes) {
const project = projectGraph.nodes[projectName];
for (const targetName in project.data.targets ?? {}) {
allTargetNames.add(targetName);
}
}

const projectDependencyConfigs = getDependencyConfigs(
{ project, target },
{},
projectGraph
projectGraph,
Array.from(allTargetNames)
);

// if the task runner already ran the target, skip the initial run
Expand Down
15 changes: 13 additions & 2 deletions packages/nx/src/tasks-runner/create-task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ export class ProcessTasks {
private readonly seen = new Set<string>();
readonly tasks: { [id: string]: Task } = {};
readonly dependencies: { [k: string]: string[] } = {};
private readonly allTargetNames: string[];

constructor(
private readonly extraTargetDependencies: TargetDependencies,
private readonly projectGraph: ProjectGraph
) {}
) {
const allTargetNames = new Set<string>();
for (const projectName in projectGraph.nodes) {
const project = projectGraph.nodes[projectName];
for (const targetName in project.data.targets ?? {}) {
allTargetNames.add(targetName);
}
}
this.allTargetNames = Array.from(allTargetNames);
}

processTasks(
projectNames: string[],
Expand Down Expand Up @@ -100,7 +110,8 @@ export class ProcessTasks {
const dependencyConfigs = getDependencyConfigs(
{ project: task.target.project, target: task.target.target },
this.extraTargetDependencies,
this.projectGraph
this.projectGraph,
this.allTargetNames
);
for (const dependencyConfig of dependencyConfigs) {
const taskOverrides =
Expand Down
123 changes: 97 additions & 26 deletions packages/nx/src/tasks-runner/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
expandDependencyConfigSyntaxSugar,
getDependencyConfigs,
getOutputsForTargetAndConfiguration,
interpolate,
transformLegacyOutputs,
Expand Down Expand Up @@ -443,7 +444,7 @@ describe('utils', () => {

describe('expandDependencyConfigSyntaxSugar', () => {
it('should expand syntax for simple target names', () => {
const result = expandDependencyConfigSyntaxSugar('build', 'any', {
const result = expandDependencyConfigSyntaxSugar('build', {
dependencies: {},
nodes: {},
});
Expand All @@ -455,7 +456,7 @@ describe('utils', () => {
});

it('should assume target of self if simple target also matches project name', () => {
const result = expandDependencyConfigSyntaxSugar('build', 'any', {
const result = expandDependencyConfigSyntaxSugar('build', {
dependencies: {},
nodes: {
build: {
Expand All @@ -475,7 +476,7 @@ describe('utils', () => {
});

it('should expand syntax for simple target names targetting dependencies', () => {
const result = expandDependencyConfigSyntaxSugar('^build', 'any', {
const result = expandDependencyConfigSyntaxSugar('^build', {
dependencies: {},
nodes: {},
});
Expand All @@ -488,7 +489,7 @@ describe('utils', () => {
});

it('should expand syntax for strings like project:target if project is a valid project', () => {
const result = expandDependencyConfigSyntaxSugar('project:build', 'any', {
const result = expandDependencyConfigSyntaxSugar('project:build', {
dependencies: {},
nodes: {
project: {
Expand All @@ -509,14 +510,10 @@ describe('utils', () => {
});

it('should expand syntax for strings like target:with:colons', () => {
const result = expandDependencyConfigSyntaxSugar(
'target:with:colons',
'any',
{
dependencies: {},
nodes: {},
}
);
const result = expandDependencyConfigSyntaxSugar('target:with:colons', {
dependencies: {},
nodes: {},
});
expect(result).toEqual([
{
target: 'target:with:colons',
Expand All @@ -525,24 +522,31 @@ describe('utils', () => {
});

it('supports wildcards in targets', () => {
const result = expandDependencyConfigSyntaxSugar('build-*', 'project', {
dependencies: {},
nodes: {
project: {
name: 'project',
type: 'app',
data: {
root: 'libs/project',
targets: {
build: {},
'build-css': {},
'build-js': {},
'then-build-something-else': {},
const result = getDependencyConfigs(
{ project: 'project', target: 'build' },
{},
{
dependencies: {},
nodes: {
project: {
name: 'project',
type: 'app',
data: {
root: 'libs/project',
targets: {
build: {
dependsOn: ['build-*'],
},
'build-css': {},
'build-js': {},
'then-build-something-else': {},
},
},
},
},
},
});
['build', 'build-css', 'build-js', 'then-build-something-else']
);
expect(result).toEqual([
{
target: 'build-css',
Expand All @@ -554,6 +558,73 @@ describe('utils', () => {
},
]);
});

it('should support wildcards with dependencies', () => {
const result = getDependencyConfigs(
{ project: 'project', target: 'build' },
{},
{
dependencies: {},
nodes: {
project: {
name: 'project',
type: 'app',
data: {
root: 'libs/project',
targets: {
build: {
dependsOn: ['^build-*'],
},
'then-build-something-else': {},
},
},
},
dep1: {
name: 'dep1',
type: 'lib',
data: {
root: 'libs/dep1',
targets: {
'build-css': {},
'build-js': {},
},
},
},
dep2: {
name: 'dep2',
type: 'lib',
data: {
root: 'libs/dep2',
targets: {
'build-python': {},
},
},
},
},
},
[
'build',
'build-css',
'build-js',
'then-build-something-else',
'build-python',
]
);
expect(result).toEqual([
{
target: 'build-css',
dependencies: true,
},
{
target: 'build-js',
dependencies: true,
},
{
target: 'build-python',
dependencies: true,
},
]);
});
});

describe('validateOutputs', () => {
Expand Down

0 comments on commit 398d276

Please sign in to comment.