Skip to content

Commit

Permalink
Remove all non-docblock-imports from mdx files
Browse files Browse the repository at this point in the history
  • Loading branch information
bodograumann committed Oct 31, 2023
1 parent a2707cb commit 7921c82
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 0 additions & 5 deletions code/lib/codemod/src/transforms/__tests__/mdx-to-csf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ test('convert story re-definition', () => {

expect(mdx).toMatchInlineSnapshot(`
import { Meta, Story } from '@storybook/blocks';
import { Primary } from './Foobar.stories';
import * as FoobarStories from './Foobar_.stories';
<Meta of={FoobarStories} />
Expand Down Expand Up @@ -242,7 +241,6 @@ test('extract esm into csf head code', () => {

expect(mdx).toMatchInlineSnapshot(`
import { Meta, Story } from '@storybook/blocks';
import { Button } from './Button';
import * as FoobarStories from './Foobar.stories';
# hello
Expand Down Expand Up @@ -406,7 +404,6 @@ test('duplicate story name', () => {

expect(mdx).toMatchInlineSnapshot(`
import { Meta, Story } from '@storybook/blocks';
import { Button } from './Button';
import * as FoobarStories from './Foobar.stories';
<Meta of={FoobarStories} />
Expand Down Expand Up @@ -451,7 +448,6 @@ test('story name equals component name', () => {

expect(mdx).toMatchInlineSnapshot(`
import { Meta, Story } from '@storybook/blocks';
import { Button } from './Button';
import * as FoobarStories from './Foobar.stories';
<Meta of={FoobarStories} />
Expand Down Expand Up @@ -494,7 +490,6 @@ test('kebab case file name', () => {

expect(mdx).toMatchInlineSnapshot(`
import { Meta, Story } from '@storybook/blocks';
import { Kebab } from './my-component/some-kebab-case';
import * as SomeKebabCaseStories from './some-kebab-case.stories';
<Meta of={SomeKebabCaseStories} />
Expand Down
5 changes: 5 additions & 0 deletions code/lib/codemod/src/transforms/mdx-to-csf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ function cleanUpMdx(root: Root): void {

file.path.traverse({
ExportDeclaration: (path) => path.remove(),
ImportDeclaration: (path) => {
if (path.node.source.value !== '@storybook/blocks') {
path.remove();
}
},
});
const code = recast.print(file.path.node).code.trim();
if (code === '') {
Expand Down

0 comments on commit 7921c82

Please sign in to comment.