Skip to content

Commit

Permalink
fix: fix windows path error (#3180)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyqykk authored Nov 6, 2024
1 parent c2a63a6 commit 932983e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-eggs-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/storybook-addon': patch
---

fix: fix windows path error
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand All @@ -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];
}
}
Expand Down

0 comments on commit 932983e

Please sign in to comment.