Skip to content

fix(dts): preserve inferred roots and diagnostics - #4947

Open
zackarychapple wants to merge 2 commits into
mainfrom
agent/fix-dts-temp-root
Open

fix(dts): preserve inferred roots and diagnostics#4947
zackarychapple wants to merge 2 commits into
mainfrom
agent/fix-dts-temp-root

Conversation

@zackarychapple

@zackarychapple zackarychapple commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix DTS temporary-project root inference and retain actionable TypeScript failure artifacts.

Root cause

When compilerOptions.rootDir was omitted, the DTS plugin inferred a root from the source tsconfig but did not include exposed workspace files outside that tsconfig's include set. The TypeScript 7 --listFilesOnly temporary config was also written under node_modules/.federation without the computed root, so TypeScript could infer the temporary directory as its source root and emit TS6059. When dependency scanning or declaration generation failed, temporary configs were deleted or the fatal compiler output was reduced to insufficient context.

Changes

  • Infer a segment-safe common root from project sources plus existing exposed/additional source files while preserving an explicit rootDir unchanged.
  • Write the computed rootDir into temporary dependency-scan configs.
  • Preserve the effective config and complete compiler output in deterministic paths:
    • .mf/diagnostics/dts/list-files/
    • .mf/diagnostics/dts/generate-types/
  • Record the exact compiler command and resolved TypeScript version; keep fatal generation diagnostics distinct from non-fatal dependency-scan fallback warnings.
  • Continue cleaning ephemeral configs after success or after a successful diagnostic copy, while retaining the original if artifact preservation itself fails.
  • Add regression coverage for TypeScript 5.9, 6.0, and 7.0, including exposed files outside include, dependency traversal, diagnostic persistence, and temp-config cleanup.
  • Document the diagnostic artifact locations and add a patch changeset.

Validation

  • pnpm install --frozen-lockfile --ignore-scripts
  • pnpm exec rstest run src/core/configurations/remotePlugin.test.ts src/core/lib/typeScriptCompiler.test.ts --passWithNoTests — 64 tests passed
  • pnpm --filter @module-federation/dts-plugin run lint
  • pnpm exec turbo run build --filter=@module-federation/dts-plugin --force — 7 tasks passed
  • pnpm exec turbo run test --filter=@module-federation/dts-plugin --force — 15 files / 176 tests passed
  • pnpm exec prettier --check .
  • pnpm exec changeset status

Notes

The build continues to print existing dependency declaration warnings from webpack/tapable/fast-uri; they are unchanged and do not fail the build.

Closes #4948

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b4ff38f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 47 packages
Name Type
@module-federation/dts-plugin Patch
@module-federation/cli Patch
@module-federation/enhanced Patch
@module-federation/manifest Patch
@module-federation/metro Patch
@module-federation/rspack Patch
@module-federation/modern-js-v3 Patch
@module-federation/modern-js Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/rsbuild-plugin Patch
@module-federation/rspress-plugin Patch
@module-federation/storybook-addon Patch
shared-tree-shaking-no-server-host Patch
shared-tree-shaking-no-server-provider Patch
@module-federation/metro-plugin-rnc-cli Patch
@module-federation/metro-plugin-rnef Patch
@module-federation/metro-plugin-rock Patch
shared-tree-shaking-with-server-host Patch
shared-tree-shaking-with-server-provider Patch
node-dynamic-remote-new-version Patch
node-dynamic-remote Patch
@module-federation/playground Patch
remote5 Patch
remote6 Patch
website-new Patch
@module-federation/runtime Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/sdk Patch
@module-federation/runtime-tools Patch
@module-federation/managers Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/devtools Patch
@module-federation/bridge-react Patch
@module-federation/bridge-vue3 Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/retry-plugin Patch
@module-federation/error-codes Patch
@module-federation/inject-external-runtime-core-plugin Patch
@module-federation/runtime-core Patch
create-module-federation Patch
@module-federation/treeshake-server Patch
@module-federation/treeshake-frontend Patch
@module-federation/esbuild Patch
@module-federation/observability-plugin Patch
@module-federation/utilities Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@module-federation/devtools

