storybook-react-rsbuild 2.1.6 → 3.0.0-beta.1

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,56 +1,40 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ import CJS_COMPAT_NODE_URL_456fc18c5bc9e809 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_456fc18c5bc9e809 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809 from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_456fc18c5bc9e809.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_456fc18c5bc9e809.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import "../_node-chunks/chunk-736S2ISL.js";
29
13
 
30
14
  // src/loaders/react-docgen-loader.ts
31
- var react_docgen_loader_exports = {};
32
- __export(react_docgen_loader_exports, {
33
- default: () => reactDocgenLoader,
34
- getReactDocgenImporter: () => getReactDocgenImporter
35
- });
36
- module.exports = __toCommonJS(react_docgen_loader_exports);
37
- var import_find_up = __toESM(require("find-up"));
38
- var import_magic_string = __toESM(require("magic-string"));
39
- var import_react_docgen = require("react-docgen");
40
- var import_node_logger = require("storybook/internal/node-logger");
41
- var TsconfigPaths = __toESM(require("tsconfig-paths"));
15
+ import findUp from "find-up";
16
+ import MagicString from "magic-string";
17
+ import {
18
+ ERROR_CODES,
19
+ builtinHandlers as docgenHandlers,
20
+ builtinResolvers as docgenResolver,
21
+ makeFsImporter,
22
+ parse,
23
+ utils
24
+ } from "react-docgen";
25
+ import { logger } from "storybook/internal/node-logger";
26
+ import * as TsconfigPaths from "tsconfig-paths";
42
27
 
43
28
  // src/loaders/docgen-resolver.ts
