@storybook/builder-vite 0.2.2 → 0.2.4

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.
package/.eslintignore ADDED
@@ -0,0 +1,4 @@
1
+ .github
2
+ .yarn
3
+ storybook-static
4
+ dist
package/.eslintrc.js ADDED
@@ -0,0 +1,32 @@
1
+ module.exports = {
2
+ root: true,
3
+ env: {
4
+ node: true,
5
+ },
6
+ parser: '@typescript-eslint/parser',
7
+ parserOptions: {
8
+ ecmaVersion: 2021,
9
+ },
10
+ plugins: ['@typescript-eslint', 'only-warn'],
11
+ extends: [
12
+ 'eslint:recommended',
13
+ 'plugin:@typescript-eslint/eslint-recommended',
14
+ 'plugin:storybook/recommended',
15
+ 'prettier',
16
+ ],
17
+ rules: {
18
+ // Set line length to 120
19
+ 'max-len': ['error', { code: 120, ignoreComments: true }],
20
+ // Ignore arguments starting from an underscore `_`
21
+ '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
22
+ },
23
+ overrides: [
24
+ // Fix: disable `no-unused-vars` for TypeScript files
25
+ {
26
+ files: '**/*.ts',
27
+ rules: {
28
+ 'no-unused-vars': 'off',
29
+ },
30
+ },
31
+ ],
32
+ };
@@ -0,0 +1,5 @@
1
+ .yarn
2
+ **/*/storybook-static/*
3
+ *.yml
4
+ **/dist
5
+ public
package/.yarnrc.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+
3
+ cacheFolder: "../../.yarn/cache"
package/build.ts CHANGED
@@ -15,6 +15,11 @@ export async function build(options: ExtendedOptions) {
15
15
  emptyOutDir: false, // do not clean before running Vite build - Storybook has already added assets in there!
16
16
  sourcemap: true,
17
17
  },
18
+ esbuild: {
19
+ // Workaround for #206: https://github.com/storybookjs/builder-vite/issues/206#issuecomment-1122347230
20
+ // Makes sure that mocked actions can be recognized in the production build.
21
+ keepNames: true,
22
+ },
18
23
  };
19
24
 
20
25
  const finalConfig = await presets.apply('viteFinal', config, options);
package/dist/build.js CHANGED
@@ -14,6 +14,11 @@ async function build(options) {
14
14
  emptyOutDir: false,
15
15
  sourcemap: true,
16
16
  },
17
+ esbuild: {
18
+ // Workaround for #206: https://github.com/storybookjs/builder-vite/issues/206#issuecomment-1122347230
19
+ // Makes sure that mocked actions can be recognized in the production build.
20
+ keepNames: true,
21
+ },
17
22
  };
18
23
  const finalConfig = await presets.apply('viteFinal', config, options);
19
24
  const envsRaw = await presets.apply('env');
