Skip to content

fix(cli): improve path normalization of readConfig #3708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/ai-noisy-wolf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@module-federation/cli": patch
---

Improve dynamic module import for `readConfig` function to use file URL format.

- Added `pathToFileURL` import from 'url' module.
- Updated the dynamic import statement for `mfConfig` to use `pathToFileURL(preBundlePath).href`.
- Ensures compatibility and correctness in environments where file paths require URL format.
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@
"prepare": "husky install",
"changeset": "changeset",
"build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:type:pkg'",
"changegen": "./changeset-gen.js --path ./packages/enhanced --staged && ./changeset-gen.js --path ./packages/node --staged && ./changeset-gen.js --path ./packages/runtime --staged && ./changeset-gen.js --path ./packages/data-prefetch --staged && ./changeset-gen.js --path ./packages/nextjs-mf --staged && ./changeset-gen.js --path ./packages/dts-plugin --staged",
"changegen": "./changeset-gen.js --path ./packages/enhanced --staged &&./changeset-gen.js --path ./packages/cli --staged && ./changeset-gen.js --path ./packages/node --staged && ./changeset-gen.js --path ./packages/runtime --staged && ./changeset-gen.js --path ./packages/data-prefetch --staged && ./changeset-gen.js --path ./packages/nextjs-mf --staged && ./changeset-gen.js --path ./packages/dts-plugin --staged",
"commitgen:staged": "./commit-gen.js --path ./packages --staged",
"commitgen:main": "./commit-gen.js --path ./packages",
"changeset:status": "changeset status",
3 changes: 2 additions & 1 deletion packages/cli/src/utils/readConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import { bundle } from '@modern-js/node-bundle-require';
import type { moduleFederationPlugin } from '@module-federation/sdk';
import { pathToFileURL } from 'url';

const DEFAULT_CONFIG_PATH = 'module-federation.config.ts';

@@ -15,7 +16,7 @@ export const getConfigPath = (userConfigPath?: string) => {
export async function readConfig(userConfigPath?: string) {
const configPath = getConfigPath(userConfigPath);
const preBundlePath = await bundle(configPath);
const mfConfig = (await import(preBundlePath)).default
const mfConfig = (await import(pathToFileURL(preBundlePath).href)).default
.default as unknown as moduleFederationPlugin.ModuleFederationPluginOptions;
return mfConfig;
}