feat(dts-plugin): support custom outputDir for DTS type emission#4487
feat(dts-plugin): support custom outputDir for DTS type emission#4487zhouxinyong wants to merge 4 commits intomodule-federation:mainfrom
Conversation
Expose the existing internal `outputDir` option in the SDK's `DtsRemoteOptions` interface and fix `GenerateTypesPlugin` to use `path.relative()` instead of `path.basename()` when computing asset emission paths. This allows users to configure a custom output directory so that `@mf-types.zip` and `@mf-types.d.ts` are emitted alongside entry files in subdirectories (e.g. `dist/react/production/`). Previously, even if `outputDir` was set internally, `emitAsset()` always stripped directory info via `path.basename()`, causing the zip to land at the compiler output root instead of the intended subdirectory.
🦋 Changeset detectedLatest commit: c5d10e5 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc5e1f0faa
ℹ️ 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".
Bundle Size Report4 package(s) changed, 37 unchanged.
Total dist: 6.70 MB (+1.9 kB (+0.0%)) |
@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/esbuild
@module-federation/managers
@module-federation/manifest
@module-federation/metro
@module-federation/metro-plugin-rnc-cli
@module-federation/metro-plugin-rnef
@module-federation/modern-js
@module-federation/modern-js-v3
@module-federation/native-federation-tests
@module-federation/native-federation-typescript
@module-federation/nextjs-mf
@module-federation/node
@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/storybook-addon
@module-federation/third-party-dts-extractor
@module-federation/treeshake-frontend
@module-federation/treeshake-server
@module-federation/typescript
@module-federation/utilities
@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: |
|
I can not reproduce it . Can you provide the minimal reproduce repo ? |
Description
When webpack entry files are output to a subdirectory (e.g.
dist/react/production/), the DTS plugin always emits@mf-types.zipand@mf-types.d.tsto the compiler output root (dist/react/). Consumers infer the types URL from the entry path, resulting in 404s.This PR makes two minimal changes:
outputDirin SDK types —DtsRemoteOptionsnow includesoutputDir?: string, allowing users to configure where types are emitted.GenerateTypesPluginnow usespath.relative()instead ofpath.basename()to compute asset names, so types land in the correct subdirectory relative to the compiler output.Usage
Backward Compatibility
outputDiris not set,path.relative()produces the same result as the previouspath.basename().Related Issue
N/A (workaround previously required a post-build copy script)
Types of changes
Checklist