Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): ability to save task graph to a file when running --graph #16350

Merged
merged 3 commits into from
May 12, 2023

Conversation

AgentEnder
Copy link
Member

@AgentEnder AgentEnder commented Apr 17, 2023

Current Behavior

Saving the graph to a file is only supported for nx graph This looks like: nx graph --file output.json

Expected Behavior

You can also save the task graph when running nx ... --graph. The PR currently implements this like:
nx affected --target build --graph output.json

Deprecations

  • criticalPath and affected fields within json graph outputs are now deprecated

@vercel
Copy link

vercel bot commented Apr 17, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2023 10:09pm

@@ -31,11 +31,11 @@ Exclude certain projects from being processed

### graph
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

followup: Why is this here?

packages/nx/src/utils/command-line-utils.ts Outdated Show resolved Hide resolved
packages/nx/src/utils/command-line-utils.ts Outdated Show resolved Hide resolved
@@ -192,6 +193,7 @@ export function withDepGraphOptions(yargs: Argv): Argv {
describe:
'Output file (e.g. --file=output.json or --file=dep-graph.html)',
type: 'string',
alias: ['out'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove for now....

cc @philipjfulcher how do you think someone should be able to run nx graph so that it outputs to the terminal?

We are making nx graph --file stdout print to the terminal... but it looks kind of weird.. so our preliminary thought was nx graph --out stdout looks better.. but we don't have to make this identical to file. This could just be like --stdout or --print

@@ -246,6 +246,12 @@ export async function generateGraph(
graph = filterGraph(graph, args.focus || null, args.exclude || []);

if (args.file) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to alter this output to include tasks and omit affectedProjects and criticalPath.

Option 1:
tasks is the same as what print-affected has currently which is tasks: Task[]

Option 2:
tasks is the task graph so we have taskGraph: { roots: string[], tasks: Record<string, Task>, dependencies: Record<string, string[]> }

Copy link
Member Author

@AgentEnder AgentEnder May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Updated with option 2 🎉

There is a caveat. print-affected included task hashes, but they were sometimes not matching with the task hash as compared against the cache... See: #16153

Should we try to get accurate hashes this time, or just be ok with no hash?

@AgentEnder AgentEnder force-pushed the feat/save-task-graph-to-file branch from 21810e1 to efca0fc Compare May 12, 2023 20:33
@AgentEnder AgentEnder force-pushed the feat/save-task-graph-to-file branch from 37bb72a to 8c46a37 Compare May 12, 2023 22:05
@AgentEnder AgentEnder enabled auto-merge (squash) May 12, 2023 22:31
@AgentEnder AgentEnder merged commit b2470de into nrwl:master May 12, 2023
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants