@storybook/react-vite 10.1.0-alpha.1 → 10.1.0-alpha.11

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,23 +1,19 @@
1
- import CJS_COMPAT_NODE_URL_he8fw7segub from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_he8fw7segub from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_he8fw7segub from "node:module";
1
+ import CJS_COMPAT_NODE_URL_6x0q2yvwyyv from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_6x0q2yvwyyv from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_6x0q2yvwyyv from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_he8fw7segub.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_he8fw7segub.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_he8fw7segub.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_6x0q2yvwyyv.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_6x0q2yvwyyv.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_6x0q2yvwyyv.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-VKCDFKJV.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";
20
- import { logger } from "storybook/internal/node-logger";
21
17
  import { createFilter } from "@rollup/pluginutils";
22
18
  import * as find from "empathic/find";
23
19
  import MagicString from "magic-string";
@@ -32,23 +28,21 @@ import * as TsconfigPaths from "tsconfig-paths";
32
28
 
33
29
  // src/plugins/docgen-handlers/actualNameHandler.ts
34
30
  import { utils } from "react-docgen";
35
- var { getNameOrValue, isReactForwardRefCall } = utils;
36
- var actualNameHandler = /* @__PURE__ */ __name(function actualNameHandler2(documentation, componentDefinition) {
37
- documentation.set("definedInFile", componentDefinition.hub.file.opts.filename);
38
- if ((componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id")) {
31
+ var { getNameOrValue, isReactForwardRefCall } = utils, actualNameHandler = function(documentation, componentDefinition) {
32
+ if (documentation.set("definedInFile", componentDefinition.hub.file.opts.filename), (componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id"))
39
33
  documentation.set(
40
34
  "actualName",
41
35
  getNameOrValue(componentDefinition.get("id"))
42
36
  );
43
- } else if (componentDefinition.isArrowFunctionExpression() || componentDefinition.isFunctionExpression() || isReactForwardRefCall(componentDefinition)) {
37
+ else if (componentDefinition.isArrowFunctionExpression() || componentDefinition.isFunctionExpression() || isReactForwardRefCall(componentDefinition)) {
44
38
  let currentPath = componentDefinition;
45
- while (currentPath.parentPath) {
39
+ for (; currentPath.parentPath; ) {
46
40
  if (currentPath.parentPath.isVariableDeclarator()) {
47
41
  documentation.set("actualName", getNameOrValue(currentPath.parentPath.get("id")));
48
42
  return;
49
43
  }
50
44
  if (currentPath.parentPath.isAssignmentExpression()) {
51
- const leftPath = currentPath.parentPath.get("left");
45
+ let leftPath = currentPath.parentPath.get("left");
52
46
  if (leftPath.isIdentifier() || leftPath.isLiteral()) {
53
47
  documentation.set("actualName", getNameOrValue(leftPath));
54
48
  return;
@@ -58,8 +52,7 @@ var actualNameHandler = /* @__PURE__ */ __name(function actualNameHandler2(docum
58
52
  }
59
53
  documentation.set("actualName", "");
60
54
  }
61
- }, "actualNameHandler");
62
- var actualNameHandler_default = actualNameHandler;
55
+ }, actualNameHandler_default = actualNameHandler;
63
56
 
64
57
  // src/plugins/docgen-resolver.ts
65
58
  import { extname } from "node:path";
@@ -70,11 +63,7 @@ var ReactDocgenResolveError = class extends Error {
70
63
  // the magic string that react-docgen uses to check if a module is ignored
71
64
  this.code = "MODULE_NOT_FOUND";
72
65
  }
73
- static {
74
- __name(this, "ReactDocgenResolveError");
75
- }
76
- };
77
- var RESOLVE_EXTENSIONS = [
66
+ }, RESOLVE_EXTENSIONS = [
78
67
  ".js",
79
68
  ".cts",
80
69
  // These were originally not in the code, I added them
@@ -93,17 +82,16 @@ var RESOLVE_EXTENSIONS = [
93
82
  ".jsx"
94
83
  ];
95
84
  function defaultLookupModule(filename, basedir) {
96
- const resolveOptions = {
85
+ let resolveOptions = {
97
86
  basedir,
98
87
  extensions: RESOLVE_EXTENSIONS,
99
88
  // we do not need to check core modules as we cannot import them anyway
100
- includeCoreModules: false
89
+ includeCoreModules: !1
101
90
  };
102
91
  try {
103
92
  return resolve.sync(filename, resolveOptions);
104
93
  } catch (error) {
105
- const ext = extname(filename);
106
- let newFilename;
94
+ let ext = extname(filename), newFilename;
107
95
  switch (ext) {
108
96
  case ".js":
109
97
  case ".mjs":
@@ -123,94 +111,64 @@ function defaultLookupModule(filename, basedir) {
123
111
  });
124
112
  }
125
113
  }
126
- __name(defaultLookupModule, "defaultLookupModule");
127
114
 
128
115
  // src/plugins/react-docgen.ts
129
- var defaultHandlers = Object.values(docgenHandlers).map((handler) => handler);
130
- var defaultResolver = new docgenResolver.FindExportedDefinitionsResolver();
131
- var handlers = [...defaultHandlers, actualNameHandler_default];
116
+ var defaultHandlers = Object.values(docgenHandlers).map((handler) => handler), defaultResolver = new docgenResolver.FindExportedDefinitionsResolver(), handlers = [...defaultHandlers, actualNameHandler_default];
132
117
  async function reactDocgen({
133
118
  include = /\.(mjs|tsx?|jsx?)$/,
134
119
  exclude = [/node_modules\/.*/]
135
120
  } = {}) {
136
- const cwd = process.cwd();
137
- const filter = createFilter(include, exclude);
138
- const tsconfigPath = find.up("tsconfig.json", { cwd, last: getProjectRoot() });
139
- const tsconfig = TsconfigPaths.loadConfig(tsconfigPath);
140
- let matchPath;
141
- if (tsconfig.resultType === "success") {
142
- logger.info("Using tsconfig paths for react-docgen");
143
- matchPath = TsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths, [
144
- "browser",
145
- "module",
146
- "main"
147
- ]);
148
- }
149
- return {
121
+ let cwd = process.cwd(), filter = createFilter(include, exclude), tsconfigPath = find.up("tsconfig.json", { cwd, last: getProjectRoot() }), tsconfig = TsconfigPaths.loadConfig(tsconfigPath), matchPath;
122
+ return tsconfig.resultType === "success" && (matchPath = TsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths, [
123
+ "browser",
124
+ "module",
125
+ "main"
126
+ ])), {
150
127
  name: "storybook:react-docgen-plugin",
151
128
  enforce: "pre",
152
129
  async transform(src, id) {
153
- if (!filter(relative(cwd, id))) {
154
- return;
155
- }
156
- try {
157
- const docgenResults = parse(src, {
158
- resolver: defaultResolver,
159
- handlers,
160
- importer: getReactDocgenImporter(matchPath),
161
- filename: id
162
- });
163
- const s = new MagicString(src);
164
- docgenResults.forEach((info) => {
165
- const { actualName, definedInFile, ...docgenInfo } = info;
166
- if (actualName && definedInFile == id) {
167
- const docNode = JSON.stringify(docgenInfo);
168
- s.append(`;${actualName}.__docgenInfo=${docNode}`);
169
- }
170
- });
171
- return {
172
- code: s.toString(),
173
- map: s.generateMap({ hires: true, source: id })
174
- };
175
- } catch (e) {
176
- if (e.code === ERROR_CODES.MISSING_DEFINITION) {
177
- return;
130
+ if (filter(relative(cwd, id)))
131
+ try {
132
+ let docgenResults = parse(src, {
133
+ resolver: defaultResolver,
134
+ handlers,
135
+ importer: getReactDocgenImporter(matchPath),
136
+ filename: id
137
+ }), s = new MagicString(src);
138
+ return docgenResults.forEach((info) => {
139
+ let { actualName, definedInFile, ...docgenInfo } = info;
140
+ if (actualName && definedInFile == id) {
141
+ let docNode = JSON.stringify(docgenInfo);
142
+ s.append(`;${actualName}.__docgenInfo=${docNode}`);
143
+ }
144
+ }), {
145
+ code: s.toString(),
146
+ map: s.generateMap({ hires: !0, source: id })
147
+ };
148
+ } catch (e) {
149
+ if (e.code === ERROR_CODES.MISSING_DEFINITION)
150
+ return;
151
+ throw e;
178
152
  }
179
- throw e;
180
- }
181
153
  }
182
154
  };
183
155
  }
184
- __name(reactDocgen, "reactDocgen");
185
156
  function getReactDocgenImporter(matchPath) {
186
157
  return makeFsImporter((filename, basedir) => {
187
- const mappedFilenameByPaths = (() => {
188
- if (matchPath) {
189
- const match = matchPath(filename);
190
- return match || filename;
191
- } else {
192
- return filename;
193
- }
194
- })();
195
- const result = defaultLookupModule(mappedFilenameByPaths, basedir);
158
+ let mappedFilenameByPaths = matchPath && matchPath(filename) || filename, result = defaultLookupModule(mappedFilenameByPaths, basedir);
196
159
  if (result.includes(`${sep}react-native${sep}index.js`)) {
197
- const replaced = result.replace(
160
+ let replaced = result.replace(
198
161
  `${sep}react-native${sep}index.js`,
199
162
  `${sep}react-native-web${sep}dist${sep}index.js`
200
163
  );
201
- if (existsSync(replaced)) {
202
- if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
203
- return replaced;
204
- }
205
- }
164
+ if (existsSync(replaced) && RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext)))
165
+ return replaced;
206
166
  }
207
- if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
167
+ if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext)))
208
168
  return result;
209
- }
210
169
  throw new ReactDocgenResolveError(filename);
211
170
  });
212
171
  }
213
- __name(getReactDocgenImporter, "getReactDocgenImporter");
214
172
  export {
215
173
  getReactDocgenImporter,
216
174
  reactDocgen
@@ -1,23 +1,19 @@
1
- import CJS_COMPAT_NODE_URL_he8fw7segub from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_he8fw7segub from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_he8fw7segub from "node:module";
1
+ import CJS_COMPAT_NODE_URL_6x0q2yvwyyv from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_6x0q2yvwyyv from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_6x0q2yvwyyv from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_he8fw7segub.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_he8fw7segub.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_he8fw7segub.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_6x0q2yvwyyv.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_6x0q2yvwyyv.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_6x0q2yvwyyv.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-VKCDFKJV.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_he8fw7segub from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_he8fw7segub from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_he8fw7segub from "node:module";
1
+ import CJS_COMPAT_NODE_URL_6x0q2yvwyyv from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_6x0q2yvwyyv from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_6x0q2yvwyyv from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_he8fw7segub.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_he8fw7segub.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_he8fw7segub.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_6x0q2yvwyyv.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_6x0q2yvwyyv.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_6x0q2yvwyyv.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-VKCDFKJV.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-Z2XGKNB3.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-BDT2FE6V.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.1",
3
+ "version": "10.1.0-alpha.11",
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.1",
59
- "@storybook/react": "10.1.0-alpha.1",
58
+ "@storybook/builder-vite": "10.1.0-alpha.11",
59
+ "@storybook/react": "10.1.0-alpha.11",
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.1",
74
+ "storybook": "^10.1.0-alpha.11",
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_he8fw7segub from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_he8fw7segub from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_he8fw7segub from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_he8fw7segub.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_he8fw7segub.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_he8fw7segub.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
- };