Skip to content

Commit

Permalink
fix(storybook-builder): fix paths on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bashmish committed May 27, 2024
1 parent a225cd9 commit 104d7a4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { Plugin } from 'esbuild';
import { readFile } from 'fs-extra';
import { dirname } from 'path';
import { dirname, relative } from 'path';

export function esbuildPluginCommonjsNamedExports(modules: string[]): Plugin {
return {
name: 'commonjs-named-exports',
async setup(build) {
const slash = (await import('slash')).default;

const { init, parse } = await import('cjs-module-lexer');
await init();

Expand Down Expand Up @@ -56,7 +58,9 @@ export function esbuildPluginCommonjsNamedExports(modules: string[]): Plugin {

return {
resolveDir,
contents: `export { ${finalExports.join(',')} } from '${resolvedPath}';`,
contents: `export { ${finalExports.join(',')} } from '${slash(
relative(resolveDir, resolvedPath),
)}';`,
};
});

Expand Down
4 changes: 2 additions & 2 deletions packages/storybook-builder/src/rollup-plugin-mdx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { compile } from '@storybook/mdx2-csf';
import type { Options } from '@storybook/types';
import { exists, readFile } from 'fs-extra';
import { isAbsolute } from 'path';
import { isAbsolute, normalize } from 'path';
import remarkExternalLinks from 'remark-external-links';
import remarkSlug from 'remark-slug';
import type { Plugin } from 'rollup';
Expand Down Expand Up @@ -30,7 +30,7 @@ export function rollupPluginMdx(storybookOptions: Options): Plugin {
if (!id.endsWith('.mdx.js')) return;

const mdxPath = id.replace(/\.js$/, '');
const mdxCode = await readFile(mdxPath, 'utf8');
const mdxCode = await readFile(normalize(mdxPath), 'utf8');

const mdxLoaderOptions = await storybookOptions.presets.apply('mdxLoaderOptions', {
...mdxPluginOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { stringifyProcessEnvs } from '@storybook/core-common';
import { build } from 'esbuild';
import { remove } from 'fs-extra';
import { join } from 'path';
import { join, normalize } from 'path';
import type { Plugin } from 'rollup';
import { esbuildPluginCommonjsNamedExports } from './esbuild-plugin-commonjs-named-exports.js';
import { getNodeModuleDir } from './get-node-module-dir.js';

export const PREBUNDLED_MODULES_DIR = 'node_modules/.prebundled_modules';
export const PREBUNDLED_MODULES_DIR = normalize('node_modules/.prebundled_modules');

export function rollupPluginPrebundleModules(env: Record<string, string>): Plugin {
const modulePaths: Record<string, string> = {};
Expand Down

0 comments on commit 104d7a4

Please sign in to comment.