@storybook/react-vite 10.1.0-alpha.9 → 10.1.0-beta.0

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.
@@ -1,22 +1,20 @@
1
- import CJS_COMPAT_NODE_URL_slia6ilnti9 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_slia6ilnti9 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_slia6ilnti9 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_3pjujwejjlf from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_3pjujwejjlf from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_3pjujwejjlf from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_slia6ilnti9.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_slia6ilnti9.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_slia6ilnti9.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_3pjujwejjlf.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_3pjujwejjlf.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_3pjujwejjlf.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- import {
13
- __name
14
- } from "./chunk-Z3ZDR4BX.js";
15
12
 
16
13
  // src/plugins/react-docgen.ts
17
14
  import { existsSync } from "node:fs";
18
15
  import { relative, sep } from "node:path";
19
16
  import { getProjectRoot } from "storybook/internal/common";
17
+ import { logger } from "storybook/internal/node-logger";
20
18
  import { createFilter } from "@rollup/pluginutils";
21
19
  import * as find from "empathic/find";
22
20
  import MagicString from "magic-string";
@@ -31,23 +29,21 @@ import * as TsconfigPaths from "tsconfig-paths";
31
29
 
32
30
  // src/plugins/docgen-handlers/actualNameHandler.ts
33
31
  import { utils } from "react-docgen";
