Skip to content

Commit

Permalink
Merge pull request #21448 from storybookjs/kasper/mdx-csf-imports
Browse files Browse the repository at this point in the history
Fix mdx-to-csf codemod blocks imports
  • Loading branch information
kasperpeulen committed Mar 7, 2023
2 parents cc5dad2 + 97fa0ad commit 3a7e11d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions code/lib/codemod/src/transforms/__tests__/mdx-to-csf.test.ts
Expand Up @@ -138,6 +138,30 @@ test('convert correct story nodes', () => {
`);
});

test('convert addon-docs imports', () => {
const input = dedent`
import { Meta } from '@storybook/addon-docs';
import { Story } from '@storybook/addon-docs/blocks';
<Meta title="Foobar" />
<Story name="Primary">Story</Story>
`;

const mdx = jscodeshift({ source: input, path: 'Foobar.stories.mdx' });

expect(mdx).toMatchInlineSnapshot(`
import { Meta } from '@storybook/blocks';
import { Story } from '@storybook/blocks';
import * as FoobarStories from './Foobar.stories';
<Meta of={FoobarStories} />
<Story of={FoobarStories.Primary} />
`);
});

test('convert story nodes with spaces', () => {
const input = dedent`
import { Meta, Story } from '@storybook/addon-docs';
Expand Down
4 changes: 2 additions & 2 deletions code/lib/codemod/src/transforms/mdx-to-csf.ts
Expand Up @@ -75,8 +75,8 @@ export function transform(source: string, baseName: string): [mdx: string, csf:
// rewrite addon docs import
visit(root, ['mdxjsEsm'], (node: MdxjsEsm) => {
node.value = node.value
.replaceAll('@storybook/addon-docs', '@storybook/blocks')
.replaceAll('@storybook/addon-docs/blocks', '@storybook/blocks');
.replaceAll('@storybook/addon-docs/blocks', '@storybook/blocks')
.replaceAll('@storybook/addon-docs', '@storybook/blocks');
});

const file = getEsmAst(root);
Expand Down

0 comments on commit 3a7e11d

Please sign in to comment.