From 2c0a50c0d8f45f65c9a91e1426fc2e66a29af3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Twardziak?= <81327266+paweltwardziak@users.noreply.github.com> Date: Sat, 24 Aug 2024 00:20:59 +0200 Subject: [PATCH] feat(core): expose graph json type (#27496) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3283 ## Current Behavior See #3283 ## Expected Behavior See #3283 ## Related Issue(s) #3283 Fixes # - expose graph json type --------- Co-authored-by: @NgDaddy Paweł Twardziak Co-authored-by: FrozenPandaz --- docs/generated/devkit/GraphJson.md | 35 +++++++++++++++++++ docs/generated/devkit/README.md | 1 + .../packages/devkit/documents/nx_devkit.md | 1 + packages/nx/src/command-line/graph/graph.ts | 18 ++++++++-- packages/nx/src/devkit-exports.ts | 2 ++ 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 docs/generated/devkit/GraphJson.md diff --git a/docs/generated/devkit/GraphJson.md b/docs/generated/devkit/GraphJson.md new file mode 100644 index 0000000000000..349d669498213 --- /dev/null +++ b/docs/generated/devkit/GraphJson.md @@ -0,0 +1,35 @@ +# Interface: GraphJson + +The data type that `nx graph --file graph.json` or `nx build --graph graph.json` contains + +## Table of contents + +### Properties + +- [graph](../../devkit/documents/GraphJson#graph): ProjectGraph +- [taskPlans](../../devkit/documents/GraphJson#taskplans): Record +- [tasks](../../devkit/documents/GraphJson#tasks): TaskGraph + +## Properties + +### graph + +• **graph**: [`ProjectGraph`](../../devkit/documents/ProjectGraph) + +The project graph + +--- + +### taskPlans + +• `Optional` **taskPlans**: `Record`\<`string`, `string`[]\> + +The plans for hashing a task in the task graph + +--- + +### tasks + +• `Optional` **tasks**: [`TaskGraph`](../../devkit/documents/TaskGraph) + +A graph of tasks populated with `nx build --graph` diff --git a/docs/generated/devkit/README.md b/docs/generated/devkit/README.md index 0b9bc52845183..b3aff0c2758cf 100644 --- a/docs/generated/devkit/README.md +++ b/docs/generated/devkit/README.md @@ -35,6 +35,7 @@ It only uses language primitives and immutable objects - [FileData](../../devkit/documents/FileData) - [FileMap](../../devkit/documents/FileMap) - [GeneratorsJson](../../devkit/documents/GeneratorsJson) +- [GraphJson](../../devkit/documents/GraphJson) - [Hash](../../devkit/documents/Hash) - [HasherContext](../../devkit/documents/HasherContext) - [ImplicitJsonSubsetDependency](../../devkit/documents/ImplicitJsonSubsetDependency) diff --git a/docs/generated/packages/devkit/documents/nx_devkit.md b/docs/generated/packages/devkit/documents/nx_devkit.md index 0b9bc52845183..b3aff0c2758cf 100644 --- a/docs/generated/packages/devkit/documents/nx_devkit.md +++ b/docs/generated/packages/devkit/documents/nx_devkit.md @@ -35,6 +35,7 @@ It only uses language primitives and immutable objects - [FileData](../../devkit/documents/FileData) - [FileMap](../../devkit/documents/FileMap) - [GeneratorsJson](../../devkit/documents/GeneratorsJson) +- [GraphJson](../../devkit/documents/GraphJson) - [Hash](../../devkit/documents/Hash) - [HasherContext](../../devkit/documents/HasherContext) - [ImplicitJsonSubsetDependency](../../devkit/documents/ImplicitJsonSubsetDependency) diff --git a/packages/nx/src/command-line/graph/graph.ts b/packages/nx/src/command-line/graph/graph.ts index 9f994085e2fca..ca8c4edda2284 100644 --- a/packages/nx/src/command-line/graph/graph.ts +++ b/packages/nx/src/command-line/graph/graph.ts @@ -1155,9 +1155,21 @@ function expandInputs( }; } -interface GraphJsonResponse { +/** + * The data type that `nx graph --file graph.json` or `nx build --graph graph.json` contains + */ +export interface GraphJson { + /** + * A graph of tasks populated with `nx build --graph` + */ tasks?: TaskGraph; + /** + * The plans for hashing a task in the task graph + */ taskPlans?: Record; + /** + * The project graph + */ graph: ProjectGraph; } @@ -1166,8 +1178,8 @@ async function createJsonOutput( rawGraph: ProjectGraph, projects: string[], targets?: string[] -): Promise { - const response: GraphJsonResponse = { +): Promise { + const response: GraphJson = { graph: prunedGraph, }; diff --git a/packages/nx/src/devkit-exports.ts b/packages/nx/src/devkit-exports.ts index 3477936477d55..a51e64914f825 100644 --- a/packages/nx/src/devkit-exports.ts +++ b/packages/nx/src/devkit-exports.ts @@ -159,6 +159,8 @@ export type { ProjectGraphProcessorContext, } from './config/project-graph'; +export type { GraphJson } from './command-line/graph/graph'; + /** * @category Project Graph */