Skip to content

Commit

Permalink
fix(core): fix print-affected not filtering on target (#12355)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Jean <jasonjean1993@gmail.com>
  • Loading branch information
jefflage and FrozenPandaz committed Oct 27, 2022
1 parent c0e5fb6 commit d9a2852
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
9 changes: 3 additions & 6 deletions e2e/nx-run/src/affected-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,26 +333,23 @@ describe('Nx Affected and Graph Tests', () => {
command: `${runNx} run ${myapp}:test`,
outputs: [`coverage/apps/${myapp}`],
});
compareTwoArrays(resWithTarget.projects, [`${myapp}-e2e`, myapp]);
compareTwoArrays(resWithTarget.projects, [myapp]);

const resWithTargetWithSelect1 = (
await runCLIAsync(
`print-affected --files=apps/${myapp}/src/app/app.element.spec.ts --target=test --select=projects`,
{ silent: true }
)
).stdout.trim();
compareTwoSerializedArrays(
resWithTargetWithSelect1,
`${myapp}-e2e, ${myapp}`
);
compareTwoSerializedArrays(resWithTargetWithSelect1, myapp);

const resWithTargetWithSelect2 = (
await runCLIAsync(
`print-affected --files=apps/${myapp}/src/app.element.spec.ts --target=test --select="tasks.target.project"`,
{ silent: true }
)
).stdout.trim();
compareTwoSerializedArrays(resWithTargetWithSelect2, `${myapp}`);
compareTwoSerializedArrays(resWithTargetWithSelect2, myapp);
}, 120000);

function compareTwoSerializedArrays(a: string, b: string) {
Expand Down
5 changes: 1 addition & 4 deletions packages/nx/src/command-line/affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,15 @@ export async function affected(

case 'print-affected':
if (nxArgs.target) {
const projectsWithTarget = allProjectsWithTarget(projects, nxArgs);
await printAffected(
projectsWithTarget,
projects,
allProjectsWithTarget(projects, nxArgs),
projectGraph,
{ nxJson },
nxArgs,
overrides
);
} else {
await printAffected(
[],
projects,
projectGraph,
{ nxJson },
Expand Down
24 changes: 12 additions & 12 deletions packages/nx/src/command-line/print-affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ import { workspaceRoot } from '../utils/workspace-root';
import { getPackageManagerCommand } from 'nx/src/utils/package-manager';

export async function printAffected(
affectedProjectsWithTargetAndConfig: ProjectGraphProjectNode[],
affectedProjects: ProjectGraphProjectNode[],
projectGraph: ProjectGraph,
{ nxJson }: { nxJson: NxJsonConfiguration },
nxArgs: NxArgs,
overrides: yargs.Arguments
) {
const projectNames = affectedProjects
.filter((p) => (nxArgs.type ? p.type === nxArgs.type : true))
.map((p) => p.name);
const tasksJson = await createTasks(
affectedProjectsWithTargetAndConfig.filter((p) =>
nxArgs.type ? p.type === nxArgs.type : true
),
projectGraph,
nxArgs,
nxJson,
overrides
const projectsForType = affectedProjects.filter((p) =>
nxArgs.type ? p.type === nxArgs.type : true
);
const projectNames = projectsForType.map((p) => p.name);
const tasksJson = nxArgs.target
? await createTasks(
projectsForType,
projectGraph,
nxArgs,
nxJson,
overrides
)
: [];
const result = {
tasks: tasksJson,
projects: projectNames,
Expand Down

1 comment on commit d9a2852

@vercel
Copy link

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

Please sign in to comment.