Skip to content

refactor: restructure module federation SDK types and plugins#4510

Merged
2heal1 merged 15 commits intomainfrom
refactor/type-schema
Mar 12, 2026
Merged

refactor: restructure module federation SDK types and plugins#4510
2heal1 merged 15 commits intomainfrom
refactor/type-schema

Conversation

@2heal1
Copy link
Copy Markdown
Member

@2heal1 2heal1 commented Mar 9, 2026

Summary: Calibrate Schemas, Sync Docs, Add Schema Change Hook

Background

Calibrated enhanced package schema descriptions to match implementations in packages/enhanced/src/lib, synchronized Chinese/English docs, and added a git hook to auto-generate validation/types when schemas change.

Changes

  • Schema description calibrations (packages/enhanced/src/schemas):
  • container/ModuleFederationPlugin.json
  • getPublicPath: effective only when exposes is set; supports stringified function or return expression.
  • experiments.externalRuntime: externalize '@module-federation/runtime-core'; read global '_FEDERATION_RUNTIME_CORE' at runtime.
  • experiments.provideExternalRuntime: pure consumer only (no exposes); auto-inject '@module-federation/inject-external-runtime-core-plugin'; error if used with exposes.
  • treeShakingSharedPlugins: list of plugin module paths used for independent shared fallbacks (require and instantiate).
  • treeShakingSharedExcludePlugins: filter by plugin names (excluded from independent shared compilation).
  • shareStrategy: clarified default 'version-first'.
  • sharing/SharePlugin.json
  • independentShareFileName: deprecated; use treeShaking.filename.
  • Git hook:
  • .husky/pre-commit: when packages/enhanced/src/schemas/*.json changes, run pnpm generate:schema and re-stage generated files; then run npm run lint-fix and git add.

Generation

  • Ran pnpm generate:schema (nx run enhanced:generate:schema) to update .check.ts and SDK types (packages/sdk/src/types/plugins/).

Docs Updates

  • Chinese (apps/website-new/docs/zh/configure):
  • getpublicpath.mdx: added effective condition, stringified function/return forms, fixed title.
  • experiments.mdx: clarified externalRuntime/provideExternalRuntime with notes.
  • treeShakingSharedPlugins.mdx: updated to plugin module path list; example without version suffix.
  • index.mdx: added shareStrategy, experiments, virtualRuntimeEntry; runtimePlugins tuple support; getPublicPath effective condition.
  • English (apps/website-new/docs/en/configure):
  • getpublicpath.mdx: added effective condition; stringified function/return forms; fixed default value.
  • experiments.mdx: clarified externalRuntime/provideExternalRuntime with notes.
  • treeShakingSharedPlugins.mdx: updated to plugin module path list; require participation clarified.

Commands Run

  • npx nx run enhanced:generate:schema
  • npx nx format:check (passed)
  • Attempted npx nx run enhanced:build (failed due to duplicate TreeShakingConfig; out of scope for this PR)

Skipped Checks and Reasons

  • Broader package builds/tests skipped; focus is schema/doc/hook updates. Build failure identified for future PR.

Acceptance Criteria

  • Pre-commit: schema changes trigger pnpm generate:schema and stage outputs.
  • Chinese/English docs aligned with implementation; format checks pass.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 9, 2026

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 185151f
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/69b27c63eb07e500089a4b93
😎 Deploy Preview https://deploy-preview-4510--module-federation-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.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 9, 2026

⚠️ No Changeset found

Latest commit: 185151f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 9, 2026

⚠️ No Changeset found

Latest commit: 7d41a71

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Copy Markdown

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

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: 7d41a71044

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

* Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request.
*/
export type Exposes = (ExposesItem | ExposesObject)[] | ExposesObject;
// <-- BEGIN SCHEMA-GENERATED TYPES -->
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore missing imports in ModuleFederationPlugin types

Replacing the file header with the schema marker removed the previous import type webpack from 'webpack' and import { Stats } from '../stats' lines, but the file still references webpack.Compiler, webpack.Compilation, and Stats in AdditionalDataOptions and related types. Any declaration/type-check pass over this file now fails with unresolved identifiers, which blocks SDK/enhanced builds.

Useful? React with 👍 / 👎.

