Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storybook-builder): fix providerImportSource extension when using @storybook/addon-essentials #2703

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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