Skip to content

Commit

Permalink
fix(core): prune project graph after affected nodes are found to avoi…
Browse files Browse the repository at this point in the history
…d errors
  • Loading branch information
jaysoo committed Jun 19, 2023
1 parent ef5813a commit 77ab6f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions e2e/nx-run/src/affected-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ describe('Nx Affected and Graph Tests', () => {
expect(model).toHaveProperty('tasks');
});

it('affected:graph should include affected projects in environment file', () => {
runCLI(`affected:graph --file=project-graph.html`);
it('should include affected projects in environment file', () => {
runCLI(`graph --affected --file=project-graph.html`);

const environmentJs = readFile('static/environment.js');
const affectedProjects = environmentJs
Expand Down
21 changes: 13 additions & 8 deletions packages/nx/src/command-line/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,12 @@ export async function generateGraph(
? args.targets[0]
: args.targets;

let graph = pruneExternalNodes(
await createProjectGraphAsync({ exitOnError: true })
);
const rawGraph = await createProjectGraphAsync({ exitOnError: true });
let prunedGraph = pruneExternalNodes(rawGraph);

const projects = Object.values(graph.nodes) as ProjectGraphProjectNode[];
const projects = Object.values(
prunedGraph.nodes
) as ProjectGraphProjectNode[];
projects.sort((a, b) => {
return a.name.localeCompare(b.name);
});
Expand All @@ -243,7 +244,7 @@ export async function generateGraph(
{ printWarnings: true },
readNxJson()
).nxArgs,
graph
rawGraph
)
).map((n) => n.name);
}
Expand Down Expand Up @@ -271,14 +272,18 @@ export async function generateGraph(
'utf-8'
);

graph = filterGraph(graph, args.focus || null, args.exclude || []);
prunedGraph = filterGraph(
prunedGraph,
args.focus || null,
args.exclude || []
);

if (args.file) {
// stdout is a magical constant that doesn't actually write a file
if (args.file === 'stdout') {
console.log(
JSON.stringify(
createJsonOutput(graph, args.projects, args.targets),
createJsonOutput(prunedGraph, args.projects, args.targets),
null,
2
)
Expand Down Expand Up @@ -334,7 +339,7 @@ export async function generateGraph(
} else if (ext === '.json') {
ensureDirSync(dirname(fullFilePath));

const json = createJsonOutput(graph, args.projects, args.targets);
const json = createJsonOutput(prunedGraph, args.projects, args.targets);
json.affectedProjects = affectedProjects;
json.criticalPath = affectedProjects;

Expand Down

0 comments on commit 77ab6f8

Please sign in to comment.