Conversation
* feat: dts plugin for vite * fix: pass live reload flag to dts dev worker * fix: improve dts consume remotes
There was a problem hiding this comment.
Pull request overview
This PR adds DTS (TypeScript definitions) plugin integration to the Vite Module Federation plugin to prevent build crashes when DTS options are invalid. The change guards DTS build normalization and validation with try-catch blocks and includes a regression test.
Changes:
- Adds
@module-federation/dts-plugindependency for TypeScript definition generation and consumption - Implements error handling around DTS option normalization to prevent build crashes
- Updates pnpm version to 9.14.2 across all CI workflows for consistency
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/utils/normalizeModuleFederationOptions.ts | Adds comprehensive TypeScript interfaces for DTS plugin options (PluginDtsOptions, DtsRemoteOptions, DtsHostOptions, RemoteTypeUrl, RemoteTypeUrls) |
| src/plugins/pluginDts.ts | New plugin implementation with error guards around normalizeDtsOptions, normalizeConsumeTypesOptions, and normalizeGenerateTypesOptions calls to prevent crashes |
| src/plugins/tests/pluginDts.test.ts | Regression test verifying that invalid DTS options don't throw errors during build |
| src/index.ts | Integrates the new pluginDts into the main plugin array |
| package.json | Adds @module-federation/dts-plugin@^0.21.6 dependency and bumps version to 1.9.6 |
| pnpm-lock.yaml | Updates lockfile with new dts-plugin dependencies and their transitive dependencies |
| examples/vite-vite/vite-remote/vite.config.js | Adds DTS configuration example for remote with generateTypes enabled |
| examples/vite-vite/vite-host/vite.config.js | Adds DTS configuration example for host with consumeTypes enabled |
| examples/vite-vite/vite-remote/tsconfig.json | New TypeScript configuration for the remote example |
| examples/vite-vite/vite-host/tsconfig.json | New TypeScript configuration for the host example |
| .github/workflows/unit-test.yml | Updates pnpm version to 9.14.2 |
| .github/workflows/linter.yml | Updates pnpm version to 9.14.2 |
| .github/workflows/e2e-test.yml | Updates pnpm version to 9.14.2 |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } as ResolvedConfig; | ||
|
|
||
| buildPlugin?.configResolved?.(config); | ||
| await expect(buildPlugin?.generateBundle?.()).resolves.toBeUndefined(); |
There was a problem hiding this comment.
The generateBundle hook should be called with the proper Vite/Rollup plugin parameters. According to the Rollup plugin API, generateBundle receives two parameters: options and bundle. While the implementation doesn't use these parameters, the test should call the method with the expected signature to properly simulate how Vite would invoke this hook. Consider updating the test to call it as buildPlugin?.generateBundle?.({}, {}) to match the actual plugin API.
| await expect(buildPlugin?.generateBundle?.()).resolves.toBeUndefined(); | |
| await expect(buildPlugin?.generateBundle?.({}, {})).resolves.toBeUndefined(); |
Summary
Testing