Skip to content

Commit

Permalink
fix(core): fix graph calculation when there are mixed targets (#11418)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Jean <jasonjean1993@gmail.com>
  • Loading branch information
JakeGinnivan and FrozenPandaz committed Oct 27, 2022
1 parent cd4e983 commit edd1415
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 8 deletions.
148 changes: 148 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 @@ -486,6 +486,154 @@ describe('createTaskGraph', () => {
});
});

it('should handle-mix of targets', () => {
projectGraph = {
nodes: {
app1: {
name: 'app1',
type: 'app',
data: {
root: 'app1-root',
files: [],
targets: {
build: {},
},
},
},
app2: {
name: 'app2',
type: 'app',
data: {
root: 'app2-root',
files: [],
targets: {
build: {},
},
},
},
infra1: {
name: 'infra1',
type: 'app',
data: {
root: 'infra1-root',
files: [],
targets: {
apply: {},
},
},
},
infra2: {
name: 'infra2',
type: 'app',
data: {
root: 'infra2-root',
files: [],
targets: {
apply: {},
},
},
},
coreInfra: {
name: 'coreInfra',
type: 'app',
data: {
root: 'infra3-root',
files: [],
targets: {
apply: {},
},
},
},
},
dependencies: {
app1: [],
app2: [],
// Scenario is app 1 depends on app 2, so this extends to the infrastructure projects
infra1: [
{ source: 'infra1', target: 'coreInfra', type: 'implicit' },
{ source: 'infra1', target: 'infra2', type: 'implicit' },
{ source: 'infra1', target: 'app1', type: 'implicit' },
],
infra2: [
{ source: 'infra2', target: 'coreInfra', type: 'implicit' },
{ source: 'infra1', target: 'app2', type: 'implicit' },
],
coreInfra: [],
},
};

const taskGraph = createTaskGraph(
projectGraph,
{
build: ['^build'],
apply: [
{ projects: 'dependencies', target: 'build' },
{
projects: 'dependencies',
target: 'apply',
params: 'forward',
},
],
},
['infra1'],
['apply'],
'development',
{
myFlag: 'flag value',
}
);

// prebuild should also be in here
expect(taskGraph).toEqual({
roots: ['app2:build', 'coreInfra:apply', 'app1:build'],
tasks: {
'infra1:apply': {
id: 'infra1:apply',
target: { project: 'infra1', target: 'apply' },
projectRoot: 'infra1-root',
overrides: { myFlag: 'flag value' },
},
'app2:build': {
id: 'app2:build',
target: { project: 'app2', target: 'build' },
projectRoot: 'app2-root',
overrides: { __overrides_unparsed__: [] },
},
'coreInfra:apply': {
id: 'coreInfra:apply',
target: { project: 'coreInfra', target: 'apply' },
projectRoot: 'infra3-root',
overrides: { myFlag: 'flag value' },
},
'app1:build': {
id: 'app1:build',
target: { project: 'app1', target: 'build' },
projectRoot: 'app1-root',
overrides: { __overrides_unparsed__: [] },
},
'infra2:apply': {
id: 'infra2:apply',
target: { project: 'infra2', target: 'apply' },
projectRoot: 'infra2-root',
overrides: { myFlag: 'flag value' },
},
},
dependencies: {
'infra1:apply': [
'app2:build',
'coreInfra:apply',
'app1:build',
'coreInfra:apply',
'infra2:apply',
],
'app2:build': [],
'coreInfra:apply': [],
'app1:build': [],
'infra2:apply': ['app2:build', 'coreInfra:apply'],
},
});
});

it('should handle cycles within the same project', () => {
projectGraph = {
nodes: {
Expand Down
11 changes: 3 additions & 8 deletions packages/nx/src/tasks-runner/create-task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,11 @@ export class ProcessTasks {
newTask,
newTask.target.project,
configuration,
taskOverrides
overrides
);
}
} else {
this.processTask(
task,
depProject.name,
configuration,
taskOverrides
);
this.processTask(task, depProject.name, configuration, overrides);
}
}
} else {
Expand Down Expand Up @@ -180,7 +175,7 @@ export class ProcessTasks {
newTask,
newTask.target.project,
configuration,
taskOverrides
overrides
);
}
}
Expand Down

1 comment on commit edd1415

@vercel
Copy link

@vercel vercel bot commented on edd1415 Oct 27, 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-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.