Skip to content

feat(vite-plugin-zephyr): decouple module federation integration#409

Merged
Nsttt merged 6 commits intomainfrom
feat/vite-zephyr-decouple-mf
Mar 26, 2026
Merged

feat(vite-plugin-zephyr): decouple module federation integration#409
Nsttt merged 6 commits intomainfrom
feat/vite-zephyr-decouple-mf

Conversation

@Nsttt
Copy link
Copy Markdown
Member

@Nsttt Nsttt commented Mar 22, 2026

What's added in this PR?

This refactors vite-plugin-zephyr so withZephyr() is the single public API while still supporting external @module-federation/vite configuration. The plugin now detects an existing MF Vite plugin, injects the Zephyr runtime plugin early, and serves that runtime plugin through a Zephyr virtual module so remote rewrites still happen without Zephyr wrapping federation directly.

It also removes the temporary split public APIs, updates the Vite MF example to use plugins: [react(), federation(mfConfig), withZephyr()], and upgrades the MF Vite/runtime versions so the examples can use normal ESM imports.

Screenshots

N/A

What's the issues or discussion related to this PR ?

The Vite integration had grown a hard dependency on Zephyr wrapping the Module Federation plugin. That made the API inconsistent with the other Zephyr plugins and blocked using withZephyr() alongside a separately configured federation(mfConfig). The goal here is to keep the rewrites and deployment behavior while removing the extra public wrapper API.

What are the steps to test this PR?

  • pnpm install
  • pnpm nx test vite-plugin-zephyr
  • pnpm nx build vite-plugin-zephyr
  • pnpm --filter vite-host run build
  • pnpm --filter vite-remote run build

Documentation update for this PR (if applicable)?

Updated the package README in this repo. No separate zephyr-documentation PR.

(Optional) What's left to be done for this PR?

  • Optional upstream follow-up with Module Federation if we want a public extension hook instead of relying on plugin internals.

(Optional) What's the potential risk and how to mitigate it?

  • The MF detection path still relies on the module-federation-vite plugin exposing _options. If upstream changes that internal shape, the Zephyr injection path could regress.
  • Mitigation: keep the regression test coverage around runtime plugin injection and example builds.

(Required) Pre-PR/Merge checklist

  • I have added/updated/opened a PR to documentation to cover this new behavior
  • I have added an explanation of my changes
  • I have written new tests (if applicable)
  • I have tested this locally (standing from a first time user point of view, never touch this app before)
  • I have/will run tests, or ask for help to add test

@Nsttt Nsttt self-assigned this Mar 22, 2026
@Nsttt Nsttt marked this pull request as ready for review March 22, 2026 18:12
Copilot AI review requested due to automatic review settings March 22, 2026 18:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors vite-plugin-zephyr to make withZephyr() the primary public API while supporting a separately configured @module-federation/vite plugin by detecting it, ensuring the Zephyr runtime plugin is injected, and serving that runtime plugin via a Zephyr virtual module.

Changes:

  • Refactors withZephyr() to (optionally) delegate to @module-federation/vite while keeping Zephyr’s core Vite integration in a separate internal plugin.
  • Adds runtime-plugin injection utilities and tests; improves MF plugin extraction to handle nested plugin arrays.
  • Updates Module Federation dependency versions and adjusts the Vite MF example/README to use plugins: [react(), federation(mfConfig), withZephyr()].

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pnpm-workspace.yaml Bumps MF catalog versions (@module-federation/runtime, @module-federation/vite).
pnpm-lock.yaml Lockfile updates for the MF version bumps and related transitive deps.
libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.ts Main refactor: MF plugin detection, runtime plugin virtual module, and new withZephyr() composition.
libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.spec.ts Adds unit tests for withZephyr() behavior with/without mfConfig.
libs/vite-plugin-zephyr/src/lib/types/module-federation-options.ts Introduces exported MF options type alias derived from @module-federation/vite.
libs/vite-plugin-zephyr/src/lib/internal/mf-vite-etl/ensure_runtime_plugin.ts Adds helper to inject the Zephyr MF runtime plugin and resolve its runtime source path/IDs.
libs/vite-plugin-zephyr/src/lib/internal/mf-vite-etl/test/ensure_runtime_plugin.test.ts Tests for runtime plugin injection/deduplication.
libs/vite-plugin-zephyr/src/lib/internal/extract/extract_mf_plugin.ts Enhances MF plugin detection by flattening nested plugin arrays and loosening input typing.
libs/vite-plugin-zephyr/src/index.ts Adjusts exports to keep withZephyr() as the API and re-exports MF options type from the new file.
libs/vite-plugin-zephyr/package.json Moves MF Vite to optional peer + devDependency (decoupling runtime dependency).
libs/vite-plugin-zephyr/README.md Updates docs to show configuring MF plugin separately and installing MF only when needed.
examples/vite-react-mf/remote/vite.config.ts Updates example to explicitly add federation(mfConfig) and then withZephyr().
examples/vite-react-mf/remote/package.json Adds @module-federation/vite to devDependencies for the example.
examples/vite-react-mf/host/vite.config.ts Updates example to explicitly add federation(mfConfig) and then withZephyr().
examples/vite-react-mf/host/package.json Adds @module-federation/vite to devDependencies for the example.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.ts
Comment thread libs/vite-plugin-zephyr/src/lib/types/module-federation-options.ts Outdated
Comment thread libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.ts
Comment thread libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.ts
Comment thread libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.spec.ts
Comment thread libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.ts
Copy link
Copy Markdown
Member

@arthurfiorette arthurfiorette left a comment

Choose a reason for hiding this comment

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

late night review from my phone :)

Comment thread libs/vite-plugin-zephyr/src/lib/internal/extract/extract_mf_plugin.ts Outdated
Comment thread libs/vite-plugin-zephyr/src/lib/types/module-federation-options.ts Outdated
Comment thread libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.ts
Comment thread libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.ts
Comment thread libs/vite-plugin-zephyr/src/lib/vite-plugin-zephyr.ts
@Nsttt Nsttt requested a review from arthurfiorette March 23, 2026 10:06
@Nsttt Nsttt enabled auto-merge (squash) March 26, 2026 13:41
@Nsttt Nsttt merged commit 1954e06 into main Mar 26, 2026
11 checks passed
@Nsttt Nsttt deleted the feat/vite-zephyr-decouple-mf branch March 26, 2026 13:58
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.

5 participants