Skip to content

Commit e9a0681

Browse files
fix(cli): improve path normalization of readConfig (#3708)
1 parent 0eb6d1b commit e9a0681

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.changeset/ai-noisy-wolf.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@module-federation/cli": patch
3+
---
4+
5+
Improve dynamic module import for `readConfig` function to use file URL format.
6+
7+
- Added `pathToFileURL` import from 'url' module.
8+
- Updated the dynamic import statement for `mfConfig` to use `pathToFileURL(preBundlePath).href`.
9+
- Ensures compatibility and correctness in environments where file paths require URL format.
10+
```

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"prepare": "husky install",
5252
"changeset": "changeset",
5353
"build:packages": "npx nx affected -t build --parallel=10 --exclude='*,!tag:type:pkg'",
54-
"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",
54+
"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",
5555
"commitgen:staged": "./commit-gen.js --path ./packages --staged",
5656
"commitgen:main": "./commit-gen.js --path ./packages",
5757
"changeset:status": "changeset status",

packages/cli/src/utils/readConfig.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path';
22
import { bundle } from '@modern-js/node-bundle-require';
33
import type { moduleFederationPlugin } from '@module-federation/sdk';
4+
import { pathToFileURL } from 'url';
45

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

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

0 commit comments

Comments
 (0)