Skip to content

fix(js): narrow tsc build-base outputs to only tsc-produced file types#35041

Merged
FrozenPandaz merged 1 commit into
masterfrom
fix/tsc-plugin-granular-outputs
Mar 27, 2026
Merged

fix(js): narrow tsc build-base outputs to only tsc-produced file types#35041
FrozenPandaz merged 1 commit into
masterfrom
fix/tsc-plugin-granular-outputs

Conversation

@FrozenPandaz

@FrozenPandaz FrozenPandaz commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

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.

@FrozenPandaz FrozenPandaz requested a review from a team as a code owner March 27, 2026 16:20
@FrozenPandaz FrozenPandaz requested a review from AgentEnder March 27, 2026 16:20
@netlify

netlify Bot commented Mar 27, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit a3eaeda
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69c6f4fe7a49fd000896df73
😎 Deploy Preview https://deploy-preview-35041--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Mar 27, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit a3eaeda
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69c6f4fe22e5e80008dc9ec7
😎 Deploy Preview https://deploy-preview-35041--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud

nx-cloud Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit a3eaeda

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 56m 30s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 6s View ↗
nx-cloud record -- pnpm nx conformance:check ✅ Succeeded 7s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-27 22:22:37 UTC

@FrozenPandaz FrozenPandaz force-pushed the fix/tsc-plugin-granular-outputs branch from 78e963e to ec7e445 Compare March 27, 2026 18:30

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Apply fix via Nx Cloud  Reject fix via Nx Cloud


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

@FrozenPandaz FrozenPandaz force-pushed the fix/tsc-plugin-granular-outputs branch from ec7e445 to f1aacde Compare March 27, 2026 19:00
@FrozenPandaz FrozenPandaz force-pushed the fix/tsc-plugin-granular-outputs branch 2 times, most recently from a7f90d5 to d556075 Compare March 27, 2026 20:45
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}
@FrozenPandaz FrozenPandaz force-pushed the fix/tsc-plugin-granular-outputs branch from d556075 to a3eaeda Compare March 27, 2026 21:22
@FrozenPandaz FrozenPandaz enabled auto-merge (squash) March 27, 2026 21:36
@FrozenPandaz FrozenPandaz merged commit f39f304 into master Mar 27, 2026
24 checks passed
@FrozenPandaz FrozenPandaz deleted the fix/tsc-plugin-granular-outputs branch March 27, 2026 22:22
FrozenPandaz added a commit that referenced this pull request Mar 30, 2026
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.
FrozenPandaz added a commit that referenced this pull request Mar 31, 2026
## 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
FrozenPandaz added a commit that referenced this pull request Mar 31, 2026
#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)
FrozenPandaz added a commit that referenced this pull request Mar 31, 2026
## 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)
@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

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 Apr 2, 2026
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