From 7b1106447ff5b1756e5c1a20f7b55b5d8339fa0d Mon Sep 17 00:00:00 2001 From: Mikhail Bashkirov Date: Wed, 17 Apr 2024 17:53:22 +0200 Subject: [PATCH] fix(storybook-builder): fix providerImportSource extension when using @storybook/addon-essentials --- .changeset/clean-olives-fly.md | 5 +++++ package-lock.json | 2 +- .../storybook-builder/src/rollup-plugin-mdx.ts | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 .changeset/clean-olives-fly.md diff --git a/.changeset/clean-olives-fly.md b/.changeset/clean-olives-fly.md new file mode 100644 index 000000000..c743e573e --- /dev/null +++ b/.changeset/clean-olives-fly.md @@ -0,0 +1,5 @@ +--- +'@web/storybook-builder': patch +--- + +fix providerImportSource extension when using @storybook/addon-essentials diff --git a/package-lock.json b/package-lock.json index 097dfa6ec..745b41ad3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41315,7 +41315,7 @@ }, "packages/storybook-builder": { "name": "@web/storybook-builder", - "version": "0.1.13", + "version": "0.1.14", "license": "MIT", "dependencies": { "@rollup/plugin-node-resolve": "^15.1.0", diff --git a/packages/storybook-builder/src/rollup-plugin-mdx.ts b/packages/storybook-builder/src/rollup-plugin-mdx.ts index 15bc7c062..8f46a590f 100644 --- a/packages/storybook-builder/src/rollup-plugin-mdx.ts +++ b/packages/storybook-builder/src/rollup-plugin-mdx.ts @@ -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'; @@ -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, });