pnpm add https://pkg.pr.new/@module-federation/devtools@b4ff38f

@module-federation/cli

pnpm add https://pkg.pr.new/@module-federation/cli@b4ff38f

create-module-federation

pnpm add https://pkg.pr.new/create-module-federation@b4ff38f

@module-federation/dts-plugin

pnpm add https://pkg.pr.new/@module-federation/dts-plugin@b4ff38f

@module-federation/enhanced

pnpm add https://pkg.pr.new/@module-federation/enhanced@b4ff38f

@module-federation/error-codes

pnpm add https://pkg.pr.new/@module-federation/error-codes@b4ff38f

@module-federation/esbuild

pnpm add https://pkg.pr.new/@module-federation/esbuild@b4ff38f

@module-federation/managers

pnpm add https://pkg.pr.new/@module-federation/managers@b4ff38f

@module-federation/manifest

pnpm add https://pkg.pr.new/@module-federation/manifest@b4ff38f

@module-federation/metro

pnpm add https://pkg.pr.new/@module-federation/metro@b4ff38f

@module-federation/metro-plugin-rnc-cli

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnc-cli@b4ff38f

@module-federation/metro-plugin-rnef

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnef@b4ff38f

@module-federation/metro-plugin-rock

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rock@b4ff38f

@module-federation/modern-js

pnpm add https://pkg.pr.new/@module-federation/modern-js@b4ff38f

@module-federation/modern-js-v3

pnpm add https://pkg.pr.new/@module-federation/modern-js-v3@b4ff38f

@module-federation/native-federation-tests

pnpm add https://pkg.pr.new/@module-federation/native-federation-tests@b4ff38f

@module-federation/native-federation-typescript

pnpm add https://pkg.pr.new/@module-federation/native-federation-typescript@b4ff38f

@module-federation/nextjs-mf

pnpm add https://pkg.pr.new/@module-federation/nextjs-mf@b4ff38f

@module-federation/node

pnpm add https://pkg.pr.new/@module-federation/node@b4ff38f

@module-federation/observability-plugin

pnpm add https://pkg.pr.new/@module-federation/observability-plugin@b4ff38f

@module-federation/playground

pnpm add https://pkg.pr.new/@module-federation/playground@b4ff38f

@module-federation/retry-plugin

pnpm add https://pkg.pr.new/@module-federation/retry-plugin@b4ff38f

@module-federation/rsbuild-plugin

pnpm add https://pkg.pr.new/@module-federation/rsbuild-plugin@b4ff38f

@module-federation/rspack

pnpm add https://pkg.pr.new/@module-federation/rspack@b4ff38f

@module-federation/rspress-plugin

pnpm add https://pkg.pr.new/@module-federation/rspress-plugin@b4ff38f

@module-federation/runtime

pnpm add https://pkg.pr.new/@module-federation/runtime@b4ff38f

@module-federation/runtime-core

pnpm add https://pkg.pr.new/@module-federation/runtime-core@b4ff38f

@module-federation/runtime-tools

pnpm add https://pkg.pr.new/@module-federation/runtime-tools@b4ff38f

@module-federation/sdk

pnpm add https://pkg.pr.new/@module-federation/sdk@b4ff38f

@module-federation/storybook-addon

pnpm add https://pkg.pr.new/@module-federation/storybook-addon@b4ff38f

@module-federation/third-party-dts-extractor

pnpm add https://pkg.pr.new/@module-federation/third-party-dts-extractor@b4ff38f

@module-federation/treeshake-frontend

pnpm add https://pkg.pr.new/@module-federation/treeshake-frontend@b4ff38f

@module-federation/treeshake-server

pnpm add https://pkg.pr.new/@module-federation/treeshake-server@b4ff38f

@module-federation/typescript

pnpm add https://pkg.pr.new/@module-federation/typescript@b4ff38f

@module-federation/utilities

pnpm add https://pkg.pr.new/@module-federation/utilities@b4ff38f

