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 mdx-to-csf codemod blocks imports #21448

Merged
merged 1 commit into from Mar 7, 2023
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
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