fix(core): fix output text for multiple targets (#28043)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
4fedc409fa
commit
05f16cfbdd
@ -1,4 +1,5 @@
|
|||||||
import { formatFlags } from './formatting-utils';
|
import { output } from '../../utils/output';
|
||||||
|
import { formatFlags, formatTargetsAndProjects } from './formatting-utils';
|
||||||
|
|
||||||
describe('formatFlags', () => {
|
describe('formatFlags', () => {
|
||||||
it('should properly show string values', () => {
|
it('should properly show string values', () => {
|
||||||
@ -42,3 +43,339 @@ describe('formatFlags', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('formatTargetsAndProjects', () => {
|
||||||
|
it('should handle single project and target', () => {
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject:build',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'build',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(`target ${output.bold('build')} for project myproject`);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject:lint',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'lint',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(`target ${output.bold('lint')} for project myproject`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle single project and multiple targets', () => {
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject:build',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'build',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'myproject:test',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'test',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(
|
||||||
|
`targets ${output.bold('build')}, ${output.bold(
|
||||||
|
'test'
|
||||||
|
)} for project myproject`
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject', 'myproject2'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject:lint',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'lint',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(`target ${output.bold('lint')} for project myproject`);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject', 'myproject2'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject2:lint',
|
||||||
|
target: {
|
||||||
|
project: 'myproject2',
|
||||||
|
target: 'lint',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(`target ${output.bold('lint')} for project myproject2`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle multiple projects and targets', () => {
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject', 'myproject2'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject:build',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'build',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'myproject2:build',
|
||||||
|
target: {
|
||||||
|
project: 'myproject2',
|
||||||
|
target: 'build',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(`target ${output.bold('build')} for 2 projects`);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject', 'myproject2'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject:lint',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'lint',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'myproject2:lint',
|
||||||
|
target: {
|
||||||
|
project: 'myproject2',
|
||||||
|
target: 'lint',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(`target ${output.bold('lint')} for 2 projects`);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject', 'myproject2'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject:lint',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'lint',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'myproject2:build',
|
||||||
|
target: {
|
||||||
|
project: 'myproject2',
|
||||||
|
target: 'build',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(
|
||||||
|
`targets ${output.bold('lint')}, ${output.bold('build')} for 2 projects`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle dependent tasks', () => {
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject', 'myproject2'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject:build',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'build',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'myproject3:build',
|
||||||
|
target: {
|
||||||
|
project: 'myproject3',
|
||||||
|
target: 'build',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(
|
||||||
|
`target ${output.bold('build')} for project myproject and ${output.bold(
|
||||||
|
1
|
||||||
|
)} task it depends on`
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject', 'myproject2'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject:lint',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'lint',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'myproject2:lint',
|
||||||
|
target: {
|
||||||
|
project: 'myproject2',
|
||||||
|
target: 'lint',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'myproject3:lint',
|
||||||
|
target: {
|
||||||
|
project: 'myproject3',
|
||||||
|
target: 'lint',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(
|
||||||
|
`target ${output.bold('lint')} for 2 projects and ${output.bold(
|
||||||
|
1
|
||||||
|
)} task they depend on`
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
formatTargetsAndProjects(
|
||||||
|
['myproject', 'myproject2'],
|
||||||
|
['lint', 'build', 'test'],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: 'myproject:lint',
|
||||||
|
target: {
|
||||||
|
project: 'myproject',
|
||||||
|
target: 'lint',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'myproject2:build',
|
||||||
|
target: {
|
||||||
|
project: 'myproject2',
|
||||||
|
target: 'build',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'myproject3:build',
|
||||||
|
target: {
|
||||||
|
project: 'myproject3',
|
||||||
|
target: 'build',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'myproject3:bundle',
|
||||||
|
target: {
|
||||||
|
project: 'myproject3',
|
||||||
|
target: 'bundle',
|
||||||
|
},
|
||||||
|
overrides: {},
|
||||||
|
parallelism: false,
|
||||||
|
outputs: [],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
).toEqual(
|
||||||
|
`targets ${output.bold('lint')}, ${output.bold(
|
||||||
|
'build'
|
||||||
|
)} for 2 projects and ${output.bold(2)} tasks they depend on`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -26,32 +26,45 @@ export function formatTargetsAndProjects(
|
|||||||
targets: string[],
|
targets: string[],
|
||||||
tasks: Task[]
|
tasks: Task[]
|
||||||
) {
|
) {
|
||||||
if (tasks.length === 1)
|
let targetsText = '';
|
||||||
return `target ${targets[0]} for project ${projectNames[0]}`;
|
let projectsText = '';
|
||||||
|
let dependentTasksText = '';
|
||||||
|
|
||||||
|
const tasksTargets = new Set();
|
||||||
|
const tasksProjects = new Set();
|
||||||
|
const dependentTasks = new Set();
|
||||||
|
|
||||||
|
tasks.forEach((task) => {
|
||||||
|
tasksTargets.add(task.target.target);
|
||||||
|
tasksProjects.add(task.target.project);
|
||||||
|
if (
|
||||||
|
!projectNames.includes(task.target.project) ||
|
||||||
|
!targets.includes(task.target.target)
|
||||||
|
) {
|
||||||
|
dependentTasks.add(task);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
targets = targets.filter((t) => tasksTargets.has(t)); // filter out targets that don't exist
|
||||||
|
projectNames = projectNames.filter((p) => tasksProjects.has(p)); // filter out projects that don't exist
|
||||||
|
|
||||||
let text;
|
|
||||||
const project =
|
|
||||||
projectNames.length === 1
|
|
||||||
? `project ${projectNames[0]}`
|
|
||||||
: `${projectNames.length} projects`;
|
|
||||||
if (targets.length === 1) {
|
if (targets.length === 1) {
|
||||||
text = `target ${output.bold(targets[0])} for ${project}`;
|
targetsText = `target ${output.bold(targets[0])}`;
|
||||||
} else {
|
} else {
|
||||||
text = `targets ${targets
|
targetsText = `targets ${targets.map((t) => output.bold(t)).join(', ')}`;
|
||||||
.map((t) => output.bold(t))
|
|
||||||
.join(', ')} for ${project}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dependentTasks = tasks.filter(
|
if (projectNames.length === 1) {
|
||||||
(t) =>
|
projectsText = `project ${projectNames[0]}`;
|
||||||
projectNames.indexOf(t.target.project) === -1 ||
|
} else {
|
||||||
targets.indexOf(t.target.target) === -1
|
projectsText = `${projectNames.length} projects`;
|
||||||
).length;
|
}
|
||||||
|
|
||||||
if (dependentTasks > 0) {
|
if (dependentTasks.size > 0) {
|
||||||
text += ` and ${output.bold(dependentTasks)} ${
|
dependentTasksText = ` and ${output.bold(dependentTasks.size)} ${
|
||||||
dependentTasks === 1 ? 'task' : 'tasks'
|
dependentTasks.size === 1 ? 'task' : 'tasks'
|
||||||
} ${projectNames.length === 1 ? 'it depends on' : 'they depend on'}`;
|
} ${projectNames.length === 1 ? 'it depends on' : 'they depend on'}`;
|
||||||
}
|
}
|
||||||
return text;
|
|
||||||
|
return `${targetsText} for ${projectsText}${dependentTasksText}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user