@module-federation/webpack-bundler-runtime

pnpm add https://pkg.pr.new/@module-federation/webpack-bundler-runtime@b4ff38f

@module-federation/bridge-react

pnpm add https://pkg.pr.new/@module-federation/bridge-react@b4ff38f

@module-federation/bridge-react-webpack-plugin

pnpm add https://pkg.pr.new/@module-federation/bridge-react-webpack-plugin@b4ff38f

@module-federation/bridge-shared

pnpm add https://pkg.pr.new/@module-federation/bridge-shared@b4ff38f

@module-federation/bridge-vue3

pnpm add https://pkg.pr.new/@module-federation/bridge-vue3@b4ff38f

@module-federation/inject-external-runtime-core-plugin

pnpm add https://pkg.pr.new/@module-federation/inject-external-runtime-core-plugin@b4ff38f

commit: b4ff38f

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

🚀 Preview Environment Ready!

Name Status URL
website-new ✅ Active https://nestor-lopez-31353-website-new-core-module-federa-b966f1c... ↗

Details:

  • Latest Commit: b4ff38f
  • Updated at: 7/29/2026, 7:50:41 PM

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Report

7 package(s) changed, 35 unchanged.

Package dist + ESM entry

Package Total dist (raw) Delta ESM gzip Delta
@module-federation/dts-plugin 339.9 kB +6.6 kB (+2.0%) 4.7 kB -2 B (-0.0%)

Bundle targets

Package Web bundle (gzip) Delta Node bundle (gzip) Delta
@module-federation/cli 2.3 kB -9 B (-0.4%) 2.4 kB -34 B (-1.4%)
@module-federation/core 1.0 kB -1 B (-0.1%) 1.0 kB -35 B (-3.2%)
@module-federation/devtools 30.3 kB -1 B (-0.0%) 30.3 kB -25 B (-0.1%)
@module-federation/dts-plugin 15.8 kB +484 B (+3.1%) 15.8 kB +484 B (+3.1%)
@module-federation/enhanced 2.7 kB +1 B (+0.0%) 2.8 kB -46 B (-1.6%)
@module-federation/metro-plugin-rnc-cli 416 B -1 B (-0.2%) 435 B -28 B (-6.0%)
@module-federation/node 9.2 kB +3 B (+0.0%) 9.2 kB -31 B (-0.3%)

Consumer scenarios

Scenario Web output (gzip) Delta Node output (gzip) Delta Gap (node-web) Delta
Enhanced remoteEntry 21.5 kB -18 B (-0.1%) 23.1 kB -18 B (-0.1%) +1.7 kB 0 B

Total dist (raw): 35.80 MB (+6.6 kB (+0.0%))
Total ESM gzip: 104.8 kB (-2 B (-0.0%))
Total web bundle (gzip): 233.9 kB (+476 B (+0.2%))
Total node bundle (gzip): 236.6 kB (+285 B (+0.1%))
Tracked ./bundler entry gzip: 556 B (no change)
Tracked ./bundler web bundle (gzip): 4.8 kB (no change)
Tracked ./bundler node bundle (gzip): 4.8 kB (no change)

Bundle sizes are generated with rslib (Rspack). Package-root metrics preserve the historical report. Tracked subpath exports such as ./bundler are measured separately so ENV_TARGET-driven tree-shaking is visible. Bare imports are externalized to keep package-level sizes consistent, and assets are emitted as resources.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09c3807d17

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/dts-plugin/src/core/lib/typeScriptDiagnostics.ts Outdated
@2heal1

2heal1 commented Jul 31, 2026

Copy link
Copy Markdown
Member

If this PR is intended to fix type generation for files outside the project directory, it should also consider cross-workspace dependencies.

For example, an exposed file under apps/remote may import source code from a sibling workspace package such as packages/shared. The root directory should
be determined from the full dependency graph, not only from the exposed entry files; otherwise type generation can still fail when an exposed file imports
workspace source outside the inferred root.

Could we add a regression test for this case before merging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(dts): preserve source root in temporary type-generation projects

2 participants