package/dist/build.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../build.ts"],"names":[],"mappings":";;;AAAA,+BAA0C;AAC1C,iCAA8C;AAC9C,+CAA6C;AAItC,KAAK,UAAU,KAAK,CAAC,OAAwB;IAClD,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAE5B,MAAM,UAAU,GAAG,MAAM,IAAA,0BAAY,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG;QACb,GAAG,UAAU;QACb,KAAK,EAAE;YACL,MAAM,EAAE,OAAO,CAAC,SAAS;YACzB,WAAW,EAAE,KAAK;YAClB,SAAS,EAAE,IAAI;SAChB;KACF,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAEtE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAmB,KAAK,CAAC,CAAC;IAC7D,0EAA0E;IAC1E,MAAM,IAAI,GAAG,IAAA,2BAAoB,EAAC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAClE,kBAAkB;IAClB,WAAW,CAAC,MAAM,GAAG;QACnB,GAAG,WAAW,CAAC,MAAM;QACrB,GAAG,IAAI;KACR,CAAC;IAEF,MAAM,IAAA,YAAS,EAAC,WAAW,CAAC,CAAC;AAC/B,CAAC;AAzBD,sBAyBC","sourcesContent":["import { build as viteBuild } from 'vite';\nimport { stringifyProcessEnvs } from './envs';\nimport { commonConfig } from './vite-config';\n\nimport type { EnvsRaw, ExtendedOptions } from './types';\n\nexport async function build(options: ExtendedOptions) {\n const { presets } = options;\n\n const baseConfig = await commonConfig(options, 'build');\n const config = {\n ...baseConfig,\n build: {\n outDir: options.outputDir,\n emptyOutDir: false, // do not clean before running Vite build - Storybook has already added assets in there!\n sourcemap: true,\n },\n };\n\n const finalConfig = await presets.apply('viteFinal', config, options);\n\n const envsRaw = await presets.apply<Promise<EnvsRaw>>('env');\n // Stringify env variables after getting `envPrefix` from the final config\n const envs = stringifyProcessEnvs(envsRaw, finalConfig.envPrefix);\n // Update `define`\n finalConfig.define = {\n ...finalConfig.define,\n ...envs,\n };\n\n await viteBuild(finalConfig);\n}\n"]}
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../build.ts"],"names":[],"mappings":";;;AAAA,+BAA0C;AAC1C,iCAA8C;AAC9C,+CAA6C;AAItC,KAAK,UAAU,KAAK,CAAC,OAAwB;IAClD,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAE5B,MAAM,UAAU,GAAG,MAAM,IAAA,0BAAY,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG;QACb,GAAG,UAAU;QACb,KAAK,EAAE;YACL,MAAM,EAAE,OAAO,CAAC,SAAS;YACzB,WAAW,EAAE,KAAK;YAClB,SAAS,EAAE,IAAI;SAChB;QACD,OAAO,EAAE;YACP,sGAAsG;YACtG,4EAA4E;YAC5E,SAAS,EAAE,IAAI;SAChB;KACF,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAEtE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAmB,KAAK,CAAC,CAAC;IAC7D,0EAA0E;IAC1E,MAAM,IAAI,GAAG,IAAA,2BAAoB,EAAC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAClE,kBAAkB;IAClB,WAAW,CAAC,MAAM,GAAG;QACnB,GAAG,WAAW,CAAC,MAAM;QACrB,GAAG,IAAI;KACR,CAAC;IAEF,MAAM,IAAA,YAAS,EAAC,WAAW,CAAC,CAAC;AAC/B,CAAC;AA9BD,sBA8BC","sourcesContent":["import { build as viteBuild } from 'vite';\nimport { stringifyProcessEnvs } from './envs';\nimport { commonConfig } from './vite-config';\n\nimport type { EnvsRaw, ExtendedOptions } from './types';\n\nexport async function build(options: ExtendedOptions) {\n const { presets } = options;\n\n const baseConfig = await commonConfig(options, 'build');\n const config = {\n ...baseConfig,\n build: {\n outDir: options.outputDir,\n emptyOutDir: false, // do not clean before running Vite build - Storybook has already added assets in there!\n sourcemap: true,\n },\n esbuild: {\n // Workaround for #206: https://github.com/storybookjs/builder-vite/issues/206#issuecomment-1122347230\n // Makes sure that mocked actions can be recognized in the production build.\n keepNames: true,\n },\n };\n\n const finalConfig = await presets.apply('viteFinal', config, options);\n\n const envsRaw = await presets.apply<Promise<EnvsRaw>>('env');\n // Stringify env variables after getting `envPrefix` from the final config\n const envs = stringifyProcessEnvs(envsRaw, finalConfig.envPrefix);\n // Update `define`\n finalConfig.define = {\n ...finalConfig.define,\n ...envs,\n };\n\n await viteBuild(finalConfig);\n}\n"]}
@@ -46,6 +46,7 @@ const INCLUDE_CANDIDATES = [
46
46
  '@storybook/react > acorn-jsx',
47
47
  '@storybook/react',
48
48
  '@storybook/svelte',
49
+ '@storybook/vue',
49
50
  '@storybook/vue3',
50
51
  'acorn-jsx',
51
52
  'acorn-walk',
@@ -1 +1 @@
1
- {"version":3,"file":"optimizeDeps.js","sourceRoot":"","sources":["../optimizeDeps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+BAAgE;AAChE,iDAA6C;AAI7C,MAAM,kBAAkB,GAAG;IACzB,4BAA4B;IAC5B,eA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AE,CACxF,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAExF,KAAK,UAAU,eAAe,CACnC,MAAwD,EACxD,OAAwB;IAExB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACxB,MAAM,eAAe,GAAG,MAAM,IAAA,0BAAW,EAAC,OAAO,CAAC,CAAC;IACnD,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAA,oBAAa,EAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAClG,MAAM,cAAc,GAAG,MAAM,IAAA,oBAAa,EAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;IAE3E,6FAA6F;IAC7F,uIAAuI;IACvI,MAAM,OAAO,GAAG,cAAc,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEhG,OAAO;QACL,2EAA2E;QAC3E,OAAO,EAAE,OAAO;QAChB,oGAAoG;QACpG,2CAA2C;QAC3C,OAAO;KACR,CAAC;AACJ,CAAC;AArBD,0CAqBC","sourcesContent":["import * as path from 'path';\nimport { normalizePath, resolveConfig, UserConfig } from 'vite';\nimport { listStories } from './list-stories';\n\nimport type { ExtendedOptions } from './types';\n\nconst INCLUDE_CANDIDATES = [\n '@base2/pretty-print-object',\n '@emotion/core',\n '@emotion/is-prop-valid',\n '@emotion/styled',\n '@mdx-js/react',\n '@storybook/addon-docs > acorn-jsx',\n '@storybook/addon-docs',\n '@storybook/addons',\n '@storybook/channel-postmessage',\n '@storybook/channel-websocket',\n '@storybook/client-api',\n '@storybook/client-logger',\n '@storybook/core/client',\n '@storybook/csf',\n '@storybook/preview-web',\n '@storybook/react > acorn-jsx',\n '@storybook/react',\n '@storybook/svelte',\n '@storybook/vue3',\n 'acorn-jsx',\n 'acorn-walk',\n 'acorn',\n 'airbnb-js-shims',\n 'ansi-to-html',\n 'axe-core',\n 'color-convert',\n 'deep-object-diff',\n 'doctrine',\n 'emotion-theming',\n 'escodegen',\n 'estraverse',\n 'fast-deep-equal',\n 'global',\n 'html-tags',\n 'isobject',\n 'jest-mock',\n 'loader-utils',\n 'lodash/cloneDeep',\n 'lodash/isFunction',\n 'lodash/isPlainObject',\n 'lodash/isString',\n 'lodash/mapKeys',\n 'lodash/mapValues',\n 'lodash/pick',\n 'lodash/pickBy',\n 'lodash/startCase',\n 'lodash/throttle',\n 'lodash/uniq',\n 'markdown-to-jsx',\n 'memoizerific',\n 'overlayscrollbars',\n 'polished',\n 'prettier/parser-babel',\n 'prettier/parser-flow',\n 'prettier/parser-typescript',\n 'prop-types',\n 'qs',\n 'react-dom',\n 'react-dom/client',\n 'react-fast-compare',\n 'react-is',\n 'react-textarea-autosize',\n 'react',\n 'react/jsx-runtime',\n 'refractor/core',\n 'refractor/lang/bash.js',\n 'refractor/lang/css.js',\n 'refractor/lang/graphql.js',\n 'refractor/lang/js-extras.js',\n 'refractor/lang/json.js',\n 'refractor/lang/jsx.js',\n 'refractor/lang/markdown.js',\n 'refractor/lang/markup.js',\n 'refractor/lang/tsx.js',\n 'refractor/lang/typescript.js',\n 'refractor/lang/yaml.js',\n 'regenerator-runtime/runtime.js',\n 'slash',\n 'stable',\n 'store2',\n 'synchronous-promise',\n 'telejson',\n 'ts-dedent',\n 'unfetch',\n 'util-deprecate',\n 'uuid-browser/v4',\n 'vue',\n 'warning',\n];\n\n/**\n * Helper function which allows us to `filter` with an async predicate. Uses Promise.all for performance.\n */\nconst asyncFilter = async (arr: string[], predicate: (val: string) => Promise<boolean>) =>\n Promise.all(arr.map(predicate)).then((results) => arr.filter((_v, index) => results[index]));\n\nexport async function getOptimizeDeps(\n config: UserConfig & { configFile: false; root: string },\n options: ExtendedOptions\n) {\n const { root } = config;\n const absoluteStories = await listStories(options);\n const stories = absoluteStories.map((storyPath) => normalizePath(path.relative(root, storyPath)));\n const resolvedConfig = await resolveConfig(config, 'serve', 'development');\n\n // This function converts ids which might include ` > ` to a real path, if it exists on disk.\n // See https://github.com/vitejs/vite/blob/67d164392e8e9081dc3f0338c4b4b8eea6c5f7da/packages/vite/src/node/optimizer/index.ts#L182-L199\n const resolve = resolvedConfig.createResolver({ asSrc: false });\n const include = await asyncFilter(INCLUDE_CANDIDATES, async (id) => Boolean(await resolve(id)));\n\n return {\n // We don't need to resolve the glob since vite supports globs for entries.\n entries: stories,\n // We need Vite to precompile these dependencies, because they contain non-ESM code that would break\n // if we served it directly to the browser.\n include,\n };\n}\n"]}
1
+ {"version":3,"file":"optimizeDeps.js","sourceRoot":"","sources":["../optimizeDeps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+BAAgE;AAChE,iDAA6C;AAI7C,MAAM,kBAAkB,GAAG;IACzB,4BAA4B;IAC5B,eAAe;IACf,wBAAwB;IACxB,iBAAiB;IACjB,eAAe;IACf,mCAAmC;IACnC,uBAAuB;IACvB,mBAAmB;IACnB,gCAAgC;IAChC,8BAA8B;IAC9B,uBAAuB;IACvB,0BAA0B;IAC1B,wBAAwB;IACxB,gBAAgB;IAChB,wBAAwB;IACxB,8BAA8B;IAC9B,kBAAkB;IAClB,mBAAmB;IACnB,gBAAgB;IAChB,iBAAiB;IACjB,WAAW;IACX,YAAY;IACZ,OAAO;IACP,iBAAiB;IACjB,cAAc;IACd,UAAU;IACV,eAAe;IACf,kBAA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AM,eAAe,GAAG,MAAM,IAAA,0BAAW,EAAC,OAAO,CAAC,CAAC;IACnD,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAA,oBAAa,EAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAClG,MAAM,cAAc,GAAG,MAAM,IAAA,oBAAa,EAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;IAE3E,6FAA6F;IAC7F,uIAAuI;IACvI,MAAM,OAAO,GAAG,cAAc,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,kBAAkB,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEhG,OAAO;QACL,2EAA2E;QAC3E,OAAO,EAAE,OAAO;QAChB,oGAAoG;QACpG,2CAA2C;QAC3C,OAAO;KACR,CAAC;AACJ,CAAC;AArBD,0CAqBC","sourcesContent":["import * as path from 'path';\nimport { normalizePath, resolveConfig, UserConfig } from 'vite';\nimport { listStories } from './list-stories';\n\nimport type { ExtendedOptions } from './types';\n\nconst INCLUDE_CANDIDATES = [\n '@base2/pretty-print-object',\n '@emotion/core',\n '@emotion/is-prop-valid',\n '@emotion/styled',\n '@mdx-js/react',\n '@storybook/addon-docs > acorn-jsx',\n '@storybook/addon-docs',\n '@storybook/addons',\n '@storybook/channel-postmessage',\n '@storybook/channel-websocket',\n '@storybook/client-api',\n '@storybook/client-logger',\n '@storybook/core/client',\n '@storybook/csf',\n '@storybook/preview-web',\n '@storybook/react > acorn-jsx',\n '@storybook/react',\n '@storybook/svelte',\n '@storybook/vue',\n '@storybook/vue3',\n 'acorn-jsx',\n 'acorn-walk',\n 'acorn',\n 'airbnb-js-shims',\n 'ansi-to-html',\n 'axe-core',\n 'color-convert',\n 'deep-object-diff',\n 'doctrine',\n 'emotion-theming',\n 'escodegen',\n 'estraverse',\n 'fast-deep-equal',\n 'global',\n 'html-tags',\n 'isobject',\n 'jest-mock',\n 'loader-utils',\n 'lodash/cloneDeep',\n 'lodash/isFunction',\n 'lodash/isPlainObject',\n 'lodash/isString',\n 'lodash/mapKeys',\n 'lodash/mapValues',\n 'lodash/pick',\n 'lodash/pickBy',\n 'lodash/startCase',\n 'lodash/throttle',\n 'lodash/uniq',\n 'markdown-to-jsx',\n 'memoizerific',\n 'overlayscrollbars',\n 'polished',\n 'prettier/parser-babel',\n 'prettier/parser-flow',\n 'prettier/parser-typescript',\n 'prop-types',\n 'qs',\n 'react-dom',\n 'react-dom/client',\n 'react-fast-compare',\n 'react-is',\n 'react-textarea-autosize',\n 'react',\n 'react/jsx-runtime',\n 'refractor/core',\n 'refractor/lang/bash.js',\n 'refractor/lang/css.js',\n 'refractor/lang/graphql.js',\n 'refractor/lang/js-extras.js',\n 'refractor/lang/json.js',\n 'refractor/lang/jsx.js',\n 'refractor/lang/markdown.js',\n 'refractor/lang/markup.js',\n 'refractor/lang/tsx.js',\n 'refractor/lang/typescript.js',\n 'refractor/lang/yaml.js',\n 'regenerator-runtime/runtime.js',\n 'slash',\n 'stable',\n 'store2',\n 'synchronous-promise',\n 'telejson',\n 'ts-dedent',\n 'unfetch',\n 'util-deprecate',\n 'uuid-browser/v4',\n 'vue',\n 'warning',\n];\n\n/**\n * Helper function which allows us to `filter` with an async predicate. Uses Promise.all for performance.\n */\nconst asyncFilter = async (arr: string[], predicate: (val: string) => Promise<boolean>) =>\n Promise.all(arr.map(predicate)).then((results) => arr.filter((_v, index) => results[index]));\n\nexport async function getOptimizeDeps(\n config: UserConfig & { configFile: false; root: string },\n options: ExtendedOptions\n) {\n const { root } = config;\n const absoluteStories = await listStories(options);\n const stories = absoluteStories.map((storyPath) => normalizePath(path.relative(root, storyPath)));\n const resolvedConfig = await resolveConfig(config, 'serve', 'development');\n\n // This function converts ids which might include ` > ` to a real path, if it exists on disk.\n // See https://github.com/vitejs/vite/blob/67d164392e8e9081dc3f0338c4b4b8eea6c5f7da/packages/vite/src/node/optimizer/index.ts#L182-L199\n const resolve = resolvedConfig.createResolver({ asSrc: false });\n const include = await asyncFilter(INCLUDE_CANDIDATES, async (id) => Boolean(await resolve(id)));\n\n return {\n // We don't need to resolve the glob since vite supports globs for entries.\n entries: stories,\n // We need Vite to precompile these dependencies, because they contain non-ESM code that would break\n // if we served it directly to the browser.\n include,\n };\n}\n"]}
@@ -72,7 +72,10 @@ function mdxPlugin(options) {
72
72
  : await Promise.resolve().then(() => __importStar(require('@storybook/mdx1-csf')));
73
73
  const mdxCode = String(await compile(src, { skipCsf: !isStorybookMdx(id) }));
74
74
  const modifiedCode = injectRenderer(mdxCode, Boolean(features === null || features === void 0 ? void 0 : features.previewMdx2));
75
- const result = await (reactRefresh === null || reactRefresh === void 0 ? void 0 : reactRefresh.transform.call(this, modifiedCode, `${id}.jsx`, options));
75
+ // Hooks in recent rollup versions can be functions or objects, and though react hasn't changed, the typescript defs have
76
+ const rTransform = reactRefresh === null || reactRefresh === void 0 ? void 0 : reactRefresh.transform;
77
+ const transform = rTransform && 'handler' in rTransform ? rTransform.handler : rTransform;
78
+ const result = await transform.call(this, modifiedCode, `${id}.jsx`, options);
76
79
  if (!result)
77
80
  return modifiedCode;
78
81
  if (typeof result === 'string')
@@ -1 +1 @@
1
- {"version":3,"file":"mdx-plugin.js","sourceRoot":"","sources":["../../plugins/mdx-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,cAAc,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAE9F,SAAS,cAAc,CAAC,IAAY,EAAE,IAAa;IACjD,IAAI,IAAI,EAAE;QACR,OAAO;;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,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,CAAC,CAAC,CAAC;gBAE7E,MAAM,MAAM,GAAG,MAAM,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,SAAS,CAAE,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA,CAAC;gBAE7F,IAAI,CAAC,MAAM;oBAAE,OAAO,YAAY,CAAC;gBAEjC,IAAI,OAAO,MAAM,KAAK,QAAQ;oBAAE,OAAO,MAAM,CAAC;gBAE9C,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;gBAExC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;aACjH;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AA7CD,8BA6CC","sourcesContent":["import type { Options } from '@storybook/core-common';\nimport { Plugin } from 'vite';\n\nconst isStorybookMdx = (id: string) => id.endsWith('stories.mdx') || id.endsWith('story.mdx');\n\nfunction injectRenderer(code: string, mdx2: boolean) {\n if (mdx2) {\n return `\n import React from 'react';\n ${code}\n `;\n }\n\n return `\n /* @jsx mdx */\n import React from 'react';\n import { mdx } from '@mdx-js/react';\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 let reactRefresh: Plugin | undefined;\n\n return {\n name: 'storybook-vite-mdx-plugin',\n enforce: 'pre',\n configResolved({ plugins }) {\n // @vitejs/plugin-react-refresh has been upgraded to @vitejs/plugin-react,\n // and the name of the plugin performing `transform` has been changed from 'react-refresh' to 'vite:react-babel',\n // to be compatible, we need to look for both plugin name.\n // We should also look for the other plugins names exported from @vitejs/plugin-react in case there are some internal refactors.\n const reactRefreshPlugins = plugins.filter(\n (p) =>\n p.name === 'react-refresh' ||\n p.name === 'vite:react-babel' ||\n p.name === 'vite:react-refresh' ||\n p.name === 'vite:react-jsx'\n );\n reactRefresh = reactRefreshPlugins.find((p) => p.transform);\n },\n async transform(src, id, options) {\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 const mdxCode = String(await compile(src, { skipCsf: !isStorybookMdx(id) }));\n\n const modifiedCode = injectRenderer(mdxCode, Boolean(features?.previewMdx2));\n\n const result = await reactRefresh?.transform!.call(this, modifiedCode, `${id}.jsx`, options);\n\n if (!result) return modifiedCode;\n\n if (typeof result === 'string') return result;\n\n const { code, map: resultMap } = result;\n\n return { code, map: !resultMap || typeof resultMap === 'string' ? resultMap : { ...resultMap, sources: [id] } };\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"mdx-plugin.js","sourceRoot":"","sources":["../../plugins/mdx-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,cAAc,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAE9F,SAAS,cAAc,CAAC,IAAY,EAAE,IAAa;IACjD,IAAI,IAAI,EAAE;QACR,OAAO;;aAEE,IAAI;YACL,CAAC;KACV;IAED,OAAO;;;;UAIC,IAAI;SACL,CAAC;AACV,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,SAAS,CAAC,OAAgB;IACxC,MAAM,EAAE,QAAQ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AAC;gBAC3C,MAAM,SAAS,GAAG,UAAU,IAAI,SAAS,IAAI,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC;gBAE1F,MAAM,MAAM,GAAG,MAAM,SAAU,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;gBAE/E,IAAI,CAAC,MAAM;oBAAE,OAAO,YAAY,CAAC;gBAEjC,IAAI,OAAO,MAAM,KAAK,QAAQ;oBAAE,OAAO,MAAM,CAAC;gBAE9C,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;gBAExC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;aACjH;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAjDD,8BAiDC","sourcesContent":["import type { Options } from '@storybook/core-common';\nimport { Plugin } from 'vite';\n\nconst isStorybookMdx = (id: string) => id.endsWith('stories.mdx') || id.endsWith('story.mdx');\n\nfunction injectRenderer(code: string, mdx2: boolean) {\n if (mdx2) {\n return `\n import React from 'react';\n ${code}\n `;\n }\n\n return `\n /* @jsx mdx */\n import React from 'react';\n import { mdx } from '@mdx-js/react';\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 let reactRefresh: Plugin | undefined;\n\n return {\n name: 'storybook-vite-mdx-plugin',\n enforce: 'pre',\n configResolved({ plugins }) {\n // @vitejs/plugin-react-refresh has been upgraded to @vitejs/plugin-react,\n // and the name of the plugin performing `transform` has been changed from 'react-refresh' to 'vite:react-babel',\n // to be compatible, we need to look for both plugin name.\n // We should also look for the other plugins names exported from @vitejs/plugin-react in case there are some internal refactors.\n const reactRefreshPlugins = plugins.filter(\n (p) =>\n p.name === 'react-refresh' ||\n p.name === 'vite:react-babel' ||\n p.name === 'vite:react-refresh' ||\n p.name === 'vite:react-jsx'\n );\n reactRefresh = reactRefreshPlugins.find((p) => p.transform);\n },\n async transform(src, id, options) {\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 const mdxCode = String(await compile(src, { skipCsf: !isStorybookMdx(id) }));\n\n const modifiedCode = injectRenderer(mdxCode, Boolean(features?.previewMdx2));\n\n // Hooks in recent rollup versions can be functions or objects, and though react hasn't changed, the typescript defs have\n const rTransform = reactRefresh?.transform;\n const transform = rTransform && 'handler' in rTransform ? rTransform.handler : rTransform;\n\n const result = await transform!.call(this, modifiedCode, `${id}.jsx`, options);\n\n if (!result) return modifiedCode;\n\n if (typeof result === 'string') return result;\n\n const { code, map: resultMap } = result;\n\n return { code, map: !resultMap || typeof resultMap === 'string' ? resultMap : { ...resultMap, sources: [id] } };\n }\n },\n };\n}\n"]}
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.reactDocgen = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
- const pluginutils_1 = require("@rollup/pluginutils");
9
8
  const react_docgen_1 = require("react-docgen");
10
9
  const magic_string_1 = __importDefault(require("magic-string"));
10
+ const vite_1 = require("vite");
11
11
  const actualNameHandler_1 = __importDefault(require("./docgen-handlers/actualNameHandler"));
12
12
  // TODO: None of these are able to be overridden, so `default` is aspirational here.
13
13
  const defaultHandlers = Object.values(react_docgen_1.handlers).map((handler) => handler);
@@ -16,7 +16,7 @@ const defaultImporter = react_docgen_1.importers.makeFsImporter();
16
16
  const handlers = [...defaultHandlers, actualNameHandler_1.default];
17
17
  function reactDocgen({ include = /\.(mjs|tsx?|jsx?)$/, exclude = [/node_modules\/.*/, '**/**.stories.tsx'], } = {}) {
18
18
  const cwd = process.cwd();
19
- const filter = (0, pluginutils_1.createFilter)(include, exclude);
19
+ const filter = (0, vite_1.createFilter)(include, exclude);
20
20
  return {
21
21
  name: 'react-docgen',
22
22
  enforce: 'pre',
@@ -1 +1 @@
1
- {"version":3,"file":"react-docgen.js","sourceRoot":"","sources":["../../plugins/react-docgen.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,qDAAmD;AACnD,+CAKsB;AAEtB,gEAAuC;AAEvC,4FAAoE;AAIpE,oFAAoF;AACpF,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAc,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;AAChF,MAAM,eAAe,GAAG,uBAAc,CAAC,mCAAmC,CAAC;AAC3E,MAAM,eAAe,GAAG,wBAAe,CAAC,cAAc,EAAE,CAAC;AACzD,MAAM,QAAQ,GAAG,CAAC,GAAG,eAAe,EAAE,2BAAiB,CAAC,CAAC;AAOzD,SAAgB,WAAW,CAAC,EAC1B,OAAO,GAAG,oBAAoB,EAC9B,OAAO,GAAG,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,MACxC,EAAE;IACb,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,MAAM,GAAG,IAAA,0BAAY,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE9C,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,KAAK;QACd,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;YACrC,MAAM,OAAO,GAAG,cAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACvC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;gBAAE,OAAO;YAE7B,IAAI;gBACF,yFAAyF;gBACzF,MAAM,aAAa,GAAG,IAAA,oBAAK,EAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,EAAE,CAC3F,CAAC;gBACb,MAAM,CAAC,GAAG,IAAI,sBAAW,CAAC,GAAG,CAAC,CAAC;gBAE/B,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;oBAC7B,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC;oBAC3C,IAAI,UAAU,EAAE;wBACd,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;wBAC3C,CAAC,CAAC,MAAM,CAAC,IAAI,UAAU,iBAAiB,OAAO,EAAE,CAAC,CAAC;qBACpD;gBACH,CAAC,CAAC,CAAC;gBAEH,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;oBAClB,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;iBAChD,CAAC;aACH;YAAC,OAAO,CAAC,EAAE;gBACV,oFAAoF;gBACpF,qCAAqC;gBACrC,oBAAoB;aACrB;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAvCD,kCAuCC","sourcesContent":["import path from 'path';\nimport { createFilter } from '@rollup/pluginutils';\nimport {\n parse,\n handlers as docgenHandlers,\n resolver as docgenResolver,\n importers as docgenImporters,\n} from 'react-docgen';\nimport type { DocumentationObject } from 'react-docgen/lib/Documentation';\nimport MagicString from 'magic-string';\nimport type { Plugin } from 'vite';\nimport actualNameHandler from './docgen-handlers/actualNameHandler';\n\ntype DocObj = DocumentationObject & { actualName: string };\n\n// TODO: None of these are able to be overridden, so `default` is aspirational here.\nconst defaultHandlers = Object.values(docgenHandlers).map((handler) => handler);\nconst defaultResolver = docgenResolver.findAllExportedComponentDefinitions;\nconst defaultImporter = docgenImporters.makeFsImporter();\nconst handlers = [...defaultHandlers, actualNameHandler];\n\ntype Options = {\n include?: string | RegExp | (string | RegExp)[];\n exclude?: string | RegExp | (string | RegExp)[];\n};\n\nexport function reactDocgen({\n include = /\\.(mjs|tsx?|jsx?)$/,\n exclude = [/node_modules\\/.*/, '**/**.stories.tsx'],\n}: Options = {}): Plugin {\n const cwd = process.cwd();\n const filter = createFilter(include, exclude);\n\n return {\n name: 'react-docgen',\n enforce: 'pre',\n async transform(src: string, id: string) {\n const relPath = path.relative(cwd, id);\n if (!filter(relPath)) return;\n\n try {\n // Since we're using `findAllExportedComponentDefinitions`, this will always be an array.\n const docgenResults = parse(src, defaultResolver, handlers, { importer: defaultImporter, filename: id }) as\n | DocObj[];\n const s = new MagicString(src);\n\n docgenResults.forEach((info) => {\n const { actualName, ...docgenInfo } = info;\n if (actualName) {\n const docNode = JSON.stringify(docgenInfo);\n s.append(`;${actualName}.__docgenInfo=${docNode}`);\n }\n });\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n } catch (e) {\n // Usually this is just an error from react-docgen that it couldn't find a component\n // Only uncomment for troubleshooting\n // console.error(e);\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"react-docgen.js","sourceRoot":"","sources":["../../plugins/react-docgen.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,+CAKsB;AAEtB,gEAAuC;AAEvC,+BAAoC;AACpC,4FAAoE;AAIpE,oFAAoF;AACpF,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAc,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;AAChF,MAAM,eAAe,GAAG,uBAAc,CAAC,mCAAmC,CAA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Q,EAAE;oBAClB,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;iBAChD,CAAC;aACH;YAAC,OAAO,CAAC,EAAE;gBACV,oFAAoF;gBACpF,qCAAqC;gBACrC,oBAAoB;aACrB;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAvCD,kCAuCC","sourcesContent":["import path from 'path';\nimport {\n parse,\n handlers as docgenHandlers,\n resolver as docgenResolver,\n importers as docgenImporters,\n} from 'react-docgen';\nimport type { DocumentationObject } from 'react-docgen/lib/Documentation';\nimport MagicString from 'magic-string';\nimport type { Plugin } from 'vite';\nimport { createFilter } from 'vite';\nimport actualNameHandler from './docgen-handlers/actualNameHandler';\n\ntype DocObj = DocumentationObject & { actualName: string };\n\n// TODO: None of these are able to be overridden, so `default` is aspirational here.\nconst defaultHandlers = Object.values(docgenHandlers).map((handler) => handler);\nconst defaultResolver = docgenResolver.findAllExportedComponentDefinitions;\nconst defaultImporter = docgenImporters.makeFsImporter();\nconst handlers = [...defaultHandlers, actualNameHandler];\n\ntype Options = {\n include?: string | RegExp | (string | RegExp)[];\n exclude?: string | RegExp | (string | RegExp)[];\n};\n\nexport function reactDocgen({\n include = /\\.(mjs|tsx?|jsx?)$/,\n exclude = [/node_modules\\/.*/, '**/**.stories.tsx'],\n}: Options = {}): Plugin {\n const cwd = process.cwd();\n const filter = createFilter(include, exclude);\n\n return {\n name: 'react-docgen',\n enforce: 'pre',\n async transform(src: string, id: string) {\n const relPath = path.relative(cwd, id);\n if (!filter(relPath)) return;\n\n try {\n // Since we're using `findAllExportedComponentDefinitions`, this will always be an array.\n const docgenResults = parse(src, defaultResolver, handlers, { importer: defaultImporter, filename: id }) as\n | DocObj[];\n const s = new MagicString(src);\n\n docgenResults.forEach((info) => {\n const { actualName, ...docgenInfo } = info;\n if (actualName) {\n const docNode = JSON.stringify(docgenInfo);\n s.append(`;${actualName}.__docgenInfo=${docNode}`);\n }\n });\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n } catch (e) {\n // Usually this is just an error from react-docgen that it couldn't find a component\n // Only uncomment for troubleshooting\n // console.error(e);\n }\n },\n };\n}\n"]}
@@ -1,2 +1,2 @@
1
1
  import type { Plugin } from 'vite';
2
- export declare function vueDocgen(): Plugin;
2
+ export declare function vueDocgen(vueVersion: 2 | 3): Plugin;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.vueDocgen = void 0;
7
7
  const vue_docgen_api_1 = require("vue-docgen-api");
8
8
  const magic_string_1 = __importDefault(require("magic-string"));
9
- function vueDocgen() {
9
+ function vueDocgen(vueVersion) {
10
10
  return {
11
11
  name: 'vue-docgen',
12
12
  async transform(src, id) {
@@ -14,7 +14,8 @@ function vueDocgen() {
14
14
  const metaData = await (0, vue_docgen_api_1.parse)(id);
15
15
  const metaSource = JSON.stringify(metaData);
16
16
  const s = new magic_string_1.default(src);
17
- s.append(`;_sfc_main.__docgenInfo = ${metaSource}`);
17
+ const componentLocation = vueVersion === 3 ? '_sfc_main' : '__component__.exports';
18
+ s.append(`;${componentLocation}.__docgenInfo = ${metaSource}`);
18
19
  return {
19
20
  code: s.toString(),
20
21
  map: s.generateMap({ hires: true, source: id }),
@@ -1 +1 @@
1
- {"version":3,"file":"vue-docgen.js","sourceRoot":"","sources":["../../plugins/vue-docgen.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAuC;AAEvC,gEAAuC;AAEvC,SAAgB,SAAS;IACvB,OAAO;QACL,IAAI,EAAE,YAAY;QAElB,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;YACrC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBACvB,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAK,EAAC,EAAE,CAAC,CAAC;gBACjC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAC5C,MAAM,CAAC,GAAG,IAAI,sBAAW,CAAC,GAAG,CAAC,CAAC;gBAC/B,CAAC,CAAC,MAAM,CAAC,6BAA6B,UAAU,EAAE,CAAC,CAAC;gBAEpD,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;oBAClB,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;iBAChD,CAAC;aACH;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAlBD,8BAkBC","sourcesContent":["import { parse } from 'vue-docgen-api';\nimport type { Plugin } from 'vite';\nimport MagicString from 'magic-string';\n\nexport function vueDocgen(): Plugin {\n return {\n name: 'vue-docgen',\n\n async transform(src: string, id: string) {\n if (/\\.(vue)$/.test(id)) {\n const metaData = await parse(id);\n const metaSource = JSON.stringify(metaData);\n const s = new MagicString(src);\n s.append(`;_sfc_main.__docgenInfo = ${metaSource}`);\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"vue-docgen.js","sourceRoot":"","sources":["../../plugins/vue-docgen.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAuC;AAEvC,gEAAuC;AAEvC,SAAgB,SAAS,CAAC,UAAiB;IACzC,OAAO;QACL,IAAI,EAAE,YAAY;QAElB,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,EAAU;YACrC,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;gBACvB,MAAM,QAAQ,GAAG,MAAM,IAAA,sBAAK,EAAC,EAAE,CAAC,CAAC;gBACjC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAC5C,MAAM,CAAC,GAAG,IAAI,sBAAW,CAAC,GAAG,CAAC,CAAC;gBAC/B,MAAM,iBAAiB,GAAG,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,uBAAuB,CAAC;gBACnF,CAAC,CAAC,MAAM,CAAC,IAAI,iBAAiB,mBAAmB,UAAU,EAAE,CAAC,CAAC;gBAE/D,OAAO;oBACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;oBAClB,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;iBAChD,CAAC;aACH;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAnBD,8BAmBC","sourcesContent":["import { parse } from 'vue-docgen-api';\nimport type { Plugin } from 'vite';\nimport MagicString from 'magic-string';\n\nexport function vueDocgen(vueVersion: 2 | 3): Plugin {\n return {\n name: 'vue-docgen',\n\n async transform(src: string, id: string) {\n if (/\\.(vue)$/.test(id)) {\n const metaData = await parse(id);\n const metaSource = JSON.stringify(metaData);\n const s = new MagicString(src);\n const componentLocation = vueVersion === 3 ? '_sfc_main' : '__component__.exports';\n s.append(`;${componentLocation}.__docgenInfo = ${metaSource}`);\n\n return {\n code: s.toString(),\n map: s.generateMap({ hires: true, source: id }),\n };\n }\n },\n };\n}\n"]}
@@ -2,7 +2,7 @@ import { Plugin } from 'vite';
2
2
  import type { UserConfig } from 'vite';
3
3
  import type { ExtendedOptions } from './types';
4
4
  export declare type PluginConfigType = 'build' | 'development';
5
- export declare function readPackageJson(): Record<string, any> | false;
5
+ export declare function readPackageJson(dir?: string): Record<string, any> | false;
6
6
  export declare function commonConfig(options: ExtendedOptions, _type: PluginConfigType): Promise<UserConfig & {
7
7
  configFile: false;
8
8
  root: string;
@@ -30,14 +30,15 @@ exports.pluginConfig = exports.commonConfig = exports.readPackageJson = void 0;
30
30
  const path = __importStar(require("path"));
31
31
  const fs_1 = __importDefault(require("fs"));
32
32
  const plugin_react_1 = __importDefault(require("@vitejs/plugin-react"));
33
+ const semver_1 = __importDefault(require("@storybook/semver"));
33
34
  const envs_1 = require("./envs");
34
35
  const code_generator_plugin_1 = require("./code-generator-plugin");
35
36
  const inject_export_order_plugin_1 = require("./inject-export-order-plugin");
36
37
  const mdx_plugin_1 = require("./plugins/mdx-plugin");
37
38
  const no_fouc_1 = require("./plugins/no-fouc");
38
39
  const source_loader_plugin_1 = require("./source-loader-plugin");
39
- function readPackageJson() {
40
- const packageJsonPath = path.resolve('package.json');
40
+ function readPackageJson(dir = process.cwd()) {
41
+ const packageJsonPath = path.resolve(dir, 'package.json');
41
42
  if (!fs_1.default.existsSync(packageJsonPath)) {
42
43
  return false;
43
44
  }
@@ -48,16 +49,17 @@ exports.readPackageJson = readPackageJson;
48
49
  // Vite config that is common to development and production mode
49
50
  async function commonConfig(options, _type) {
50
51
  const { framework } = options;
52
+ const vuePath = framework === 'vue3' ? 'vue/dist/vue.esm-bundler.js' : 'vue/dist/vue.esm.js';
51
53
  return {
52
54
  configFile: false,
53
55
  root: path.resolve(options.configDir, '..'),
54
56
  cacheDir: 'node_modules/.vite-storybook',
55
57
  envPrefix: envs_1.allowedEnvPrefix,
56
58
  define: {},
57
- resolve: framework === 'vue3'
59
+ resolve: /^vue3?$/.test(framework)
58
60
  ? {
59
61
  alias: {
60
- vue: 'vue/dist/vue.esm-bundler.js',
62
+ vue: vuePath,
61
63
  },
62
64
  }
63
65
  : {},
@@ -66,8 +68,10 @@ async function commonConfig(options, _type) {
66
68
  }
67
69
  exports.commonConfig = commonConfig;
68
70
  async function pluginConfig(options, _type) {
71
+ var _a, _b, _c;
69
72
  const { framework, presets } = options;
70
73
  const svelteOptions = await presets.apply('svelteOptions', {}, options);
74
+ const root = path.resolve(options.configDir, '..');
71
75
  const plugins = [
72
76
  (0, code_generator_plugin_1.codeGeneratorPlugin)(options),
73
77
  (0, source_loader_plugin_1.sourceLoaderPlugin)(options),
@@ -94,17 +98,59 @@ async function pluginConfig(options, _type) {
94
98
  },
95
99
  },
96
100
  ];
97
- if (framework === 'vue' || framework === 'vue3') {
101
+ if (framework === 'vue') {
102
+ const pkgJson = readPackageJson(root);
103
+ const vueVer = pkgJson && ((_b = (_a = pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.dependencies) === null || _a === void 0 ? void 0 : _a.vue) !== null && _b !== void 0 ? _b : (_c = pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.devDependencies) === null || _c === void 0 ? void 0 : _c.vue);
104
+ // Default to 2.7, but check if package.json has a version that is less than 2.7
105
+ const is26 = vueVer && semver_1.default.gtr('2.7.0', vueVer);
106
+ try {
107
+ const vuePlugin = is26 ? require('vite-plugin-vue2').createVuePlugin : require('@vitejs/plugin-vue2');
108
+ plugins.push(vuePlugin());
109
+ }
110
+ catch (err) {
111
+ if (err.code === 'MODULE_NOT_FOUND') {
112
+ throw new Error(`
113
+ @storybook/builder-vite requires ${is26 ? 'vite-plugin-vue2' : '@vitejs/plugin-vue2'} to be installed when using @storybook/vue.
114
+ Please install it and start storybook again.
115
+ `);
116
+ }
117
+ throw err;
118
+ }
119
+ try {
120
+ const { vueDocgen } = await Promise.resolve().then(() => __importStar(require('./plugins/vue-docgen')));
121
+ plugins.push(vueDocgen(2));
122
+ }
123
+ catch (err) {
124
+ if (err.code === 'MODULE_NOT_FOUND') {
125
+ throw new Error('@storybook/builder-vite requires vue-docgen-api to be installed ' +
126
+ 'when using @storybook/vue.' +
127
+ ' Please install it and start storybook again.');
128
+ }
129
+ throw err;
130
+ }
131
+ }
132
+ if (framework === 'vue3') {
98
133
  try {
99
134
  const vuePlugin = require('@vitejs/plugin-vue');
100
135
  plugins.push(vuePlugin());
136
+ }
137
+ catch (err) {
138
+ if (err.code === 'MODULE_NOT_FOUND') {
139
+ throw new Error(`
140
+ @storybook/builder-vite requires @vitejs/plugin-vue to be installed when using @storybook/vue3.
141
+ Please install it and start storybook again.
142
+ `);
143
+ }
144
+ throw err;
145
+ }
146
+ try {
101
147
  const { vueDocgen } = await Promise.resolve().then(() => __importStar(require('./plugins/vue-docgen')));
102
- plugins.push(vueDocgen());
148
+ plugins.push(vueDocgen(3));
103
149
  }
104
150
  catch (err) {
105
151
  if (err.code === 'MODULE_NOT_FOUND') {
106
- throw new Error('@storybook/builder-vite requires @vitejs/plugin-vue to be installed ' +
107
- 'when using @storybook/vue or @storybook/vue3.' +
152
+ throw new Error('@storybook/builder-vite requires vue-docgen-api to be installed ' +
153
+ 'when using @storybook/vue3.' +
108
154
  ' Please install it and start storybook again.');
109
155
  }
110
156
  throw err;
@@ -170,7 +216,15 @@ async function pluginConfig(options, _type) {
170
216
  }
171
217
  if (framework === 'react') {
172
218
  const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply('typescript', {});
173
- if (reactDocgenOption === 'react-docgen-typescript') {
219
+ let typescriptPresent;
220
+ try {
221
+ require.resolve('typescript');
222
+ typescriptPresent = true;
223
+ }
224
+ catch (e) {
225
+ typescriptPresent = false;
226
+ }
227
+ if (reactDocgenOption === 'react-docgen-typescript' && typescriptPresent) {
174
228
  plugins.push(require('@joshwooding/vite-plugin-react-docgen-typescript')({
175
229
  ...reactDocgenTypescriptOptions,
176
230
  // We *need* this set so that RDT returns default values in the same format as react-docgen
@@ -1 +1 @@
1
- {"version":3,"file":"vite-config.js","sourceRoot":"","sources":["../vite-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAAoB;AAGpB,wEAA6C;AAE7C,iCAAuD;AACvD,mEAA8D;AAC9D,6EAAuE;AACvE,qDAAiD;AACjD,+CAA2C;AAC3C,iEAA4D;AAO5D,SAAgB,eAAe;IAC7B,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACrD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;QACnC,OAAO,KAAK,CAAC;KACd;IAED,MAAM,WAAW,GAAG,YAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC7D,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CA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MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;KAChC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAjJD,oCAiJC","sourcesContent":["import * as path from 'path';\nimport fs from 'fs';\nimport { Plugin } from 'vite';\nimport { TypescriptConfig } from '@storybook/core-common';\nimport viteReact from '@vitejs/plugin-react';\n\nimport { allowedEnvPrefix as envPrefix } from './envs';\nimport { codeGeneratorPlugin } from './code-generator-plugin';\nimport { injectExportOrderPlugin } from './inject-export-order-plugin';\nimport { mdxPlugin } from './plugins/mdx-plugin';\nimport { noFouc } from './plugins/no-fouc';\nimport { sourceLoaderPlugin } from './source-loader-plugin';\n\nimport type { UserConfig } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nexport type PluginConfigType = 'build' | 'development';\n\nexport function readPackageJson(): Record<string, any> | false {\n const packageJsonPath = path.resolve('package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return false;\n }\n\n const jsonContent = fs.readFileSync(packageJsonPath, 'utf8');\n return JSON.parse(jsonContent);\n}\n\n// Vite config that is common to development and production mode\nexport async function commonConfig(\n options: ExtendedOptions,\n _type: PluginConfigType\n): Promise<UserConfig & { configFile: false; root: string }> {\n const { framework } = options;\n\n return {\n configFile: false,\n root: path.resolve(options.configDir, '..'),\n cacheDir: 'node_modules/.vite-storybook',\n envPrefix,\n define: {},\n resolve:\n framework === 'vue3'\n ? {\n alias: {\n vue: 'vue/dist/vue.esm-bundler.js',\n },\n }\n : {},\n plugins: await pluginConfig(options, _type),\n };\n}\n\nexport async function pluginConfig(options: ExtendedOptions, _type: PluginConfigType) {\n const { framework, presets } = options;\n const svelteOptions: Record<string, any> = await presets.apply('svelteOptions', {}, options);\n\n const plugins = [\n codeGeneratorPlugin(options),\n sourceLoaderPlugin(options),\n mdxPlugin(options),\n noFouc(),\n injectExportOrderPlugin,\n // We need the react plugin here to support MDX.\n viteReact({\n // Do not treat story files as HMR boundaries, storybook itself needs to handle them.\n exclude: [/\\.stories\\.([tj])sx?$/, /node_modules/].concat(framework === 'react' ? [] : [/\\.([tj])sx?$/]),\n }),\n {\n name: 'vite-plugin-storybook-allow',\n enforce: 'post',\n config(config) {\n // if there is no allow list then Vite allows anything in the root directory\n // if there is an allow list then Vite allows anything in the listed directories\n // add the .storybook directory only if there's an allow list so that we don't end up\n // disallowing the root directory unless it's already disallowed\n if (config?.server?.fs?.allow) {\n config.server.fs.allow.push('.storybook');\n }\n },\n },\n ] as Plugin[];\n if (framework === 'vue' || framework === 'vue3') {\n try {\n const vuePlugin = require('@vitejs/plugin-vue');\n plugins.push(vuePlugin());\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen());\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @vitejs/plugin-vue to be installed ' +\n 'when using @storybook/vue or @storybook/vue3.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n if (framework === 'svelte') {\n try {\n const sveltePlugin = require('@sveltejs/vite-plugin-svelte').svelte;\n\n // We need to create two separate svelte plugins, one for stories, and one for other svelte files\n // because stories.svelte files cannot be hot-module-reloaded.\n // Suggested in: https://github.com/sveltejs/vite-plugin-svelte/issues/321#issuecomment-1113205509\n\n // First, create an array containing user exclude patterns, to combine with ours.\n const userExclude = Array.isArray(svelteOptions?.exclude)\n ? svelteOptions?.exclude\n : svelteOptions?.exclude\n ? [svelteOptions?.exclude]\n : [];\n\n // These are the svelte stories we need to exclude from HMR\n const storyPatterns = ['**/*.story.svelte', '**/*.stories.svelte'];\n // Non-story svelte files\n // Starting in 1.0.0-next.42, svelte.config.js is included by default.\n // We disable that, but allow it to be overridden in svelteOptions\n plugins.push(sveltePlugin({ ...svelteOptions, exclude: [...userExclude, ...storyPatterns] }));\n // Svelte stories without HMR\n const storySveltePlugin = sveltePlugin({\n ...svelteOptions,\n exclude: userExclude,\n include: storyPatterns,\n hot: false,\n });\n plugins.push({\n // Starting in 1.0.0-next.43, the plugin function returns an array of plugins. We only want the first one here.\n ...(Array.isArray(storySveltePlugin) ? storySveltePlugin[0] : storySveltePlugin),\n name: 'vite-plugin-svelte-stories',\n });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @sveltejs/vite-plugin-svelte to be installed' +\n ' when using @storybook/svelte.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n\n const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');\n const config = { ...loadSvelteConfig(), ...svelteOptions };\n\n try {\n const csfPlugin = require('./svelte/csf-plugin').default;\n plugins.push(csfPlugin(config));\n } catch (err) {\n // Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.\n // If it's any other kind of error, re-throw.\n if ((err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n }\n\n const { svelteDocgen } = await import('./plugins/svelte-docgen');\n plugins.push(svelteDocgen(config));\n }\n\n if (framework === 'preact') {\n plugins.push(require('@preact/preset-vite').default());\n }\n\n if (framework === 'react') {\n const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply(\n 'typescript',\n {} as TypescriptConfig\n );\n\n if (reactDocgenOption === 'react-docgen-typescript') {\n plugins.push(\n require('@joshwooding/vite-plugin-react-docgen-typescript')({\n ...reactDocgenTypescriptOptions,\n // We *need* this set so that RDT returns default values in the same format as react-docgen\n savePropValueAsString: true,\n })\n );\n }\n\n // Add react-docgen so long as the option is not false\n if (typeof reactDocgenOption === 'string') {\n const { reactDocgen } = await import('./plugins/react-docgen');\n // Needs to run before the react plugin, so add to the front\n plugins.unshift(\n // If react-docgen is specified, use it for everything, otherwise only use it for non-typescript files\n reactDocgen({ include: reactDocgenOption === 'react-docgen' ? /\\.(mjs|tsx?|jsx?)$/ : /\\.(mjs|jsx?)$/ })\n );\n }\n }\n\n if (framework === 'glimmerx') {\n const plugin = require('vite-plugin-glimmerx/index.cjs');\n plugins.push(plugin.default());\n }\n\n return plugins;\n}\n"]}
1
+ {"version":3,"file":"vite-config.js","sourceRoot":"","sources":["../vite-config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAAoB;AAGpB,wEAA6C;AAC7C,+DAAuC;AAEvC,iCAAuD;AACvD,mEAA8D;AAC9D,6EAAuE;AACvE,qDAAiD;AACjD,+CAA2C;AAC3C,iEAA4D;AAO5D,SAAgB,eAAe,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IACzD,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;QACnC,OAAO,KAAK,CAAC;KACd;IAED,MAAM,WAAW,GAAG,YAAE,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC7D,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACjC,CAAC;AARD,0CAQC;AAED,gEAAgE;AACzD,KAAK,UAAU,YAAY,CAChC,OAAwB,EACxB,KAAuB;IAEvB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,MAAM,OAAO,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,qBAAqB,CAAC;IAE7F,OAAO;QACL,UAAU,EAAE,KAAK;QACjB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC;QAC3C,QAAQ,EAAE,8BAA8B;QACxC,SAAS,EAAT,uBAAS;QACT,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;YAChC,CAAC,CAAC;gBACE,KAAK,EAAE;oBACL,GAAG,EAAE,OAAO;iBACb;aACF;YACH,CAA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AAO,CAAC;AACjB,CAAC;AA1MD,oCA0MC","sourcesContent":["import * as path from 'path';\nimport fs from 'fs';\nimport { Plugin } from 'vite';\nimport { TypescriptConfig } from '@storybook/core-common';\nimport viteReact from '@vitejs/plugin-react';\nimport semver from '@storybook/semver';\n\nimport { allowedEnvPrefix as envPrefix } from './envs';\nimport { codeGeneratorPlugin } from './code-generator-plugin';\nimport { injectExportOrderPlugin } from './inject-export-order-plugin';\nimport { mdxPlugin } from './plugins/mdx-plugin';\nimport { noFouc } from './plugins/no-fouc';\nimport { sourceLoaderPlugin } from './source-loader-plugin';\n\nimport type { UserConfig } from 'vite';\nimport type { ExtendedOptions } from './types';\n\nexport type PluginConfigType = 'build' | 'development';\n\nexport function readPackageJson(dir: string = process.cwd()): Record<string, any> | false {\n const packageJsonPath = path.resolve(dir, 'package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return false;\n }\n\n const jsonContent = fs.readFileSync(packageJsonPath, 'utf8');\n return JSON.parse(jsonContent);\n}\n\n// Vite config that is common to development and production mode\nexport async function commonConfig(\n options: ExtendedOptions,\n _type: PluginConfigType\n): Promise<UserConfig & { configFile: false; root: string }> {\n const { framework } = options;\n const vuePath = framework === 'vue3' ? 'vue/dist/vue.esm-bundler.js' : 'vue/dist/vue.esm.js';\n\n return {\n configFile: false,\n root: path.resolve(options.configDir, '..'),\n cacheDir: 'node_modules/.vite-storybook',\n envPrefix,\n define: {},\n resolve: /^vue3?$/.test(framework)\n ? {\n alias: {\n vue: vuePath,\n },\n }\n : {},\n plugins: await pluginConfig(options, _type),\n };\n}\n\nexport async function pluginConfig(options: ExtendedOptions, _type: PluginConfigType) {\n const { framework, presets } = options;\n const svelteOptions: Record<string, any> = await presets.apply('svelteOptions', {}, options);\n const root = path.resolve(options.configDir, '..');\n\n const plugins = [\n codeGeneratorPlugin(options),\n sourceLoaderPlugin(options),\n mdxPlugin(options),\n noFouc(),\n injectExportOrderPlugin,\n // We need the react plugin here to support MDX.\n viteReact({\n // Do not treat story files as HMR boundaries, storybook itself needs to handle them.\n exclude: [/\\.stories\\.([tj])sx?$/, /node_modules/].concat(framework === 'react' ? [] : [/\\.([tj])sx?$/]),\n }),\n {\n name: 'vite-plugin-storybook-allow',\n enforce: 'post',\n config(config) {\n // if there is no allow list then Vite allows anything in the root directory\n // if there is an allow list then Vite allows anything in the listed directories\n // add the .storybook directory only if there's an allow list so that we don't end up\n // disallowing the root directory unless it's already disallowed\n if (config?.server?.fs?.allow) {\n config.server.fs.allow.push('.storybook');\n }\n },\n },\n ] as Plugin[];\n\n if (framework === 'vue') {\n const pkgJson = readPackageJson(root);\n const vueVer: string | false | undefined = pkgJson && (pkgJson?.dependencies?.vue ?? pkgJson?.devDependencies?.vue);\n // Default to 2.7, but check if package.json has a version that is less than 2.7\n const is26 = vueVer && semver.gtr('2.7.0', vueVer);\n try {\n const vuePlugin = is26 ? require('vite-plugin-vue2').createVuePlugin : require('@vitejs/plugin-vue2');\n plugins.push(vuePlugin());\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(`\n @storybook/builder-vite requires ${\n is26 ? 'vite-plugin-vue2' : '@vitejs/plugin-vue2'\n } to be installed when using @storybook/vue.\n Please install it and start storybook again.\n `);\n }\n throw err;\n }\n try {\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen(2));\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires vue-docgen-api to be installed ' +\n 'when using @storybook/vue.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n\n if (framework === 'vue3') {\n try {\n const vuePlugin = require('@vitejs/plugin-vue');\n plugins.push(vuePlugin());\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(`\n @storybook/builder-vite requires @vitejs/plugin-vue to be installed when using @storybook/vue3.\n Please install it and start storybook again.\n `);\n }\n throw err;\n }\n\n try {\n const { vueDocgen } = await import('./plugins/vue-docgen');\n plugins.push(vueDocgen(3));\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires vue-docgen-api to be installed ' +\n 'when using @storybook/vue3.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n }\n\n if (framework === 'svelte') {\n try {\n const sveltePlugin = require('@sveltejs/vite-plugin-svelte').svelte;\n\n // We need to create two separate svelte plugins, one for stories, and one for other svelte files\n // because stories.svelte files cannot be hot-module-reloaded.\n // Suggested in: https://github.com/sveltejs/vite-plugin-svelte/issues/321#issuecomment-1113205509\n\n // First, create an array containing user exclude patterns, to combine with ours.\n const userExclude = Array.isArray(svelteOptions?.exclude)\n ? svelteOptions?.exclude\n : svelteOptions?.exclude\n ? [svelteOptions?.exclude]\n : [];\n\n // These are the svelte stories we need to exclude from HMR\n const storyPatterns = ['**/*.story.svelte', '**/*.stories.svelte'];\n // Non-story svelte files\n // Starting in 1.0.0-next.42, svelte.config.js is included by default.\n // We disable that, but allow it to be overridden in svelteOptions\n plugins.push(sveltePlugin({ ...svelteOptions, exclude: [...userExclude, ...storyPatterns] }));\n // Svelte stories without HMR\n const storySveltePlugin = sveltePlugin({\n ...svelteOptions,\n exclude: userExclude,\n include: storyPatterns,\n hot: false,\n });\n plugins.push({\n // Starting in 1.0.0-next.43, the plugin function returns an array of plugins. We only want the first one here.\n ...(Array.isArray(storySveltePlugin) ? storySveltePlugin[0] : storySveltePlugin),\n name: 'vite-plugin-svelte-stories',\n });\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {\n throw new Error(\n '@storybook/builder-vite requires @sveltejs/vite-plugin-svelte to be installed' +\n ' when using @storybook/svelte.' +\n ' Please install it and start storybook again.'\n );\n }\n throw err;\n }\n\n const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');\n const config = { ...loadSvelteConfig(), ...svelteOptions };\n\n try {\n const csfPlugin = require('./svelte/csf-plugin').default;\n plugins.push(csfPlugin(config));\n } catch (err) {\n // Not all projects use `.stories.svelte` for stories, and by default 6.5+ does not auto-install @storybook/addon-svelte-csf.\n // If it's any other kind of error, re-throw.\n if ((err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {\n throw err;\n }\n }\n\n const { svelteDocgen } = await import('./plugins/svelte-docgen');\n plugins.push(svelteDocgen(config));\n }\n\n if (framework === 'preact') {\n plugins.push(require('@preact/preset-vite').default());\n }\n\n if (framework === 'react') {\n const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply(\n 'typescript',\n {} as TypescriptConfig\n );\n\n let typescriptPresent;\n\n try {\n require.resolve('typescript');\n typescriptPresent = true;\n } catch (e) {\n typescriptPresent = false;\n }\n\n if (reactDocgenOption === 'react-docgen-typescript' && typescriptPresent) {\n plugins.push(\n require('@joshwooding/vite-plugin-react-docgen-typescript')({\n ...reactDocgenTypescriptOptions,\n // We *need* this set so that RDT returns default values in the same format as react-docgen\n savePropValueAsString: true,\n })\n );\n }\n\n // Add react-docgen so long as the option is not false\n if (typeof reactDocgenOption === 'string') {\n const { reactDocgen } = await import('./plugins/react-docgen');\n // Needs to run before the react plugin, so add to the front\n plugins.unshift(\n // If react-docgen is specified, use it for everything, otherwise only use it for non-typescript files\n reactDocgen({ include: reactDocgenOption === 'react-docgen' ? /\\.(mjs|tsx?|jsx?)$/ : /\\.(mjs|jsx?)$/ })\n );\n }\n }\n\n if (framework === 'glimmerx') {\n const plugin = require('vite-plugin-glimmerx/index.cjs');\n plugins.push(plugin.default());\n }\n\n return plugins;\n}\n"]}
package/optimizeDeps.ts CHANGED
@@ -23,6 +23,7 @@ const INCLUDE_CANDIDATES = [
23
23
  '@storybook/react > acorn-jsx',
24
24
  '@storybook/react',
25
25
  '@storybook/svelte',
26
+ '@storybook/vue',
26
27
  '@storybook/vue3',
27
28
  'acorn-jsx',
28
29
  'acorn-walk',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-vite",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
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",
@@ -12,12 +12,23 @@
12
12
  "directory": "packages/builder-vite"
13
13
  },
14
14
  "homepage": "https://github.com/storybookjs/builder-vite/#readme",
15
+ "scripts": {
16
+ "start": "yarn build -w",
17
+ "build": "tsc -p ./tsconfig.json",
18
+ "prepublish": "yarn build",
19
+ "lint": "yarn lint:prettier && yarn lint:eslint",
20
+ "lint:prettier": "prettier --write .",
21
+ "lint:eslint": "eslint \"**/*.{ts,tsx,js,jsx,mjs,cjs}\" --fix",
22
+ "lint-ci": "yarn lint-ci:prettier && yarn lint-ci:eslint",
23
+ "lint-ci:prettier": "prettier . --check",
24
+ "lint-ci:eslint": "eslint \"**/*.{ts,tsx,js,jsx,mjs,cjs}\" --max-warnings=0"
25
+ },
15
26
  "dependencies": {
16
27
  "@joshwooding/vite-plugin-react-docgen-typescript": "0.0.5",
17
- "@rollup/pluginutils": "^4.2.1",
18
28
  "@storybook/core-common": "^6.4.3",
19
29
  "@storybook/mdx1-csf": "^0.0.4",
20
30
  "@storybook/node-logger": "^6.4.3",
31
+ "@storybook/semver": "^7.3.2",
21
32
  "@storybook/source-loader": "^6.4.3",
22
33
  "@vitejs/plugin-react": "^2.0.0",
23
34
  "ast-types": "^0.14.2",
@@ -30,22 +41,47 @@
30
41
  "sveltedoc-parser": "^4.2.1"
31
42
  },
32
43
  "devDependencies": {
44
+ "@storybook/addon-svelte-csf": "^2.0.7",
45
+ "@storybook/client-api": "^6.5.12",
33
46
  "@storybook/mdx2-csf": "^0.0.3",
34
47
  "@sveltejs/vite-plugin-svelte": "^1.0.0",
35
48
  "@types/express": "^4.17.13",
36
49
  "@types/node": "^17.0.23",
50
+ "@typescript-eslint/eslint-plugin": "^5.38.0",
51
+ "@typescript-eslint/parser": "^5.38.0",
52
+ "eslint": "^8.23.1",
53
+ "eslint-config-prettier": "^8.5.0",
54
+ "eslint-plugin-only-warn": "^1.0.3",
55
+ "eslint-plugin-storybook": "^0.6.4",
56
+ "prettier": "^2.7.1",
57
+ "svelte": "^3.50.1",
58
+ "typescript": "^4.8.3",
59
+ "vite": "^3.1.0-beta.1",
37
60
  "vue-docgen-api": "^4.40.0"
38
61
  },
39
62
  "peerDependencies": {
40
63
  "@storybook/mdx2-csf": "^0.0.3",
41
- "vite": ">= 3.0.0"
64
+ "@sveltejs/vite-plugin-svelte": "^1.0.0",
65
+ "@vitejs/plugin-vue": "^3.0.0",
66
+ "vite": ">= 3.0.0",
67
+ "vue-docgen-api": "^4.40.0"
42
68
  },
43
69
  "peerDependenciesMeta": {
44
70
  "@storybook/mdx2-csf": {
45
71
  "optional": true
72
+ },
73
+ "@sveltejs/vite-plugin-svelte": {
74
+ "optional": true
75
+ },
76
+ "@vitejs/plugin-vue": {
77
+ "optional": true
78
+ },
79
+ "vue-docgen-api": {
80
+ "optional": true
46
81
  }
47
82
  },
48
83
  "publishConfig": {
49
84
  "access": "public"
50
- }
85
+ },
86
+ "packageManager": "yarn@3.1.1"
51
87
  }
@@ -60,7 +60,11 @@ export function mdxPlugin(options: Options): Plugin {
60
60
 
61
61
  const modifiedCode = injectRenderer(mdxCode, Boolean(features?.previewMdx2));
62
62
 
63
- const result = await reactRefresh?.transform!.call(this, modifiedCode, `${id}.jsx`, options);
63
+ // Hooks in recent rollup versions can be functions or objects, and though react hasn't changed, the typescript defs have
64
+ const rTransform = reactRefresh?.transform;
65
+ const transform = rTransform && 'handler' in rTransform ? rTransform.handler : rTransform;
66
+
67
+ const result = await transform!.call(this, modifiedCode, `${id}.jsx`, options);
64
68
 
65
69
  if (!result) return modifiedCode;
66
70
 
@@ -1,5 +1,4 @@
1
1
  import path from 'path';
2
- import { createFilter } from '@rollup/pluginutils';
3
2
  import {
4
3
  parse,
5
4
  handlers as docgenHandlers,
@@ -9,6 +8,7 @@ import {
9
8
  import type { DocumentationObject } from 'react-docgen/lib/Documentation';
10
9
  import MagicString from 'magic-string';
11
10
  import type { Plugin } from 'vite';
11
+ import { createFilter } from 'vite';
12
12
  import actualNameHandler from './docgen-handlers/actualNameHandler';
13
13
 
14
14
  type DocObj = DocumentationObject & { actualName: string };
@@ -2,7 +2,7 @@ import { parse } from 'vue-docgen-api';
2
2
  import type { Plugin } from 'vite';
3
3
  import MagicString from 'magic-string';
4
4
 
5
- export function vueDocgen(): Plugin {
5
+ export function vueDocgen(vueVersion: 2 | 3): Plugin {
6
6
  return {
7
7
  name: 'vue-docgen',
8
8
 
@@ -11,7 +11,8 @@ export function vueDocgen(): Plugin {
11
11
  const metaData = await parse(id);
12
12
  const metaSource = JSON.stringify(metaData);
13
13
  const s = new MagicString(src);
14
- s.append(`;_sfc_main.__docgenInfo = ${metaSource}`);
14
+ const componentLocation = vueVersion === 3 ? '_sfc_main' : '__component__.exports';
15
+ s.append(`;${componentLocation}.__docgenInfo = ${metaSource}`);
15
16
 
16
17
  return {
17
18
  code: s.toString(),
@@ -0,0 +1 @@
1
+ declare module '@storybook/semver';
package/vite-config.ts CHANGED
@@ -3,6 +3,7 @@ import fs from 'fs';
3
3
  import { Plugin } from 'vite';
4
4
  import { TypescriptConfig } from '@storybook/core-common';
5
5
  import viteReact from '@vitejs/plugin-react';
6
+ import semver from '@storybook/semver';
6
7
 
7
8
  import { allowedEnvPrefix as envPrefix } from './envs';
8
9
  import { codeGeneratorPlugin } from './code-generator-plugin';
@@ -16,8 +17,8 @@ import type { ExtendedOptions } from './types';
16
17
 
17
18
  export type PluginConfigType = 'build' | 'development';
18
19
 
19
- export function readPackageJson(): Record<string, any> | false {
20
- const packageJsonPath = path.resolve('package.json');
20
+ export function readPackageJson(dir: string = process.cwd()): Record<string, any> | false {
21
+ const packageJsonPath = path.resolve(dir, 'package.json');
21
22
  if (!fs.existsSync(packageJsonPath)) {
22
23
  return false;
23
24
  }
@@ -32,6 +33,7 @@ export async function commonConfig(
32
33
  _type: PluginConfigType
33
34
  ): Promise<UserConfig & { configFile: false; root: string }> {
34
35
  const { framework } = options;
36
+ const vuePath = framework === 'vue3' ? 'vue/dist/vue.esm-bundler.js' : 'vue/dist/vue.esm.js';
35
37
 
36
38
  return {
37
39
  configFile: false,
@@ -39,14 +41,13 @@ export async function commonConfig(
39
41
  cacheDir: 'node_modules/.vite-storybook',
40
42
  envPrefix,
41
43
  define: {},
42
- resolve:
43
- framework === 'vue3'
44
- ? {
45
- alias: {
46
- vue: 'vue/dist/vue.esm-bundler.js',
47
- },
48
- }
49
- : {},
44
+ resolve: /^vue3?$/.test(framework)
45
+ ? {
46
+ alias: {
47
+ vue: vuePath,
48
+ },
49
+ }
50
+ : {},
50
51
  plugins: await pluginConfig(options, _type),
51
52
  };
52
53
  }
@@ -54,6 +55,7 @@ export async function commonConfig(
54
55
  export async function pluginConfig(options: ExtendedOptions, _type: PluginConfigType) {
55
56
  const { framework, presets } = options;
56
57
  const svelteOptions: Record<string, any> = await presets.apply('svelteOptions', {}, options);
58
+ const root = path.resolve(options.configDir, '..');
57
59
 
58
60
  const plugins = [
59
61
  codeGeneratorPlugin(options),
@@ -80,23 +82,70 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
80
82
  },
81
83
  },
82
84
  ] as Plugin[];
83
- if (framework === 'vue' || framework === 'vue3') {
85
+
86
+ if (framework === 'vue') {
87
+ const pkgJson = readPackageJson(root);
88
+ const vueVer: string | false | undefined = pkgJson && (pkgJson?.dependencies?.vue ?? pkgJson?.devDependencies?.vue);
89
+ // Default to 2.7, but check if package.json has a version that is less than 2.7
90
+ const is26 = vueVer && semver.gtr('2.7.0', vueVer);
91
+ try {
92
+ const vuePlugin = is26 ? require('vite-plugin-vue2').createVuePlugin : require('@vitejs/plugin-vue2');
93
+ plugins.push(vuePlugin());
94
+ } catch (err) {
95
+ if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
96
+ throw new Error(`
97
+ @storybook/builder-vite requires ${
98
+ is26 ? 'vite-plugin-vue2' : '@vitejs/plugin-vue2'
99
+ } to be installed when using @storybook/vue.
100
+ Please install it and start storybook again.
101
+ `);
102
+ }
103
+ throw err;
104
+ }
105
+ try {
106
+ const { vueDocgen } = await import('./plugins/vue-docgen');
107
+ plugins.push(vueDocgen(2));
108
+ } catch (err) {
109
+ if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
110
+ throw new Error(
111
+ '@storybook/builder-vite requires vue-docgen-api to be installed ' +
112
+ 'when using @storybook/vue.' +
113
+ ' Please install it and start storybook again.'
114
+ );
115
+ }
116
+ throw err;
117
+ }
118
+ }
119
+
120
+ if (framework === 'vue3') {
84
121
  try {
85
122
  const vuePlugin = require('@vitejs/plugin-vue');
86
123
  plugins.push(vuePlugin());
124
+ } catch (err) {
125
+ if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
126
+ throw new Error(`
127
+ @storybook/builder-vite requires @vitejs/plugin-vue to be installed when using @storybook/vue3.
128
+ Please install it and start storybook again.
129
+ `);
130
+ }
131
+ throw err;
132
+ }
133
+
134
+ try {
87
135
  const { vueDocgen } = await import('./plugins/vue-docgen');
88
- plugins.push(vueDocgen());
136
+ plugins.push(vueDocgen(3));
89
137
  } catch (err) {
90
138
  if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
91
139
  throw new Error(
92
- '@storybook/builder-vite requires @vitejs/plugin-vue to be installed ' +
93
- 'when using @storybook/vue or @storybook/vue3.' +
140
+ '@storybook/builder-vite requires vue-docgen-api to be installed ' +
141
+ 'when using @storybook/vue3.' +
94
142
  ' Please install it and start storybook again.'
95
143
  );
96
144
  }
97
145
  throw err;
98
146
  }
99
147
  }
148
+
100
149
  if (framework === 'svelte') {
101
150
  try {
102
151
  const sveltePlugin = require('@sveltejs/vite-plugin-svelte').svelte;
@@ -169,7 +218,16 @@ export async function pluginConfig(options: ExtendedOptions, _type: PluginConfig
169
218
  {} as TypescriptConfig
170
219
  );
171
220
 
172
- if (reactDocgenOption === 'react-docgen-typescript') {
221
+ let typescriptPresent;
222
+
223
+ try {
224
+ require.resolve('typescript');
225
+ typescriptPresent = true;
226
+ } catch (e) {
227
+ typescriptPresent = false;
228
+ }
229
+
230
+ if (reactDocgenOption === 'react-docgen-typescript' && typescriptPresent) {
173
231
  plugins.push(
174
232
  require('@joshwooding/vite-plugin-react-docgen-typescript')({
175
233
  ...reactDocgenTypescriptOptions,
File without changes
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=mdx-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mdx-plugin.js","sourceRoot":"","sources":["../mdx-plugin.ts"],"names":[],"mappings":"","sourcesContent":[""]}
@@ -1,5 +0,0 @@
1
- export declare function mockCoreJs(): {
2
- name: string;
3
- resolveId(id: string): string | undefined;
4
- load(id: string): "" | undefined;
5
- };
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mockCoreJs = void 0;
4
- function mockCoreJs() {
5
- return {
6
- name: 'mock-core-js',
7
- resolveId(id) {
8
- if (id.includes('node_modules/core-js')) {
9
- return id;
10
- }
11
- return undefined;
12
- },
13
- load(id) {
14
- if (id.includes('node_modules/core-js')) {
15
- return '';
16
- }
17
- return undefined;
18
- },
19
- };
20
- }
21
- exports.mockCoreJs = mockCoreJs;
22
- //# sourceMappingURL=mock-core-js.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mock-core-js.js","sourceRoot":"","sources":["../mock-core-js.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU;IACxB,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,SAAS,CAAC,EAAU;YAClB,IAAI,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE;gBACvC,OAAO,EAAE,CAAC;aACX;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,CAAC,EAAU;YACb,IAAI,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC,EAAE;gBACvC,OAAO,EAAE,CAAC;aACX;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC;AAhBD,gCAgBC","sourcesContent":["export function mockCoreJs() {\n return {\n name: 'mock-core-js',\n resolveId(id: string) {\n if (id.includes('node_modules/core-js')) {\n return id;\n }\n return undefined;\n },\n load(id: string) {\n if (id.includes('node_modules/core-js')) {\n return '';\n }\n return undefined;\n },\n };\n}\n"]}