@storybook/builder-vite 7.0.0-alpha.39 → 7.0.0-alpha.41

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/dist/cjs/index.js CHANGED
@@ -5,6 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.bail = bail;
7
7
  exports.start = exports.build = void 0;
8
+ Object.defineProperty(exports, "withoutVitePlugins", {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _withoutVitePlugins.withoutVitePlugins;
12
+ }
13
+ });
8
14
 
9
15
  var fs = _interopRequireWildcard(require("fs"));
10
16
 
@@ -16,6 +22,8 @@ var _viteServer = require("./vite-server");
16
22
 
17
23
  var _build = require("./build");
18
24
 
25
+ var _withoutVitePlugins = require("./utils/without-vite-plugins");
26
+
19
27
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
28
 
21
29
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -67,11 +67,11 @@ function mdxPlugin(options) {
67
67
 
68
68
  const {
69
69
  compile
70
- } = features !== null && features !== void 0 && features.previewMdx2 ? await Promise.resolve().then(() => _interopRequireWildcard(require('@storybook/mdx2-csf'))) : await Promise.resolve().then(() => _interopRequireWildcard(require('@storybook/mdx1-csf')));
70
+ } = await Promise.resolve().then(() => _interopRequireWildcard(require('@storybook/mdx2-csf')));
71
71
  const mdxCode = String(await compile(src, {
72
72
  skipCsf: !isStorybookMdx(id)
73
73
  }));
74
- const modifiedCode = injectRenderer(mdxCode, Boolean(features === null || features === void 0 ? void 0 : features.previewMdx2)); // Hooks in recent rollup versions can be functions or objects, and though react hasn't changed, the typescript defs have
74
+ const modifiedCode = injectRenderer(mdxCode, true); // Hooks in recent rollup versions can be functions or objects, and though react hasn't changed, the typescript defs have
75
75
 
76
76
  const rTransform = (_reactRefresh = reactRefresh) === null || _reactRefresh === void 0 ? void 0 : _reactRefresh.transform;
77
77
  const transform = rTransform && 'handler' in rTransform ? rTransform.handler : rTransform; // It's safe to disable this, because we know it'll be there, since we added it ourselves.
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.withoutVitePlugins = void 0;
7
+
8
+ // recursively remove all plugins with the given names
9
+ const withoutVitePlugins = (plugins = [], namesToRemove) => plugins.map(plugin => {
10
+ if (Array.isArray(plugin)) {
11
+ return withoutVitePlugins(plugin, namesToRemove);
12
+ }
13
+
14
+ if (plugin && 'name' in plugin && namesToRemove.includes(plugin.name)) {
15
+ return false;
16
+ }
17
+
18
+ return plugin;
19
+ });
20
+
21
+ exports.withoutVitePlugins = withoutVitePlugins;
package/dist/esm/index.js CHANGED
@@ -4,6 +4,7 @@ import * as path from 'path';
4
4
  import { transformIframeHtml } from './transform-iframe-html';
5
5
  import { createViteServer } from './vite-server';
6
6
  import { build as viteBuild } from './build';
7
+ export { withoutVitePlugins } from './utils/without-vite-plugins';
7
8
 
