Skip to content

Commit 7b11064

Browse files
committed
fix(storybook-builder): fix providerImportSource extension when using @storybook/addon-essentials
1 parent 872c92b commit 7b11064

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

.changeset/clean-olives-fly.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/storybook-builder': patch
3+
---
4+
5+
fix providerImportSource extension when using @storybook/addon-essentials

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/storybook-builder/src/rollup-plugin-mdx.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { compile } from '@storybook/mdx2-csf';
22
import type { Options } from '@storybook/types';
3-
import { readFile } from 'fs-extra';
3+
import { exists, readFile } from 'fs-extra';
4+
import { isAbsolute } from 'path';
45
import remarkExternalLinks from 'remark-external-links';
56
import remarkSlug from 'remark-slug';
67
import type { Plugin } from 'rollup';
@@ -43,7 +44,16 @@ export function rollupPluginMdx(storybookOptions: Options): Plugin {
4344
jsxOptions,
4445
});
4546

46-
const jsCode = compile(mdxCode, {
47+
// workaround for https://github.com/storybookjs/storybook/blob/v7.6.17/code/addons/essentials/src/docs/preset.ts#L10
48+
const { providerImportSource } = mdxLoaderOptions.mdxCompileOptions;
49+
if (isAbsolute(providerImportSource)) {
50+
const providerImportSourceWithExt = providerImportSource + '.mjs';
51+
if (await exists(providerImportSourceWithExt)) {
52+
mdxLoaderOptions.mdxCompileOptions.providerImportSource = providerImportSourceWithExt;
53+
}
54+
}
55+
56+
const jsCode = await compile(mdxCode, {
4757
skipCsf: true,
4858
...mdxLoaderOptions,
4959
});

0 commit comments

Comments
 (0)