34
- var { getNameOrValue, isReactForwardRefCall } = utils;
35
- var actualNameHandler = /* @__PURE__ */ __name(function actualNameHandler2(documentation, componentDefinition) {
36
- documentation.set("definedInFile", componentDefinition.hub.file.opts.filename);
37
- if ((componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id")) {
32
+ var { getNameOrValue, isReactForwardRefCall } = utils, actualNameHandler = function(documentation, componentDefinition) {
33
+ if (documentation.set("definedInFile", componentDefinition.hub.file.opts.filename), (componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id"))
38
34
  documentation.set(
39
35
  "actualName",
40
36
  getNameOrValue(componentDefinition.get("id"))
41
37
  );
42
- } else if (componentDefinition.isArrowFunctionExpression() || componentDefinition.isFunctionExpression() || isReactForwardRefCall(componentDefinition)) {
38
+ else if (componentDefinition.isArrowFunctionExpression() || componentDefinition.isFunctionExpression() || isReactForwardRefCall(componentDefinition)) {
43
39
  let currentPath = componentDefinition;
44
- while (currentPath.parentPath) {
40
+ for (; currentPath.parentPath; ) {
45
41
  if (currentPath.parentPath.isVariableDeclarator()) {
46
42
  documentation.set("actualName", getNameOrValue(currentPath.parentPath.get("id")));
47
43
  return;
48
44
  }
49
45
  if (currentPath.parentPath.isAssignmentExpression()) {
50
- const leftPath = currentPath.parentPath.get("left");
46
+ let leftPath = currentPath.parentPath.get("left");
51
47
  if (leftPath.isIdentifier() || leftPath.isLiteral()) {
52
48
  documentation.set("actualName", getNameOrValue(leftPath));
53
49
  return;
@@ -57,8 +53,7 @@ var actualNameHandler = /* @__PURE__ */ __name(function actualNameHandler2(docum
57
53
  }
58
54
  documentation.set("actualName", "");
59
55
  }
60
- }, "actualNameHandler");
61
- var actualNameHandler_default = actualNameHandler;
56
+ }, actualNameHandler_default = actualNameHandler;
62
57
 
63
58
  // src/plugins/docgen-resolver.ts
64
59
  import { extname } from "node:path";
@@ -69,11 +64,7 @@ var ReactDocgenResolveError = class extends Error {
69
64
  // the magic string that react-docgen uses to check if a module is ignored
70
65
  this.code = "MODULE_NOT_FOUND";
71
66
  }
72
- static {
73
- __name(this, "ReactDocgenResolveError");
74
- }
75
- };
76
- var RESOLVE_EXTENSIONS = [
67
+ }, RESOLVE_EXTENSIONS = [
77
68
  ".js",
78
69
  ".cts",
79
70
  // These were originally not in the code, I added them
@@ -92,17 +83,16 @@ var RESOLVE_EXTENSIONS = [
92
83
  ".jsx"
93
84
  ];
94
85
  function defaultLookupModule(filename, basedir) {
95
- const resolveOptions = {
86
+ let resolveOptions = {
96
87
  basedir,
97
88
  extensions: RESOLVE_EXTENSIONS,
98
89
  // we do not need to check core modules as we cannot import them anyway
99
- includeCoreModules: false
90
+ includeCoreModules: !1
100
91
  };
101
92
  try {
102
93
  return resolve.sync(filename, resolveOptions);
103
94
  } catch (error) {
104
- const ext = extname(filename);
105
- let newFilename;
95
+ let ext = extname(filename), newFilename;
106
96
  switch (ext) {
107
97
  case ".js":
108
98
  case ".mjs":
@@ -122,93 +112,64 @@ function defaultLookupModule(filename, basedir) {
122
112
  });
123
113
  }
124
114
  }
125
- __name(defaultLookupModule, "defaultLookupModule");
126
115
 
127
116
  // src/plugins/react-docgen.ts
128
- var defaultHandlers = Object.values(docgenHandlers).map((handler) => handler);
129
- var defaultResolver = new docgenResolver.FindExportedDefinitionsResolver();
130
- var handlers = [...defaultHandlers, actualNameHandler_default];
117
+ var defaultHandlers = Object.values(docgenHandlers).map((handler) => handler), defaultResolver = new docgenResolver.FindExportedDefinitionsResolver(), handlers = [...defaultHandlers, actualNameHandler_default];
131
118
  async function reactDocgen({
132
119
  include = /\.(mjs|tsx?|jsx?)$/,
133
120
  exclude = [/node_modules\/.*/]
134
121
  } = {}) {
135
- const cwd = process.cwd();
136
- const filter = createFilter(include, exclude);
137
- const tsconfigPath = find.up("tsconfig.json", { cwd, last: getProjectRoot() });
138
- const tsconfig = TsconfigPaths.loadConfig(tsconfigPath);
139
- let matchPath;
140
- if (tsconfig.resultType === "success") {
141
- matchPath = TsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths, [
142
- "browser",
143
- "module",
144
- "main"
145
- ]);
146
- }
147
- return {
122
+ let cwd = process.cwd(), filter = createFilter(include, exclude), tsconfigPath = find.up("tsconfig.json", { cwd, last: getProjectRoot() }), tsconfig = TsconfigPaths.loadConfig(tsconfigPath), matchPath;
123
+ return tsconfig.resultType === "success" && (logger.debug("Using tsconfig paths for react-docgen"), matchPath = TsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths, [
124
+ "browser",
125
+ "module",
126
+ "main"
127
+ ])), {
148
128
  name: "storybook:react-docgen-plugin",
149
129
  enforce: "pre",
150
130
  async transform(src, id) {
151
- if (!filter(relative(cwd, id))) {
152
- return;
153
- }
154
- try {
155
- const docgenResults = parse(src, {
156
- resolver: defaultResolver,
157
- handlers,
158
- importer: getReactDocgenImporter(matchPath),
159
- filename: id
160
- });
161
- const s = new MagicString(src);
162
- docgenResults.forEach((info) => {
163
- const { actualName, definedInFile, ...docgenInfo } = info;
164
- if (actualName && definedInFile == id) {
165
- const docNode = JSON.stringify(docgenInfo);
166
- s.append(`;${actualName}.__docgenInfo=${docNode}`);
167
- }
168
- });
169
- return {
170
- code: s.toString(),
171
- map: s.generateMap({ hires: true, source: id })
172
- };
173
- } catch (e) {
174
- if (e.code === ERROR_CODES.MISSING_DEFINITION) {
175
- return;
131
+ if (filter(relative(cwd, id)))
132
+ try {
133
+ let docgenResults = parse(src, {
134
+ resolver: defaultResolver,
135
+ handlers,
136
+ importer: getReactDocgenImporter(matchPath),
137
+ filename: id
138
+ }), s = new MagicString(src);
139
+ return docgenResults.forEach((info) => {
140
+ let { actualName, definedInFile, ...docgenInfo } = info;
141
+ if (actualName && definedInFile == id) {
142
+ let docNode = JSON.stringify(docgenInfo);
143
+ s.append(`;${actualName}.__docgenInfo=${docNode}`);
144
+ }
145
+ }), {
146
+ code: s.toString(),
147
+ map: s.generateMap({ hires: !0, source: id })
148
+ };
149
+ } catch (e) {
150
+ if (e.code === ERROR_CODES.MISSING_DEFINITION)
151
+ return;
152
+ throw e;
176
153
  }
177
- throw e;
178
- }
179
154
  }
180
155
  };
181
156
  }
182
- __name(reactDocgen, "reactDocgen");
183
157
  function getReactDocgenImporter(matchPath) {
184
158
  return makeFsImporter((filename, basedir) => {
185
- const mappedFilenameByPaths = (() => {
186
- if (matchPath) {
187
- const match = matchPath(filename);
188
- return match || filename;
189
- } else {
190
- return filename;
191
- }
192
- })();
193
- const result = defaultLookupModule(mappedFilenameByPaths, basedir);
159
+ let mappedFilenameByPaths = matchPath && matchPath(filename) || filename, result = defaultLookupModule(mappedFilenameByPaths, basedir);
194
160
  if (result.includes(`${sep}react-native${sep}index.js`)) {
195
- const replaced = result.replace(
161
+ let replaced = result.replace(
196
162
  `${sep}react-native${sep}index.js`,
197
163
  `${sep}react-native-web${sep}dist${sep}index.js`
198
164
  );
199
- if (existsSync(replaced)) {
200
- if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
201
- return replaced;
202
- }
203
- }
165
+ if (existsSync(replaced) && RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext)))
166
+ return replaced;
204
167
  }
205
- if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
168
+ if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext)))
206
169
  return result;
207
- }
208
170
  throw new ReactDocgenResolveError(filename);
209
171
  });
210
172
  }
211
- __name(getReactDocgenImporter, "getReactDocgenImporter");
212
173
  export {
213
174
  getReactDocgenImporter,
214
175
  reactDocgen
@@ -1,23 +1,19 @@
1
- import CJS_COMPAT_NODE_URL_slia6ilnti9 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_slia6ilnti9 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_slia6ilnti9 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_3pjujwejjlf from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_3pjujwejjlf from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_3pjujwejjlf from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_slia6ilnti9.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_slia6ilnti9.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_slia6ilnti9.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_3pjujwejjlf.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_3pjujwejjlf.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_3pjujwejjlf.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- import {
13
- __name
14
- } from "../_node-chunks/chunk-Z3ZDR4BX.js";
15
12
 
16
13
  // src/node/index.ts
17
14
  function defineMain(config) {
18
15
  return config;
19
16
  }
20
- __name(defineMain, "defineMain");
21
17
  export {
22
18
  defineMain
23
19
  };
package/dist/preset.js CHANGED
@@ -1,47 +1,37 @@
1
- import CJS_COMPAT_NODE_URL_slia6ilnti9 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_slia6ilnti9 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_slia6ilnti9 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_3pjujwejjlf from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_3pjujwejjlf from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_3pjujwejjlf from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_slia6ilnti9.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_slia6ilnti9.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_slia6ilnti9.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_3pjujwejjlf.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_3pjujwejjlf.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_3pjujwejjlf.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- import {
13
- __name
14
- } from "./_node-chunks/chunk-Z3ZDR4BX.js";
15
12
 
16
13
  // src/preset.ts
17
14
  var core = {
18
15
  builder: import.meta.resolve("@storybook/builder-vite"),
19
16
  renderer: import.meta.resolve("@storybook/react/preset")
20
- };
21
- var viteFinal = /* @__PURE__ */ __name(async (config, { presets }) => {
22
- const plugins = [...config?.plugins ?? []];
23
- const { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply(
17
+ }, viteFinal = async (config, { presets }) => {
18
+ let plugins = [...config?.plugins ?? []], { reactDocgen: reactDocgenOption, reactDocgenTypescriptOptions } = await presets.apply(
24
19
  "typescript",
25
20
  {}
26
- );
27
- let typescriptPresent;
21
+ ), typescriptPresent;
28
22
  try {
29
- import.meta.resolve("typescript");
30
- typescriptPresent = true;
31
- } catch (e) {
32
- typescriptPresent = false;
23
+ import.meta.resolve("typescript"), typescriptPresent = !0;
24
+ } catch {
25
+ typescriptPresent = !1;
33
26
  }
34
- if (reactDocgenOption === "react-docgen-typescript" && typescriptPresent) {
35
- plugins.push(
36
- (await import("@joshwooding/vite-plugin-react-docgen-typescript")).default({
37
- ...reactDocgenTypescriptOptions,
38
- // We *need* this set so that RDT returns default values in the same format as react-docgen
39
- savePropValueAsString: true
40
- })
41
- );
42
- }
43
- if (typeof reactDocgenOption === "string") {
44
- const { reactDocgen } = await import("./_node-chunks/react-docgen-56DNIACL.js");
27
+ if (reactDocgenOption === "react-docgen-typescript" && typescriptPresent && plugins.push(
28
+ (await import("@joshwooding/vite-plugin-react-docgen-typescript")).default({
29
+ ...reactDocgenTypescriptOptions,
30
+ // We *need* this set so that RDT returns default values in the same format as react-docgen
31
+ savePropValueAsString: !0
32
+ })
33
+ ), typeof reactDocgenOption == "string") {
34
+ let { reactDocgen } = await import("./_node-chunks/react-docgen-A42DYXKP.js");
45
35
  plugins.unshift(
46
36
  // If react-docgen is specified, use it for everything, otherwise only use it for non-typescript files
47
37
  await reactDocgen({
@@ -50,7 +40,7 @@ var viteFinal = /* @__PURE__ */ __name(async (config, { presets }) => {
50
40
  );
51
41
  }
52
42
  return { ...config, plugins };
53
- }, "viteFinal");
43
+ };
54
44
  export {
55
45
  core,
56
46
  viteFinal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react-vite",
3
- "version": "10.1.0-alpha.9",
3
+ "version": "10.1.0-beta.0",
4
4
  "description": "Storybook for React and Vite: Develop, document, and test UI components in isolation",
5
5
  "keywords": [
6
6
  "storybook",
@@ -55,8 +55,8 @@
55
55
  "dependencies": {
56
56
  "@joshwooding/vite-plugin-react-docgen-typescript": "0.6.1",
57
57
  "@rollup/pluginutils": "^5.0.2",
58
- "@storybook/builder-vite": "10.1.0-alpha.9",
59
- "@storybook/react": "10.1.0-alpha.9",
58
+ "@storybook/builder-vite": "10.1.0-beta.0",
59
+ "@storybook/react": "10.1.0-beta.0",
60
60
  "empathic": "^2.0.0",
61
61
  "magic-string": "^0.30.0",
62
62
  "react-docgen": "^8.0.0",
@@ -71,11 +71,11 @@
71
71
  "peerDependencies": {
72
72
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
73
73
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
74
- "storybook": "^10.1.0-alpha.9",
74
+ "storybook": "^10.1.0-beta.0",
75
75
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
76
76
  },
77
77
  "publishConfig": {
78
78
  "access": "public"
79
79
  },
80
- "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae16"
80
+ "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae1l"
81
81
  }
@@ -1,17 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_slia6ilnti9 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_slia6ilnti9 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_slia6ilnti9 from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_slia6ilnti9.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_slia6ilnti9.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_slia6ilnti9.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
- var __defProp = Object.defineProperty;
13
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
-
15
- export {
16
- __name
17
- };