fix(js): narrow tsc build-base outputs to only tsc-produced file types#35041
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 a3eaeda
☁️ Nx Cloud last updated this comment at |
78e963e to
ec7e445
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:
We updated the inline snapshot for the isValidPackageJsonBuildConfig test case where outDir is outside the project root to match the narrowed output glob pattern introduced by the PR. The snapshot expected the bare path "external-build" but the updated plugin now appends /**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map} to scope outputs to only tsc-produced file types. This fix brings the test in line with the new behavior.
Warning
❌ We could not verify this fix.
diff --git a/packages/js/src/plugins/typescript/plugin.spec.ts b/packages/js/src/plugins/typescript/plugin.spec.ts
index 86fc74dbee..ad53f014ec 100644
--- a/packages/js/src/plugins/typescript/plugin.spec.ts
+++ b/packages/js/src/plugins/typescript/plugin.spec.ts
@@ -6479,7 +6479,7 @@ describe(`Plugin: ${PLUGIN_NAME}`, () => {
"cwd": "libs/my-lib",
},
"outputs": [
- "external-build",
+ "external-build/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}",
],
"syncGenerators": [
"@nx/js:typescript-sync",
🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.
Or Apply changes locally with:
npx nx-cloud apply-locally UCXr-yG9X
Apply fix locally with your editor ↗ View interactive diff ↗
🎓 Learn more about Self-Healing CI on nx.dev
ec7e445 to
f1aacde
Compare
a7f90d5 to
d556075
Compare
When outDir is set, the @nx/js/typescript plugin previously claimed the
entire outDir as output. This caused cross-OS cache pollution when other
tasks (e.g. copy-assets for .node/.wasm files) write into the same
directory — linux native binaries would be cached and restored on macOS.
Now outputs are scoped to only file types tsc actually produces:
**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}
d556075 to
a3eaeda
Compare
The narrowed output globs from #35041 excluded .tsbuildinfo files. Since tsc --build always produces tsbuildinfo (incremental is implicit), extract a getTsBuildInfoOutputPath helper and call it unconditionally at the end of the output resolution loop. Fixes the missing cache output for tsbuildinfo files.
## Current Behavior PR #35041 narrowed the `build-base` target outputs to only match tsc-produced file types (e.g. `**/*.{js,d.ts,...}{,.map}`), preventing cross-OS cache pollution from native binaries. However, `.tsbuildinfo` files were not included in the narrowed glob, so they are no longer captured as build outputs. The tsbuildinfo handling was also spread across multiple conditional branches with duplicated logic. ## Expected Behavior `.tsbuildinfo` files are always included as a build output since `tsc --build` implicitly enables `incremental: true` and always produces them. A new `getTsBuildInfoOutputPath` helper centralizes the logic for determining the tsbuildinfo file location (respecting `tsBuildInfoFile`, `outFile`, `outDir`, or the default), and is called once unconditionally at the end of the output resolution loop. ## Related Issue(s) Follow-up to #35041
#35041) ## Current Behavior The `@nx/js/typescript` plugin claims the entire `outDir` (e.g. `{projectRoot}/dist`) as the output for `build-base` targets. When other tasks like `copy-assets` also write into the same directory (e.g. `.node` or `.wasm` native binaries), those files get captured in the `build-base` cache. This causes cross-OS cache pollution — linux native binaries get cached and restored on macOS (or vice versa). ## Expected Behavior `build-base` outputs are scoped to only the file types that `tsc` actually produces: - `**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}` (default) - `**/*.{js,cjs,mjs,jsx,json,d.ts,d.cts,d.mts}{,.map}` (when `resolveJsonModule` is enabled) Native binaries (`.node`, `.wasm`) and other non-tsc files in the same output directory are no longer captured by the `build-base` cache, preventing cross-OS cache corruption. ## Related Issue(s) N/A — discovered during investigation of cross-OS cache artifacts. (cherry picked from commit f39f304)
## Current Behavior PR #35041 narrowed the `build-base` target outputs to only match tsc-produced file types (e.g. `**/*.{js,d.ts,...}{,.map}`), preventing cross-OS cache pollution from native binaries. However, `.tsbuildinfo` files were not included in the narrowed glob, so they are no longer captured as build outputs. The tsbuildinfo handling was also spread across multiple conditional branches with duplicated logic. ## Expected Behavior `.tsbuildinfo` files are always included as a build output since `tsc --build` implicitly enables `incremental: true` and always produces them. A new `getTsBuildInfoOutputPath` helper centralizes the logic for determining the tsbuildinfo file location (respecting `tsBuildInfoFile`, `outFile`, `outDir`, or the default), and is called once unconditionally at the end of the output resolution loop. ## Related Issue(s) Follow-up to #35041 (cherry picked from commit b1d8db3)
|
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. |
Current Behavior
The
@nx/js/typescriptplugin claims the entireoutDir(e.g.{projectRoot}/dist) as the output forbuild-basetargets. When other tasks likecopy-assetsalso write into the same directory (e.g..nodeor.wasmnative binaries), those files get captured in thebuild-basecache. This causes cross-OS cache pollution — linux native binaries get cached and restored on macOS (or vice versa).Expected Behavior
build-baseoutputs are scoped to only the file types thattscactually produces:**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}(default)**/*.{js,cjs,mjs,jsx,json,d.ts,d.cts,d.mts}{,.map}(whenresolveJsonModuleis enabled)Native binaries (
.node,.wasm) and other non-tsc files in the same output directory are no longer captured by thebuild-basecache, preventing cross-OS cache corruption.Related Issue(s)
N/A — discovered during investigation of cross-OS cache artifacts.