Skip to content

Commit

Permalink
fix(core): correctly set default configuration name for dependent tasks
Browse files Browse the repository at this point in the history
(cherry picked from commit ea440ae)
  • Loading branch information
vsavkin authored and FrozenPandaz committed Feb 15, 2023
1 parent 14cd02b commit 7954426
Show file tree
Hide file tree
Showing 3 changed files with 287 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ jobs:
SELECTED_PM: << parameters.pm >>
NX_E2E_RUN_CYPRESS: 'false'
NX_VERBOSE_LOGGING: 'true'
NX_PERF_LOGGING: 'true'
NX_PERF_LOGGING: 'false'
NX_NATIVE_HASHER: 'true'
steps:
- run:
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:
NX_E2E_CI_CACHE_KEY: e2e-circleci-linux
NX_VERBOSE_LOGGING: 'true'
NX_DAEMON: 'true'
NX_PERF_LOGGING: 'true'
NX_PERF_LOGGING: 'false'
NX_NATIVE_HASHER: 'true'
steps:
- run:
Expand Down Expand Up @@ -222,7 +222,7 @@ jobs:
environment:
NX_E2E_CI_CACHE_KEY: e2e-circleci-macos
NX_DAEMON: 'true'
NX_PERF_LOGGING: 'true'
NX_PERF_LOGGING: 'false'
NX_NATIVE_HASHER: 'true'
steps:
- run:
Expand Down
273 changes: 272 additions & 1 deletion packages/nx/src/tasks-runner/create-task-graph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,278 @@ describe('createTaskGraph', () => {
});
});

it('should correctly set default configuration', () => {
const projectGraph = {
nodes: {
app1: {
name: 'app1',
type: 'app',
data: {
root: 'app1-root',
files: [],
targets: {
build: {
executor: 'my-executor',
configurations: {
ci: {},
},
dependsOn: [
{
projects: 'dependencies',
target: 'build',
},
],
},
},
},
},
lib1: {
name: 'lib1',
type: 'lib',
data: {
root: 'lib1-root',
files: [],
targets: {
build: {
executor: 'my-executor',
configurations: {
libDefault: {},
},
defaultConfiguration: 'libDefault',
dependsOn: [
{
projects: 'dependencies',
target: 'build',
},
],
},
},
},
},
lib2: {
name: 'lib2',
type: 'lib',
data: {
root: 'lib2-root',
files: [],
targets: {
build: {
executor: 'my-executor',
configurations: {
ci: {},
},
},
},
},
},
},
dependencies: {
app1: [{ source: 'app1', target: 'lib1', type: 'static' }],
lib1: [{ source: 'lib1', target: 'lib2', type: 'static' }],
lib2: [],
},
} as any;

const buildLib = createTaskGraph(
projectGraph,
{},
['lib1'],
['build'],
null,
{}
);

expect(buildLib).toEqual({
roots: ['lib2:build'],
tasks: {
'lib1:build:libDefault': {
id: 'lib1:build:libDefault',
target: {
project: 'lib1',
target: 'build',
configuration: 'libDefault',
},
overrides: {},
projectRoot: 'lib1-root',
},
'lib2:build': {
id: 'lib2:build',
target: {
project: 'lib2',
target: 'build',
},
overrides: {
__overrides_unparsed__: [],
},
projectRoot: 'lib2-root',
},
},
dependencies: {
'lib1:build:libDefault': ['lib2:build'],
'lib2:build': [],
},
});

const buildApp = createTaskGraph(
projectGraph,
{},
['app1'],
['build'],
'ci',
{}
);

expect(buildApp).toEqual({
roots: ['lib2:build:ci'],
tasks: {
'app1:build:ci': {
id: 'app1:build:ci',
target: {
project: 'app1',
target: 'build',
configuration: 'ci',
},
overrides: {},
projectRoot: 'app1-root',
},
'lib1:build:libDefault': {
id: 'lib1:build:libDefault',
target: {
project: 'lib1',
target: 'build',
configuration: 'libDefault',
},
overrides: {
__overrides_unparsed__: [],
},
projectRoot: 'lib1-root',
},
'lib2:build:ci': {
id: 'lib2:build:ci',
target: {
project: 'lib2',
target: 'build',
configuration: 'ci',
},
overrides: {
__overrides_unparsed__: [],
},
projectRoot: 'lib2-root',
},
},
dependencies: {
'app1:build:ci': ['lib1:build:libDefault'],
'lib1:build:libDefault': ['lib2:build:ci'],
'lib2:build:ci': [],
},
});
});

it('should not duplicate dependencies', () => {
const projectGraph = {
nodes: {
app1: {
name: 'app1',
type: 'app',
data: {
root: 'app1-root',
files: [],
targets: {
build: {
executor: 'my-executor',
dependsOn: [
{
projects: 'dependencies',
target: 'build',
},
],
},
},
},
},
lib1: {
name: 'lib1',
type: 'lib',
data: {
root: 'lib1-root',
files: [],
targets: {},
},
},
lib2: {
name: 'lib2',
type: 'lib',
data: {
root: 'lib2-root',
files: [],
targets: {},
},
},
lib3: {
name: 'lib3',
type: 'lib',
data: {
root: 'lib3-root',
files: [],
targets: {
build: {
executor: 'my-executor',
},
},
},
},
},
dependencies: {
app1: [
{ source: 'app1', target: 'lib1', type: 'static' },
{ source: 'app1', target: 'lib2', type: 'static' },
],
lib1: [{ source: 'lib1', target: 'lib3', type: 'static' }],
lib2: [{ source: 'lib2', target: 'lib3', type: 'static' }],
lib3: [],
},
} as any;

const buildApp = createTaskGraph(
projectGraph,
{},
['app1'],
['build'],
null,
{}
);

expect(buildApp).toEqual({
dependencies: {
'app1:build': ['lib3:build'],
'lib3:build': [],
},
roots: ['lib3:build'],
tasks: {
'app1:build': {
id: 'app1:build',
overrides: {},
projectRoot: 'app1-root',
target: {
project: 'app1',
target: 'build',
},
},
'lib3:build': {
id: 'lib3:build',
overrides: {
__overrides_unparsed__: [],
},
projectRoot: 'lib3-root',
target: {
project: 'lib3',
target: 'build',
},
},
},
});
});

it('should interpolate overrides', () => {
const oneTask = createTaskGraph(
projectGraph,
Expand Down Expand Up @@ -758,7 +1030,6 @@ describe('createTaskGraph', () => {
'app2:build',
'coreInfra:apply',
'app1:build',
'coreInfra:apply',
'infra2:apply',
],
'app2:build': [],
Expand Down
14 changes: 12 additions & 2 deletions packages/nx/src/tasks-runner/create-task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ export class ProcessTasks {
}
}

for (const projectName of Object.keys(this.dependencies)) {
if (this.dependencies[projectName].length > 1) {
this.dependencies[projectName] = [
...new Set(this.dependencies[projectName]).values(),
];
}
}

return Object.keys(this.dependencies).filter(
(d) => this.dependencies[d].length === 0
);
Expand Down Expand Up @@ -224,10 +232,12 @@ export class ProcessTasks {
target: string,
configuration: string | undefined
) {
configuration ??= project.data.targets?.[target]?.defaultConfiguration;
const defaultConfiguration =
project.data.targets?.[target]?.defaultConfiguration;
configuration ??= defaultConfiguration;
return projectHasTargetAndConfiguration(project, target, configuration)
? configuration
: undefined;
: defaultConfiguration;
}

getId(
Expand Down

0 comments on commit 7954426

Please sign in to comment.