/**
* Tree-shake configuration for shared module.
*/
export interface TreeShakingConfig {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove duplicate TreeShakingConfig declaration

This commit introduces a new TreeShakingConfig declaration in the generated section while the legacy export type TreeShakingConfig = ... still exists later in the same file, so TypeScript sees duplicate identifiers in one module. This makes declaration generation/type-checking fail consistently until one of the declarations is removed or renamed.

Useful? React with 👍 / 👎.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 10, 2026

Open in StackBlitz

@module-federation/devtools

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

@module-federation/cli

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

create-module-federation

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

@module-federation/data-prefetch

pnpm add https://pkg.pr.new/@module-federation/data-prefetch@fc70f69

@module-federation/dts-plugin

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

@module-federation/enhanced

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

@module-federation/error-codes

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

@module-federation/esbuild

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

@module-federation/managers

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

@module-federation/manifest

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

@module-federation/metro

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

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

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

@module-federation/metro-plugin-rnef

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

@module-federation/modern-js

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

@module-federation/modern-js-v3

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

@module-federation/native-federation-tests

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

@module-federation/native-federation-typescript

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

@module-federation/nextjs-mf

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

@module-federation/node

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

@module-federation/retry-plugin

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

@module-federation/rsbuild-plugin

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

@module-federation/rspack

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

@module-federation/rspress-plugin

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

@module-federation/runtime

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

@module-federation/runtime-core

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

@module-federation/runtime-tools

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

@module-federation/sdk

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

@module-federation/storybook-addon

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

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

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

@module-federation/treeshake-frontend

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

@module-federation/treeshake-server

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

@module-federation/typescript

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

@module-federation/utilities

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

@module-federation/webpack-bundler-runtime

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

@module-federation/bridge-react

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

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

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

@module-federation/bridge-shared

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

@module-federation/bridge-vue3

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

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

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

commit: fc70f69

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 10, 2026

Bundle Size Report

15 package(s) changed, 25 unchanged.

Package dist + ESM entry

Package Total dist (raw) Delta ESM gzip Delta
@module-federation/cli 26.7 kB no change 786 B no change
@module-federation/core 39.1 kB no change 173 B no change
@module-federation/data-prefetch 118.4 kB +44 B (+0.0%) 105 B no change
@module-federation/enhanced 819.7 kB -22269 B (-2.6%) 712 B no change
@module-federation/managers 69.9 kB -144 B (-0.2%) 334 B no change
@module-federation/manifest 138.4 kB no change 182 B no change
@module-federation/metro 243.8 kB -40 B (-0.0%) 147 B no change
@module-federation/metro-plugin-rnc-cli 0 B no change 314 B no change
@module-federation/node 188.4 kB no change 217 B no change
@module-federation/rsbuild-plugin 120.4 kB -56 B (-0.0%) 91 B no change
@module-federation/runtime-core 249.4 kB -8 B (-0.0%) 477 B no change
@module-federation/sdk 118.4 kB +10.0 kB (+9.2%) 798 B +38 B (+5.0%)
@module-federation/storybook-addon 76.5 kB no change 100 B no change
@module-federation/utilities 110.6 kB no change 328 B no change
@module-federation/webpack-bundler-runtime 90.8 kB -150 B (-0.2%) 405 B no change

Bundle targets

Package Web bundle (gzip) Delta Node bundle (gzip) Delta
@module-federation/cli 2.3 kB -33 B (-1.4%) 2.3 kB -33 B (-1.4%)
@module-federation/core 1.1 kB -31 B (-2.8%) 1.0 kB -30 B (-2.8%)
@module-federation/data-prefetch 1.6 kB no change 1.6 kB no change
@module-federation/enhanced 5.9 kB -58 B (-0.9%) 5.9 kB -58 B (-0.9%)
@module-federation/managers 2.4 kB -27 B (-1.1%) 2.4 kB -27 B (-1.1%)
@module-federation/manifest 6.2 kB -38 B (-0.6%) 6.2 kB -38 B (-0.6%)
@module-federation/metro 7.9 kB -9 B (-0.1%) 7.9 kB -8 B (-0.1%)
@module-federation/metro-plugin-rnc-cli 411 B -26 B (-5.9%) 411 B -26 B (-5.9%)
@module-federation/node 9.2 kB -28 B (-0.3%) 9.2 kB -28 B (-0.3%)
@module-federation/rsbuild-plugin 4.5 kB no change 4.5 kB no change
@module-federation/runtime-core 13.4 kB no change 13.2 kB no change
@module-federation/sdk 4.4 kB +22 B (+0.5%) 5.3 kB +27 B (+0.5%)
@module-federation/storybook-addon 1.9 kB -24 B (-1.2%) 1.7 kB -24 B (-1.3%)
@module-federation/utilities 2.6 kB -31 B (-1.2%) 2.6 kB -31 B (-1.2%)
@module-federation/webpack-bundler-runtime 3.8 kB no change 3.8 kB no change

Consumer scenarios

Scenario Web output (gzip) Delta Node output (gzip) Delta Gap (node-web) Delta
Enhanced remoteEntry 19.1 kB -14 B (-0.1%) 20.1 kB -22 B (-0.1%) +1.0 kB -8 B

Total dist (raw): 10.63 MB (-12378 B (-0.1%))
Total ESM gzip: 68.7 kB (+38 B (+0.1%))
Total web bundle (gzip): 158.6 kB (-283 B (-0.2%))
Total node bundle (gzip): 159.2 kB (-276 B (-0.2%))
Tracked ./bundler entry gzip: 556 B (no change)
Tracked ./bundler web bundle (gzip): 4.5 kB (no change)
Tracked ./bundler node bundle (gzip): 4.5 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.

@2heal1
Copy link
Copy Markdown
Member Author

2heal1 commented Mar 10, 2026

@ScriptedAlchemy ahh i fix all ci , can you help review it :D ?

@ScriptedAlchemy
Copy link
Copy Markdown
Member

ScriptedAlchemy commented Mar 10, 2026

I verified locally and moved the actionable findings into inline review comments so each issue stays attached to the exact diff hunk.

Tracked inline items:

*/
export type Shared = (SharedItem | SharedObject)[] | SharedObject;

export type IncludeExcludeOptions = unknown | unknown | unknown;
Copy link
Copy Markdown
Member

@ScriptedAlchemy ScriptedAlchemy Mar 10, 2026

Choose a reason for hiding this comment

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

IncludeExcludeOptions is currently generated as unknown | unknown | unknown, which erases the schema-defined shape and weakens type safety for shared.include / shared.exclude.

Expected behavior:

