feat(metro-core): support dts-plugin#4449
feat(metro-core): support dts-plugin#4449Nsttt wants to merge 5 commits intomodule-federation:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 14092be The changes in this PR will be included in the next version bump. This PR includes changesets to release 43 packages
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 |
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@module-federation/devtools
@module-federation/cli
create-module-federation
@module-federation/data-prefetch
@module-federation/dts-plugin
@module-federation/enhanced
@module-federation/error-codes
@module-federation/managers
@module-federation/manifest
@module-federation/metro
@module-federation/metro-plugin-rnc-cli
@module-federation/metro-plugin-rnef
@module-federation/modern-js-v3
@module-federation/retry-plugin
@module-federation/rsbuild-plugin
@module-federation/rspack
@module-federation/rspress-plugin
@module-federation/runtime
@module-federation/runtime-core
@module-federation/runtime-tools
@module-federation/sdk
@module-federation/third-party-dts-extractor
@module-federation/treeshake-frontend
@module-federation/treeshake-server
@module-federation/webpack-bundler-runtime
@module-federation/bridge-react
@module-federation/bridge-react-webpack-plugin
@module-federation/bridge-shared
@module-federation/bridge-vue3
@module-federation/inject-external-runtime-core-plugin
commit: |
Bundle Size Report1 package(s) changed, 40 unchanged.
Total dist: 6.90 MB (+10.6 kB (+0.2%)) |
5234c59 to
fc52189
Compare
|
@jbroma rebased now that #4446 is merged and aligned this PR to the unified Metro config shape from Also validated locally after rebase:
DTS generation behavior in this branch:
|
There was a problem hiding this comment.
Pull request overview
Adds optional federated TypeScript declaration (d.ts) generation support for Metro remotes, integrating @module-federation/dts-plugin into the bundle-mf-remote flow and documenting the new configuration.
Changes:
- Extend Metro federation config typing/normalization to support
dts: boolean | PluginDtsOptions(defaulting tofalse). - Run d.ts generation during
bundle-mf-remoteand conditionally populatemf-manifest.jsonwithmetaData.types.{zip,api}when outputs exist. - Add dependency/changeset and update Metro plugin docs (EN/ZH).
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds workspace link for @module-federation/dts-plugin and lock updates. |
| packages/metro-core/src/types.ts | Adds dts to Metro federation config typing and normalized config. |
| packages/metro-core/src/plugin/validate-options.ts | Allows dts as a supported top-level option (no longer warned as unsupported). |
| packages/metro-core/src/plugin/normalize-options.ts | Defaults dts to false; fixes plugin path normalization to preserve bare package specifiers. |
| packages/metro-core/src/commands/bundle-remote/index.ts | Generates types via dts-plugin, verifies outputs, and writes manifest metaData.types only when present. |
| packages/metro-core/package.json | Adds @module-federation/dts-plugin dependency. |
| packages/metro-core/tests/plugin/normalize-options.spec.ts | Adds tests for dts default/enablement and no type-hints plugin injection. |
| apps/website-new/docs/zh/guide/build-plugins/plugins-metro.mdx | Documents dts: true usage and config typing (ZH). |
| apps/website-new/docs/en/guide/build-plugins/plugins-metro.mdx | Documents dts: true usage and config typing (EN). |
| .changeset/sweet-cats-smile.md | Publishes a patch changeset for @module-federation/metro. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
packages/metro-core/src/plugin/validate-options.ts:17
- Now that
dtsis a supported top-level option (removed fromunsupportedTopLevelOptions),validateOptionsshould explicitly validate its runtime type (boolean | object | undefined). Otherwise invalid values likedts: 1will pass validation but later crashbundle-mf-remotewhen@module-federation/dts-plugincallsnormalizeOptionsand throws a generic error. Add a small validator that throws aConfigErrorwith a clear message whendtsis not boolean/undefined/plain-object.
const unsupportedTopLevelOptions: (keyof ModuleFederationConfig)[] = [
'library',
'remoteType',
'runtime',
'shareScope',
'getPublicPath',
'implementation',
'manifest',
'dev',
'dataPrefetch',
'virtualRuntimeEntry',
'experiments',
'bridge',
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fc52189fb2
ℹ️ 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".
packages/metro-core/src/types.ts
Outdated
| /** | ||
| * Federated types (d.ts) support. When enabled, Metro bundle commands can | ||
| * generate `@mf-types.zip` and `@mf-types.d.ts` for consumption by hosts. | ||
| */ | ||
| dts?: boolean | moduleFederationPlugin.PluginDtsOptions; |
There was a problem hiding this comment.
no need to redeclare it here, it should be inherited from the SDK type
There was a problem hiding this comment.
Good catch, removed in 9c9e3c644.
ModuleFederationConfig now only inherits dts from moduleFederationPlugin.ModuleFederationPluginOptions (no local redeclaration).
There was a problem hiding this comment.
hmmm if this is inside bundle-remote then DTS works only when running bundle remote, is this the desired behavior?
There was a problem hiding this comment.
Yes, intentional for now.
DTS generation here targets remote container build artifacts (@mf-types.zip, @mf-types.d.ts, and mf-manifest.json type metadata), so it is bound to bundle-mf-remote. I made that explicit in 9c9e3c644 by renaming the helper to maybeGenerateFederatedRemoteTypes and adding an intent comment at the call site.
Adds federated d.ts generation support to Metro remotes.
Status update (rebased):
mainafter refactor(metro): align metro plugin configuration with MF SDK #4446 merged (commit374f5c2eb, Feb 16, 2026)runtimePlugins/docs-aligned shape from refactor(metro): align metro plugin configuration with MF SDK #4446What changed:
dtssupport to Metro config typing (boolean | PluginDtsOptions)bundle-mf-remoteruns dts generation and writes produced files into:dist/<platform>/@mf-types.zipdist/<platform>/@mf-types.d.ts(when produced)dist/<platform>/mf-manifest.jsongetsmetaData.types.{zip,api}only when files existdts: truedefaults toconsumeTypes: falsemetaData.typesempty if no types were produced@module-federation/metroValidation:
pnpm nx run-many -t test,build -p metro-core --skip-nx-cache