Skip to content

Commit 932983e

Browse files
authored
fix: fix windows path error (#3180)
1 parent c2a63a6 commit 932983e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

.changeset/khaki-eggs-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/storybook-addon': patch
3+
---
4+
5+
fix: fix windows path error

packages/storybook-addon/src/utils/with-module-federation-enhanced-rsbuild.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import path from 'node:path';
33
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
44
import { TEMP_DIR } from '@module-federation/sdk';
55

6+
import { correctImportPath } from './correctImportPath';
7+
68
import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core';
79
import type { moduleFederationPlugin } from '@module-federation/sdk';
810

@@ -11,14 +13,14 @@ const bootstrapPath = path.resolve(
1113
process.cwd(),
1214
`node_modules/${TEMP_DIR}/storybook-bootstrap.js`,
1315
);
14-
const generateBootstrap = (entryPath: string) => {
15-
return `import('${entryPath}')`;
16+
const generateBootstrap = (context: string, entryPath: string) => {
17+
return `import('${correctImportPath(context, entryPath)}');`;
1618
};
17-
const writeBootstrap = (entryPath: string) => {
19+
const writeBootstrap = (context: string, entryPath: string) => {
1820
if (fs.existsSync(bootstrapPath)) {
1921
fs.unlinkSync(bootstrapPath);
2022
}
21-
fs.writeFileSync(bootstrapPath, generateBootstrap(entryPath));
23+
fs.writeFileSync(bootstrapPath, generateBootstrap(context, entryPath));
2224
};
2325
export const withModuleFederation = async (
2426
rsbuildConfig: RsbuildConfig,
@@ -28,9 +30,10 @@ export const withModuleFederation = async (
2830
rsbuildConfig.source ??= {};
2931
rsbuildConfig.source.entry ??= {};
3032
const entry = rsbuildConfig.source.entry;
33+
const context = rsbuildConfig.root || process.cwd();
3134
for (const entryName in entry) {
3235
if (Array.isArray(entry[entryName])) {
33-
writeBootstrap(entry[entryName][0]);
36+
writeBootstrap(context, entry[entryName][0]);
3437
entry[entryName] = [bootstrapPath];
3538
}
3639
}

0 commit comments

Comments
 (0)