diff --git a/.changeset/khaki-eggs-grab.md b/.changeset/khaki-eggs-grab.md new file mode 100644 index 00000000000..2bec226cffc --- /dev/null +++ b/.changeset/khaki-eggs-grab.md @@ -0,0 +1,5 @@ +--- +'@module-federation/storybook-addon': patch +--- + +fix: fix windows path error diff --git a/packages/storybook-addon/src/utils/with-module-federation-enhanced-rsbuild.ts b/packages/storybook-addon/src/utils/with-module-federation-enhanced-rsbuild.ts index fb057600a3f..262103aa729 100644 --- a/packages/storybook-addon/src/utils/with-module-federation-enhanced-rsbuild.ts +++ b/packages/storybook-addon/src/utils/with-module-federation-enhanced-rsbuild.ts @@ -3,6 +3,8 @@ import path from 'node:path'; import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack'; import { TEMP_DIR } from '@module-federation/sdk'; +import { correctImportPath } from './correctImportPath'; + import type { RsbuildConfig, RsbuildPlugin } from '@rsbuild/core'; import type { moduleFederationPlugin } from '@module-federation/sdk'; @@ -11,14 +13,14 @@ const bootstrapPath = path.resolve( process.cwd(), `node_modules/${TEMP_DIR}/storybook-bootstrap.js`, ); -const generateBootstrap = (entryPath: string) => { - return `import('${entryPath}')`; +const generateBootstrap = (context: string, entryPath: string) => { + return `import('${correctImportPath(context, entryPath)}');`; }; -const writeBootstrap = (entryPath: string) => { +const writeBootstrap = (context: string, entryPath: string) => { if (fs.existsSync(bootstrapPath)) { fs.unlinkSync(bootstrapPath); } - fs.writeFileSync(bootstrapPath, generateBootstrap(entryPath)); + fs.writeFileSync(bootstrapPath, generateBootstrap(context, entryPath)); }; export const withModuleFederation = async ( rsbuildConfig: RsbuildConfig, @@ -28,9 +30,10 @@ export const withModuleFederation = async ( rsbuildConfig.source ??= {}; rsbuildConfig.source.entry ??= {}; const entry = rsbuildConfig.source.entry; + const context = rsbuildConfig.root || process.cwd(); for (const entryName in entry) { if (Array.isArray(entry[entryName])) { - writeBootstrap(entry[entryName][0]); + writeBootstrap(context, entry[entryName][0]); entry[entryName] = [bootstrapPath]; } }