44
- var import_node_path = require("path");
45
- var import_resolve = __toESM(require("resolve"));
29
+ import { extname } from "node:path";
30
+ import resolve from "resolve";
46
31
  var ReactDocgenResolveError = class extends Error {
47
32
  constructor(filename) {
48
33
  super(`'${filename}' was ignored by react-docgen.`);
49
34
  // the magic string that react-docgen uses to check if a module is ignored
50
35
  this.code = "MODULE_NOT_FOUND";
51
36
  }
52
- };
53
- var RESOLVE_EXTENSIONS = [
37
+ }, RESOLVE_EXTENSIONS = [
54
38
  ".js",
55
39
  ".cts",
56
40
  // These were originally not in the code, I added them
@@ -69,17 +53,16 @@ var RESOLVE_EXTENSIONS = [
69
53
  ".jsx"
70
54
  ];
71
55
  function defaultLookupModule(filename, basedir) {
72
- const resolveOptions = {
56
+ let resolveOptions = {
73
57
  basedir,
74
58
  extensions: RESOLVE_EXTENSIONS,
75
59
  // we do not need to check core modules as we cannot import them anyway
76
- includeCoreModules: false
60
+ includeCoreModules: !1
77
61
  };
78
62
  try {
79
- return import_resolve.default.sync(filename, resolveOptions);
63
+ return resolve.sync(filename, resolveOptions);
80
64
  } catch (error) {
81
- const ext = (0, import_node_path.extname)(filename);
82
- let newFilename;
65
+ let ext = extname(filename), newFilename;
83
66
  switch (ext) {
84
67
  case ".js":
85
68
  case ".mjs":
@@ -92,7 +75,7 @@ function defaultLookupModule(filename, basedir) {
92
75
  default:
93
76
  throw error;
94
77
  }
95
- return import_resolve.default.sync(newFilename, {
78
+ return resolve.sync(newFilename, {
96
79
  ...resolveOptions,
97
80
  // we already know that there is an extension at this point, so no need to check other extensions
98
81
  extensions: []
@@ -101,17 +84,15 @@ function defaultLookupModule(filename, basedir) {
101
84
  }
102
85
 
103
86
  // src/loaders/react-docgen-loader.ts
104
- var { getNameOrValue, isReactForwardRefCall } = import_react_docgen.utils;
105
- var actualNameHandler = function actualNameHandler2(documentation, componentDefinition) {
106
- documentation.set("definedInFile", componentDefinition.hub.file.opts.filename);
107
- if ((componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id")) {
87
+ var { getNameOrValue, isReactForwardRefCall } = utils, actualNameHandler = function(documentation, componentDefinition) {
88
+ if (documentation.set("definedInFile", componentDefinition.hub.file.opts.filename), (componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id"))
108
89
  documentation.set(
109
90
  "actualName",
110
91
  getNameOrValue(componentDefinition.get("id"))
111
92
  );
112
- } else if (componentDefinition.isArrowFunctionExpression() || componentDefinition.isFunctionExpression() || isReactForwardRefCall(componentDefinition)) {
93
+ else if (componentDefinition.isArrowFunctionExpression() || componentDefinition.isFunctionExpression() || isReactForwardRefCall(componentDefinition)) {
113
94
  let currentPath = componentDefinition;
114
- while (currentPath.parentPath) {
95
+ for (; currentPath.parentPath; ) {
115
96
  if (currentPath.parentPath.isVariableDeclarator()) {
116
97
  documentation.set(
117
98
  "actualName",
@@ -120,7 +101,7 @@ var actualNameHandler = function actualNameHandler2(documentation, componentDefi
120
101
  return;
121
102
  }
122
103
  if (currentPath.parentPath.isAssignmentExpression()) {
123
- const leftPath = currentPath.parentPath.get("left");
104
+ let leftPath = currentPath.parentPath.get("left");
124
105
  if (leftPath.isIdentifier() || leftPath.isLiteral()) {
125
106
  documentation.set("actualName", getNameOrValue(leftPath));
126
107
  return;
@@ -130,57 +111,38 @@ var actualNameHandler = function actualNameHandler2(documentation, componentDefi
130
111
  }
131
112
  documentation.set("actualName", "");
132
113
  }
133
- };
134
- var defaultHandlers = Object.values(import_react_docgen.builtinHandlers).map((handler) => handler);
135
- var defaultResolver = new import_react_docgen.builtinResolvers.FindExportedDefinitionsResolver();
136
- var handlers = [...defaultHandlers, actualNameHandler];
137
- var tsconfigPathsInitializeStatus = "uninitialized";
138
- var resolveTsconfigPathsInitialingPromise;
139
- var tsconfigPathsInitialingPromise = new Promise((resolve2) => {
114
+ }, defaultHandlers = Object.values(docgenHandlers).map((handler) => handler), defaultResolver = new docgenResolver.FindExportedDefinitionsResolver(), handlers = [...defaultHandlers, actualNameHandler], tsconfigPathsInitializeStatus = "uninitialized", resolveTsconfigPathsInitialingPromise, tsconfigPathsInitialingPromise = new Promise((resolve2) => {
140
115
  resolveTsconfigPathsInitialingPromise = resolve2;
141
- });
142
- var finishInitialization = () => {
143
- resolveTsconfigPathsInitialingPromise();
144
- tsconfigPathsInitializeStatus = "initialized";
145
- };
146
- var matchPath;
116
+ }), finishInitialization = () => {
117
+ resolveTsconfigPathsInitialingPromise(), tsconfigPathsInitializeStatus = "initialized";
118
+ }, matchPath;
147
119
  async function reactDocgenLoader(source, map) {
148
- const callback = this.async();
149
- const options = this.getOptions() || {};
150
- const { debug = false } = options;
120
+ let callback = this.async(), options = this.getOptions() || {}, { debug = !1 } = options;
151
121
  if (tsconfigPathsInitializeStatus === "uninitialized") {
152
122
  tsconfigPathsInitializeStatus = "initializing";
153
- const tsconfigPath = await (0, import_find_up.default)("tsconfig.json", { cwd: process.cwd() });
154
- const tsconfig = TsconfigPaths.loadConfig(tsconfigPath);
155
- if (tsconfig.resultType === "success") {
156
- import_node_logger.logger.info("Using tsconfig paths for react-docgen");
157
- matchPath = TsconfigPaths.createMatchPath(
158
- tsconfig.absoluteBaseUrl,
159
- tsconfig.paths,
160
- ["browser", "module", "main"]
161
- );
162
- }
163
- finishInitialization();
164
- }
165
- if (tsconfigPathsInitializeStatus === "initializing") {
166
- await tsconfigPathsInitialingPromise;
123
+ let tsconfigPath = await findUp("tsconfig.json", { cwd: process.cwd() }), tsconfig = TsconfigPaths.loadConfig(tsconfigPath);
124
+ tsconfig.resultType === "success" && (logger.info("Using tsconfig paths for react-docgen"), matchPath = TsconfigPaths.createMatchPath(
125
+ tsconfig.absoluteBaseUrl,
126
+ tsconfig.paths,
127
+ ["browser", "module", "main"]
128
+ )), finishInitialization();
167
129
  }
130
+ tsconfigPathsInitializeStatus === "initializing" && await tsconfigPathsInitialingPromise;
168
131
  try {
169
- const docgenResults = (0, import_react_docgen.parse)(source, {
132
+ let docgenResults = parse(source, {
170
133
  filename: this.resourcePath,
171
134
  resolver: defaultResolver,
172
135
  handlers,
173
136
  importer: getReactDocgenImporter(matchPath),
174
137
  babelOptions: {
175
- babelrc: false,
176
- configFile: false
138
+ babelrc: !1,
139
+ configFile: !1
177
140
  }
178
- });
179
- const magicString = new import_magic_string.default(source);
180
- for (const info of docgenResults) {
181
- const { actualName, definedInFile, ...docgenInfo } = info;
141
+ }), magicString = new MagicString(source);
142
+ for (let info of docgenResults) {
143
+ let { actualName, definedInFile, ...docgenInfo } = info;
182
144
  if (actualName && definedInFile === this.resourcePath) {
183
- const docNode = JSON.stringify(docgenInfo);
145
+ let docNode = JSON.stringify(docgenInfo);
184
146
  magicString.append(`;${actualName}.__docgenInfo=${docNode}`);
185
147
  }
186
148
  }
@@ -188,46 +150,28 @@ async function reactDocgenLoader(source, map) {
188
150
  null,
189
151
  magicString.toString(),
190
152
  map ?? magicString.generateMap({
191
- hires: true,
153
+ hires: !0,
192
154
  source: this.resourcePath,
193
- includeContent: true
155
+ includeContent: !0
194
156
  })
195
157
  );
196
158
  } catch (error) {
197
- if (error.code === import_react_docgen.ERROR_CODES.MISSING_DEFINITION) {
198
- callback(null, source);
199
- } else {
200
- if (!debug) {
201
- import_node_logger.logger.warn(
202
- `Failed to parse ${this.resourcePath} with react-docgen. Rerun Storybook with --loglevel=debug to get more info.`
203
- );
204
- } else {
205
- import_node_logger.logger.warn(
206
- `Failed to parse ${this.resourcePath} with react-docgen. Please use the below error message and the content of the file which causes the error to report the issue to the maintainers of react-docgen. https://github.com/reactjs/react-docgen`
207
- );
208
- import_node_logger.logger.error(error);
209
- }
210
- callback(null, source);
211
- }
159
+ error.code === ERROR_CODES.MISSING_DEFINITION || (debug ? (logger.warn(
160
+ `Failed to parse ${this.resourcePath} with react-docgen. Please use the below error message and the content of the file which causes the error to report the issue to the maintainers of react-docgen. https://github.com/reactjs/react-docgen`
161
+ ), logger.error(error)) : logger.warn(
162
+ `Failed to parse ${this.resourcePath} with react-docgen. Rerun Storybook with --loglevel=debug to get more info.`
163
+ )), callback(null, source);
212
164
  }
213
165
  }
214
166
  function getReactDocgenImporter(matchingPath) {
215
- return (0, import_react_docgen.makeFsImporter)((filename, basedir) => {
216
- const mappedFilenameByPaths = (() => {
217
- if (matchingPath) {
218
- const match = matchingPath(filename);
219
- return match || filename;
220
- }
221
- return filename;
222
- })();
223
- const result = defaultLookupModule(mappedFilenameByPaths, basedir);
224
- if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
167
+ return makeFsImporter((filename, basedir) => {
168
+ let mappedFilenameByPaths = matchingPath && matchingPath(filename) || filename, result = defaultLookupModule(mappedFilenameByPaths, basedir);
169
+ if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext)))
225
170
  return result;
226
- }
227
171
  throw new ReactDocgenResolveError(filename);
228
172
  });
229
173
  }
230
- // Annotate the CommonJS export names for ESM import in node:
231
- 0 && (module.exports = {
174
+ export {
175
+ reactDocgenLoader as default,
232
176
  getReactDocgenImporter
233
- });
177
+ };
@@ -1,9 +1,3 @@
1
- import { StorybookConfig } from '../index.js';
2
- import '@storybook/react';
3
- import '@storybook/react-docgen-typescript-plugin';
4
- import 'storybook-builder-rsbuild';
5
- import 'storybook/internal/types';
6
-
7
- declare function defineMain(config: StorybookConfig): StorybookConfig;
8
-
9
- export { defineMain };
1
+ // auto generated file from file:///Users/bytedance/Projects/storybook-rsbuild/scripts/build/utils/generate-type-mappers.ts, do not edit
2
+ export * from '../../src/node/index.ts';
3
+ export type * from '../../src/node/index.ts';
@@ -1,32 +1,20 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ import CJS_COMPAT_NODE_URL_456fc18c5bc9e809 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_456fc18c5bc9e809 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809 from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_456fc18c5bc9e809.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_456fc18c5bc9e809.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import "../_node-chunks/chunk-736S2ISL.js";
19
13
 
20
14
  // src/node/index.ts
21
- var node_exports = {};
22
- __export(node_exports, {
23
- defineMain: () => defineMain
24
- });
25
- module.exports = __toCommonJS(node_exports);
26
15
  function defineMain(config) {
27
16
  return config;
28
17
  }
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
18
+ export {
31
19
  defineMain
32
- });
20
+ };