Skip to content

Commit

Permalink
Merge pull request #2703 from modernweb-dev/fix/storybook-builder-pro…
Browse files Browse the repository at this point in the history
…viderImportSource-extension

fix(storybook-builder): fix providerImportSource extension when using @storybook/addon-essentials
  • Loading branch information
bashmish committed Apr 17, 2024
2 parents 872c92b + 7b11064 commit 691afb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-olives-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/storybook-builder': patch
---

fix providerImportSource extension when using @storybook/addon-essentials
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions packages/storybook-builder/src/rollup-plugin-mdx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { compile } from '@storybook/mdx2-csf';
import type { Options } from '@storybook/types';
import { readFile } from 'fs-extra';
import { exists, readFile } from 'fs-extra';
import { isAbsolute } from 'path';
import remarkExternalLinks from 'remark-external-links';
import remarkSlug from 'remark-slug';
import type { Plugin } from 'rollup';
Expand Down Expand Up @@ -43,7 +44,16 @@ export function rollupPluginMdx(storybookOptions: Options): Plugin {
jsxOptions,
});

const jsCode = compile(mdxCode, {
// workaround for https://github.com/storybookjs/storybook/blob/v7.6.17/code/addons/essentials/src/docs/preset.ts#L10
const { providerImportSource } = mdxLoaderOptions.mdxCompileOptions;
if (isAbsolute(providerImportSource)) {
const providerImportSourceWithExt = providerImportSource + '.mjs';
if (await exists(providerImportSourceWithExt)) {
mdxLoaderOptions.mdxCompileOptions.providerImportSource = providerImportSourceWithExt;
}
}

const jsCode = await compile(mdxCode, {
skipCsf: true,
...mdxLoaderOptions,
});
Expand Down

0 comments on commit 691afb0

Please sign in to comment.