8
9
  function iframeMiddleware(options, server) {
9
10
  return async (req, res, next) => {
@@ -54,11 +54,11 @@ export function mdxPlugin(options) {
54
54
 
55
55
  const {
56
56
  compile
57
- } = features?.previewMdx2 ? await import('@storybook/mdx2-csf') : await import('@storybook/mdx1-csf');
57
+ } = await import('@storybook/mdx2-csf');
58
58
  const mdxCode = String(await compile(src, {
59
59
  skipCsf: !isStorybookMdx(id)
60
60
  }));
61
- const modifiedCode = injectRenderer(mdxCode, Boolean(features?.previewMdx2)); // Hooks in recent rollup versions can be functions or objects, and though react hasn't changed, the typescript defs have
61
+ const modifiedCode = injectRenderer(mdxCode, true); // Hooks in recent rollup versions can be functions or objects, and though react hasn't changed, the typescript defs have
62
62
 
63
63
  const rTransform = reactRefresh?.transform;
64
64
  const transform = rTransform && 'handler' in rTransform ? rTransform.handler : rTransform; // It's safe to disable this, because we know it'll be there, since we added it ourselves.
@@ -0,0 +1,12 @@
1
+ // recursively remove all plugins with the given names
2
+ export const withoutVitePlugins = (plugins = [], namesToRemove) => plugins.map(plugin => {
3
+ if (Array.isArray(plugin)) {
4
+ return withoutVitePlugins(plugin, namesToRemove);
5
+ }
6
+
7
+ if (plugin && 'name' in plugin && namesToRemove.includes(plugin.name)) {
8
+ return false;
9
+ }
10
+
11
+ return plugin;
12
+ });
@@ -1,5 +1,6 @@
1
1
  import type { Builder, StorybookConfig as StorybookBaseConfig, Options } from '@storybook/core-common';
2
2
  import type { InlineConfig, UserConfig } from 'vite';
3
+ export { withoutVitePlugins } from './utils/without-vite-plugins';
3
4
  export type { TypescriptOptions } from '@storybook/core-common';
4
5
  export declare type ViteStats = {
5
6
  toJson: () => any;
@@ -0,0 +1,2 @@
1
+ import { PluginOption } from 'vite';
2
+ export declare const withoutVitePlugins: (plugins: PluginOption[] | undefined, namesToRemove: string[]) => PluginOption[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-vite",
3
- "version": "7.0.0-alpha.39",
3
+ "version": "7.0.0-alpha.41",
4
4
  "description": "A plugin to run and build Storybooks with Vite",
5
5
  "homepage": "https://github.com/storybookjs/storybook/tree/main/code/lib/builder-vite/#readme",
6
6
  "repository": {
@@ -19,13 +19,13 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@joshwooding/vite-plugin-react-docgen-typescript": "0.0.5",
22
- "@storybook/client-api": "7.0.0-alpha.39",
23
- "@storybook/client-logger": "7.0.0-alpha.39",
24
- "@storybook/core-common": "7.0.0-alpha.39",
25
- "@storybook/mdx1-csf": "0.0.5-canary.13.9ce928a.0",
26
- "@storybook/node-logger": "7.0.0-alpha.39",
27
- "@storybook/preview-web": "7.0.0-alpha.39",
28
- "@storybook/source-loader": "7.0.0-alpha.39",
22
+ "@storybook/client-api": "7.0.0-alpha.41",
23
+ "@storybook/client-logger": "7.0.0-alpha.41",
24
+ "@storybook/core-common": "7.0.0-alpha.41",
25
+ "@storybook/mdx2-csf": "0.1.0-next.0",
26
+ "@storybook/node-logger": "7.0.0-alpha.41",
27
+ "@storybook/preview-web": "7.0.0-alpha.41",
28
+ "@storybook/source-loader": "7.0.0-alpha.41",
29
29
  "@vitejs/plugin-react": "^2.0.0",
30
30
  "browser-assert": "^1.2.1",
31
31
  "es-module-lexer": "^0.9.3",
@@ -36,22 +36,13 @@
36
36
  "vite": "^3.1.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@storybook/mdx2-csf": "^0.0.3",
40
39
  "@types/express": "^4.17.13",
41
40
  "@types/node": "^16.0.0",
42
41
  "typescript": "~4.6.3",
43
42
  "vite": "^3.1.3"
44
43
  },
45
- "peerDependencies": {
46
- "@storybook/mdx2-csf": "^0.0.3"
47
- },
48
- "peerDependenciesMeta": {
49
- "@storybook/mdx2-csf": {
50
- "optional": true
51
- }
52
- },
53
44
  "publishConfig": {
54
45
  "access": "public"
55
46
  },
56
- "gitHead": "47386bd49d141ea70daac41ab3e4d52749fc5da9"
47
+ "gitHead": "7ec6f916eb875bd2e3cf3aa6b1afcd1fe25d1637"
57
48
  }
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ import { createViteServer } from './vite-server';
14
14
  import { build as viteBuild } from './build';
15
15
  import type { ExtendedOptions } from './types';
16
16
 
17
+ export { withoutVitePlugins } from './utils/without-vite-plugins';
17
18
  export type { TypescriptOptions } from '@storybook/core-common';
18
19
 
19
20
  // Storybook's Stats are optional Webpack related property
@@ -56,13 +56,11 @@ export function mdxPlugin(options: Options): Plugin {
56
56
  if (!filter(id)) return undefined;
57
57
 
58
58
  // @ts-expect-error typescript doesn't think compile exists, but it does.
59
- const { compile } = features?.previewMdx2
60
- ? await import('@storybook/mdx2-csf')
61
- : await import('@storybook/mdx1-csf');
59
+ const { compile } = await import('@storybook/mdx2-csf');
62
60
 
63
61
  const mdxCode = String(await compile(src, { skipCsf: !isStorybookMdx(id) }));
64
62
 
65
- const modifiedCode = injectRenderer(mdxCode, Boolean(features?.previewMdx2));
63
+ const modifiedCode = injectRenderer(mdxCode, true);
66
64
 
67
65
  // Hooks in recent rollup versions can be functions or objects, and though react hasn't changed, the typescript defs have
68
66
  const rTransform = reactRefresh?.transform;
@@ -0,0 +1,16 @@
1
+ import { PluginOption } from 'vite';
2
+
3
+ // recursively remove all plugins with the given names
4
+ export const withoutVitePlugins = (
5
+ plugins: PluginOption[] = [],
6
+ namesToRemove: string[]
7
+ ): PluginOption[] =>
8
+ plugins.map((plugin) => {
9
+ if (Array.isArray(plugin)) {
10
+ return withoutVitePlugins(plugin, namesToRemove);
11
+ }
12
+ if (plugin && 'name' in plugin && namesToRemove.includes(plugin.name)) {
13
+ return false;
14
+ }
15
+ return plugin;
16
+ });