@storybook/builder-vite 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,9 +22,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.mdxPlugin = void 0;
27
30
  const node_path_1 = require("node:path");
31
+ const slash_1 = __importDefault(require("slash"));
28
32
  const isStorybookMdx = (id) => id.endsWith('stories.mdx') || id.endsWith('story.mdx');
29
33
  /**
30
34
  * Grab the mdx compiler from the @mdx-js/react that comes with @storybook/mdx1-csf,
@@ -32,9 +36,9 @@ const isStorybookMdx = (id) => id.endsWith('stories.mdx') || id.endsWith('story.
32
36
  * Equivilent to https://github.com/storybookjs/mdx1-csf/blob/d58cb032a8902b3f24ad487b6a7aae11ba8b33f6/loader.js#L12-L16
33
37
  */
34
38
  function injectRenderer(code) {
35
- const mdxReactPackage = (0, node_path_1.dirname)(require.resolve('@mdx-js/react/package.json', {
39
+ const mdxReactPackage = (0, slash_1.default)((0, node_path_1.dirname)(require.resolve('@mdx-js/react/package.json', {
36
40
  paths: [(0, node_path_1.dirname)(require.resolve('@storybook/mdx1-csf/package.json'))],
37
- }));
41
+ })));
38
42
  return `
39
43
  import { mdx } from '${mdxReactPackage}';
40
44
  ${code}
@@ -1 +1 @@
1
- {"version":3,"file":"mdx-plugin.js","sourceRoot":"","sources":["../../plugins/mdx-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAoC;AAIpC,MAAM,cAAc,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,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ook/core-common';\nimport { Plugin } from 'vite';\n\nconst isStorybookMdx = (id: string) => id.endsWith('stories.mdx') || id.endsWith('story.mdx');\n\n/**\n * Grab the mdx compiler from the @mdx-js/react that comes with @storybook/mdx1-csf,\n * and add it to the top of the code.\n * Equivilent to https://github.com/storybookjs/mdx1-csf/blob/d58cb032a8902b3f24ad487b6a7aae11ba8b33f6/loader.js#L12-L16\n */\nfunction injectRenderer(code: string) {\n const mdxReactPackage = dirname(\n require.resolve('@mdx-js/react/package.json', {\n paths: [dirname(require.resolve('@storybook/mdx1-csf/package.json'))],\n })\n );\n\n return `\n import { mdx } from '${mdxReactPackage}';\n ${code}\n `;\n}\n\n/**\n * Storybook uses two different loaders when dealing with MDX:\n *\n * - *stories.mdx and *story.mdx are compiled with the CSF compiler\n * - *.mdx are compiled with the MDX compiler directly\n *\n * @see https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#csf-stories-with-arbitrary-mdx\n */\nexport function mdxPlugin(options: Options): Plugin {\n const { features } = options;\n\n return {\n name: 'storybook-vite-mdx-plugin',\n enforce: 'pre',\n async transform(src, id) {\n if (id.match(/\\.mdx?$/)) {\n // @ts-ignore\n const { compile } = features?.previewMdx2\n ? await import('@storybook/mdx2-csf')\n : await import('@storybook/mdx1-csf');\n\n // TODO: we don't currently support setting mdx options. Storybook 7.0 does\n const mdxCode = String(await compile(src, { skipCsf: !isStorybookMdx(id) }));\n\n const code = features?.previewMdx2 ? mdxCode : injectRenderer(mdxCode);\n\n return {\n code,\n map: null,\n };\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"mdx-plugin.js","sourceRoot":"","sources":["../../plugins/mdx-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAoC;AAGpC,kDAA0B;AAE1B,MAAM,cAAc,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC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":["import { dirname } from 'node:path';\nimport type { Options } from '@storybook/core-common';\nimport { Plugin } from 'vite';\nimport slash from 'slash';\n\nconst isStorybookMdx = (id: string) => id.endsWith('stories.mdx') || id.endsWith('story.mdx');\n\n/**\n * Grab the mdx compiler from the @mdx-js/react that comes with @storybook/mdx1-csf,\n * and add it to the top of the code.\n * Equivilent to https://github.com/storybookjs/mdx1-csf/blob/d58cb032a8902b3f24ad487b6a7aae11ba8b33f6/loader.js#L12-L16\n */\nfunction injectRenderer(code: string) {\n const mdxReactPackage = slash(\n dirname(\n require.resolve('@mdx-js/react/package.json', {\n paths: [dirname(require.resolve('@storybook/mdx1-csf/package.json'))],\n })\n )\n );\n\n return `\n import { mdx } from '${mdxReactPackage}';\n ${code}\n `;\n}\n\n/**\n * Storybook uses two different loaders when dealing with MDX:\n *\n * - *stories.mdx and *story.mdx are compiled with the CSF compiler\n * - *.mdx are compiled with the MDX compiler directly\n *\n * @see https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#csf-stories-with-arbitrary-mdx\n */\nexport function mdxPlugin(options: Options): Plugin {\n const { features } = options;\n\n return {\n name: 'storybook-vite-mdx-plugin',\n enforce: 'pre',\n async transform(src, id) {\n if (id.match(/\\.mdx?$/)) {\n // @ts-ignore\n const { compile } = features?.previewMdx2\n ? await import('@storybook/mdx2-csf')\n : await import('@storybook/mdx1-csf');\n\n // TODO: we don't currently support setting mdx options. Storybook 7.0 does\n const mdxCode = String(await compile(src, { skipCsf: !isStorybookMdx(id) }));\n\n const code = features?.previewMdx2 ? mdxCode : injectRenderer(mdxCode);\n\n return {\n code,\n map: null,\n };\n }\n },\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-vite",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "A plugin to run and build Storybooks with Vite",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +1,7 @@
1
1
  import { dirname } from 'node:path';
2
2
  import type { Options } from '@storybook/core-common';
3
3
  import { Plugin } from 'vite';
4
+ import slash from 'slash';
4
5
 
5
6
  const isStorybookMdx = (id: string) => id.endsWith('stories.mdx') || id.endsWith('story.mdx');
6
7
 
@@ -10,10 +11,12 @@ const isStorybookMdx = (id: string) => id.endsWith('stories.mdx') || id.endsWith
10
11
  * Equivilent to https://github.com/storybookjs/mdx1-csf/blob/d58cb032a8902b3f24ad487b6a7aae11ba8b33f6/loader.js#L12-L16
11
12
  */
12
13
  function injectRenderer(code: string) {
13
- const mdxReactPackage = dirname(
14
- require.resolve('@mdx-js/react/package.json', {
15
- paths: [dirname(require.resolve('@storybook/mdx1-csf/package.json'))],
16
- })
14
+ const mdxReactPackage = slash(
15
+ dirname(
16
+ require.resolve('@mdx-js/react/package.json', {
17
+ paths: [dirname(require.resolve('@storybook/mdx1-csf/package.json'))],
18
+ })
19
+ )
17
20
  );
18
21
 
19
22
  return `