  • preserve the concrete object shape generated from schema ({ request?, version?, fallbackVersion? })
  • keep parity with the standalone generated type in packages/sdk/src/types/plugins/ConsumeSharedPlugin.ts

Requested fix:

  • correct packages/enhanced/src/scripts/generate-sdk-types.js so this union is emitted with concrete members instead of unknown
  • add/adjust generator coverage so this regression is caught in future runs

dev?: boolean | PluginDevOptions;
dts?: boolean | PluginDtsOptions;
dataPrefetch?: DataPrefetch;
virtualRuntimeEntry?: boolean;
Copy link
Copy Markdown
Member

@ScriptedAlchemy ScriptedAlchemy Mar 10, 2026

Choose a reason for hiding this comment

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

dataPrefetch appears to have been dropped from the exported SDK option surface even though runtime/plugin usage still exists.

Impact:

  • TypeScript consumers using dataPrefetch: true now fail type-checking
  • downstream code is forced into // @ts-ignore even when runtime behavior is still supported

Requested fix:

  • restore dataPrefetch in the public options typings generated for this surface
  • keep generated declarations aligned with the schema and runtime/plugin consumers

/**
* Options for shared modules.
*/
export interface SharePluginOptions {
Copy link
Copy Markdown
Member

@ScriptedAlchemy ScriptedAlchemy Mar 10, 2026

Choose a reason for hiding this comment

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

The generated declarations now keep SharePluginOptions but dropped the exported SharePlugin class declaration that existed on origin/main.

Impact:

  • downstream TypeScript code referencing sharePlugin.SharePlugin breaks at type level despite runtime class availability
  • packages/managers/src/SharedManager.ts already had to stop using typeof sharePlugin.SharePlugin, indicating declaration-surface regression

Requested fix:

  • restore the SharePlugin class declaration in the generated type surface (or provide an equivalent compatible exported class type)
  • keep declaration output backward-compatible with existing consumers

@2heal1 2heal1 merged commit 64d8962 into main Mar 12, 2026
24 checks passed
@2heal1 2heal1 deleted the refactor/type-schema branch March 12, 2026 09:23
@2heal1 2heal1 mentioned this pull request Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants