Skip to content

Commit 4ca0c7b

Browse files
authored
fix(enhanced): use upath to against more edge cases between different OS (#2070)
1 parent a3f58fa commit 4ca0c7b

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

.changeset/silent-lions-impress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/enhanced': patch
3+
---
4+
5+
fix(enhanced): use upath to against more edge cases between different OS

packages/enhanced/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"dependencies": {
3434
"@module-federation/sdk": "workspace:*",
35-
"@module-federation/runtime-tools": "workspace:*"
35+
"@module-federation/runtime-tools": "workspace:*",
36+
"upath": "2.0.1"
3637
}
3738
}

packages/enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
normalizeRuntimeInitOptionsWithOutShared,
77
modifyEntry,
88
createHash,
9+
normalizeToPosixPath,
910
} from './utils';
1011
import fs from 'fs';
1112
import path from 'path';
@@ -46,21 +47,21 @@ class FederationRuntimePlugin {
4647

4748
static getTemplate(runtimePlugins: string[], bundlerRuntimePath?: string) {
4849
// internal runtime plugin
49-
const normalizedBundlerRuntimePath = (
50-
bundlerRuntimePath || BundlerRuntimePath
51-
).replaceAll('\\', '/');
50+
const normalizedBundlerRuntimePath = normalizeToPosixPath(
51+
bundlerRuntimePath || BundlerRuntimePath,
52+
);
5253

5354
let runtimePluginTemplates = '';
5455
const runtimePLuginNames: string[] = [];
5556

5657
if (Array.isArray(runtimePlugins)) {
5758
runtimePlugins.forEach((runtimePlugin, index) => {
5859
const runtimePluginName = `plugin_${index}`;
59-
const runtimePluginPath = (
60+
const runtimePluginPath = normalizeToPosixPath(
6061
path.isAbsolute(runtimePlugin)
6162
? runtimePlugin
62-
: path.join(process.cwd(), runtimePlugin)
63-
).replaceAll('\\', '/');
63+
: path.join(process.cwd(), runtimePlugin),
64+
);
6465

6566
runtimePluginTemplates += `import ${runtimePluginName} from '${runtimePluginPath}';\n`;
6667
runtimePLuginNames.push(runtimePluginName);

packages/enhanced/src/lib/container/runtime/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
2+
import upath from 'upath';
3+
import path from 'path';
24
import crypto from 'crypto';
35
import { parseOptions } from '../options';
46
import type { init } from '@module-federation/runtime-tools';
@@ -102,3 +104,6 @@ export function modifyEntry(options: ModifyEntryOptions): void {
102104
export function createHash(contents: string): string {
103105
return crypto.createHash('md5').update(contents).digest('hex');
104106
}
107+
108+
export const normalizeToPosixPath = (p: string) =>
109+
upath.normalizeSafe(path.normalize(p || ''));

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)