From fd97a095c0cd3864defdf8a3fff32695ddda28d0 Mon Sep 17 00:00:00 2001 From: nyqykk <1327719263@qq.com> Date: Tue, 5 Nov 2024 18:25:20 +0800 Subject: [PATCH 1/2] fix: fix windows path error --- .changeset/khaki-eggs-grab.md | 5 +++++ .../with-module-federation-enhanced-rsbuild.ts | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/khaki-eggs-grab.md 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..176c6211008 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]; } } From 887f6ec425f96aba14f7d788d24408629dbab9bd Mon Sep 17 00:00:00 2001 From: nyqykk <1327719263@qq.com> Date: Tue, 5 Nov 2024 18:32:01 +0800 Subject: [PATCH 2/2] fix: fix path error --- .../src/utils/with-module-federation-enhanced-rsbuild.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 176c6211008..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 @@ -14,7 +14,7 @@ const bootstrapPath = path.resolve( `node_modules/${TEMP_DIR}/storybook-bootstrap.js`, ); const generateBootstrap = (context: string, entryPath: string) => { - return `import '${correctImportPath(context, entryPath)}';`; + return `import('${correctImportPath(context, entryPath)}');`; }; const writeBootstrap = (context: string, entryPath: string) => { if (fs.existsSync(bootstrapPath)) {