feat(core): add commands for debugging cache inputs / outputs#34414
feat(core): add commands for debugging cache inputs / outputs#34414FrozenPandaz merged 12 commits intomasterfrom
Conversation
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit e8eb696
☁️ Nx Cloud last updated this comment at |
e227453 to
689f62b
Compare
FrozenPandaz
left a comment
There was a problem hiding this comment.
Can we make this...
nx show target nx:build
nx show target inputs nx:build
nx show target inputs nx:build --check path/to/blah
nx show target outputs nx:build
nx show target outputs nx:build --check path/to/blah689f62b to
93a62e8
Compare
93a62e8 to
4aaadb7
Compare
e2e/nx/src/misc.test.ts
Outdated
|
|
||
| it('should check a matching input file and exit 0', () => { | ||
| // Get the list of inputs first | ||
| const inputs = JSON.parse( |
There was a problem hiding this comment.
Let's check for the main.ts.. this seems like cheating
e2e/nx/src/misc.test.ts
Outdated
|
|
||
| it('should check a matching output path and exit 0', () => { | ||
| const outputs = JSON.parse( | ||
| runCLI(`show target outputs ${app}:build --json`) |
e2e/nx/src/misc.test.ts
Outdated
| `show target inputs ${app}:build --check apps/${app}/src --json` | ||
| ) | ||
| ); | ||
| expect(result.isInput).toBe(false); |
There was a problem hiding this comment.
This is awkward and not well thought out yet.. let's remove this functionality for now.
| expect(output).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| it('should render output paths', () => { |
| description: | ||
| 'The target to inspect, in the format project:target or just target.', | ||
| }) | ||
| .option('configuration', { |
| String(uniquePaths.size) | ||
| )} output path(s) for ${c.cyan(data.project)}:${c.green(data.target)}` | ||
| ); | ||
| printList('Configured outputs', data.containedOutputPaths, '\n'); |
There was a problem hiding this comment.
drop the configured outputs from check..
| HashInstruction::TaskOutput(_glob, dep_outputs) => HashInputsBuilder { | ||
| dep_outputs: dep_outputs.iter().cloned().collect(), | ||
| ..Default::default() | ||
| }, |
There was a problem hiding this comment.
This probably needs the glob?
| let files: HashSet<String> = self | ||
| .all_workspace_files | ||
| .iter() | ||
| .filter(|f| { | ||
| !f.file.contains('/') | ||
| && f.file.starts_with("tsconfig") | ||
| && f.file.ends_with(".json") | ||
| }) | ||
| .map(|f| f.file.clone()) | ||
| .collect(); |
There was a problem hiding this comment.
This should only be 1 of tsconfig.json or tsconfig.base.json
| let mut files = HashSet::new(); | ||
| if let Some(project) = self.project_graph.nodes.get(project_name) { | ||
| let project_json = format!("{}/project.json", project.root); | ||
| let package_json = format!("{}/package.json", project.root); | ||
| if self | ||
| .all_workspace_files | ||
| .iter() | ||
| .any(|f| f.file == project_json) | ||
| { | ||
| files.insert(project_json); | ||
| } else if self | ||
| .all_workspace_files | ||
| .iter() | ||
| .any(|f| f.file == package_json) | ||
| { | ||
| files.insert(package_json); | ||
| } | ||
| } | ||
| HashInputsBuilder { | ||
| files, | ||
| ..Default::default() | ||
| } |
There was a problem hiding this comment.
Remove these files... for now.... we'll need to work out how to utilize the source map... to get a full list of files considered to create the project configuration
| @@ -49,6 +49,13 @@ export declare class FileLock { | |||
| export declare class HashPlanInspector { | |||
| constructor(allWorkspaceFiles: ExternalObject<Array<FileData>>, projectGraph: ExternalObject<ProjectGraph>, projectFileMap: ExternalObject<Record<string, Array<FileData>>>) | |||
| inspect(hashPlans: ExternalObject<Record<string, Array<HashInstruction>>>): Record<string, string[]> | |||
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
packages/devkit/tsconfig.json
Outdated
| ], | ||
| "nx": { | ||
| "addTypecheckTarget": false | ||
| // "addTypecheckTarget": false |
| printList('Configured outputs', data.outputPaths); | ||
| } | ||
| const extraExpanded = data.expandedOutputs.filter( | ||
| (o) => !data.outputPaths.includes(o) |
| } | ||
| await showTargetInfoHandler(args); | ||
| }); | ||
| process.exit(exitCode); |
There was a problem hiding this comment.
| process.exit(exitCode); | |
| process.exit(process.exitCode || exitCode); |
6de2b68 to
d0fddb9
Compare
🐳 We have a release for that!This PR has a release associated with it. You can try it out using this command: npx create-nx-workspace@22.6.0-pr.34414.d0fddb9 my-workspaceOr just copy this version and use it in your own command: 22.6.0-pr.34414.d0fddb9
To request a new release for this pull request, mention someone from the Nx team or the |
…ests Failed tasks: nx:lint, e2e-nx:e2e-ci--src/misc.test.ts Local verification: enhanced
Failed tasks: e2e-nx:e2e-ci--src/misc.test.ts Local verification: enhanced
eb808a5 to
c8d6b87
Compare
There was a problem hiding this comment.
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud is proposing a fix for your failed CI:
These changes complete the deterministic rendering fix for the nx show target command. The previous commit added sorting to renderInputs() but missed the expandInputsForDisplay() function, causing snapshot test failures due to non-deterministic input ordering when named inputs were expanded.
Note
⏳ We are verifying this fix by re-running a subset of the 2 failed tasks that were analyzed.
Suggested Fix changes
diff --git a/e2e/nx/src/__snapshots__/misc.test.ts.snap b/e2e/nx/src/__snapshots__/misc.test.ts.snap
index a4205b32c8..c41689f0d7 100644
--- a/e2e/nx/src/__snapshots__/misc.test.ts.snap
+++ b/e2e/nx/src/__snapshots__/misc.test.ts.snap
@@ -73,11 +73,12 @@ Options:
args: ["--node-env=production"]
command: "webpack-cli build"
Inputs:
- - default
+ - !{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)
- !{projectRoot}/.eslintrc.json
- !{projectRoot}/eslint.config.mjs
- - !{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)
+ - !{projectRoot}/src/test-setup.[jt]s
- !{projectRoot}/tsconfig.spec.json
+ - default
- ^production
- {"externalDependencies":["webpack-cli"]}
Outputs:
diff --git a/packages/nx/src/command-line/show/target.ts b/packages/nx/src/command-line/show/target.ts
index 61d6e82583..7070d659dd 100644
--- a/packages/nx/src/command-line/show/target.ts
+++ b/packages/nx/src/command-line/show/target.ts
@@ -828,7 +828,31 @@ function expandInputsForDisplay(
}
}
- return result;
+ // Sort for deterministic rendering: group by type, then sort within each group
+ return result.sort((a, b) => {
+ const aIsString = typeof a === 'string';
+ const bIsString = typeof b === 'string';
+
+ // Objects come after strings
+ if (!aIsString && bIsString) return 1;
+ if (aIsString && !bIsString) return -1;
+
+ // Both are strings
+ if (aIsString && bIsString) {
+ const aIsDep = a.startsWith('^');
+ const bIsDep = b.startsWith('^');
+
+ // Dependency inputs (^) come after regular inputs
+ if (aIsDep && !bIsDep) return 1;
+ if (!aIsDep && bIsDep) return -1;
+
+ // Sort within the same category
+ return a.localeCompare(b);
+ }
+
+ // Both are objects - maintain order (stable sort)
+ return 0;
+ });
}
/**
Or Apply changes locally with:
npx nx-cloud apply-locally F8XB-L6os
Apply fix locally with your editor ↗ View interactive diff ↗
🎓 Learn more about Self-Healing CI on nx.dev
Sort inputs by category (regular strings → dependency inputs → objects) to avoid locale-dependent ordering of ^ prefix vs letters.
localeCompare produces different orderings for special characters like * vs . across different locales/environments.
Current Behavior
There's not a great way to troubleshoot or test inputs and outputs configurations on tasks.
Expected Behavior
Adds
nx show targetto enable users to debug inputs and outputs. It has flags--inputs,--check-input,--outputs, and--check-outputto list or test specific file patterns.