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

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,195 +0,0 @@
1
- import findUp from 'find-up';
2
- import MagicString from 'magic-string';
3
- import { builtinHandlers, builtinResolvers, parse, ERROR_CODES, makeFsImporter, utils } from 'react-docgen';
4
- import { logger } from 'storybook/internal/node-logger';
5
- import * as TsconfigPaths from 'tsconfig-paths';
6
- import { extname } from 'path';
7
- import resolve from 'resolve';
8
-
9
- // src/loaders/react-docgen-loader.ts
10
- var ReactDocgenResolveError = class extends Error {
11
- constructor(filename) {
12
- super(`'${filename}' was ignored by react-docgen.`);
13
- // the magic string that react-docgen uses to check if a module is ignored
14
- this.code = "MODULE_NOT_FOUND";
15
- }
16
- };
17
- var RESOLVE_EXTENSIONS = [
18
- ".js",
19
- ".cts",
20
- // These were originally not in the code, I added them
21
- ".mts",
22
- // These were originally not in the code, I added them
23
- ".ctsx",
24
- // These were originally not in the code, I added them
25
- ".mtsx",
26
- // These were originally not in the code, I added them
27
- ".ts",
28
- ".tsx",
29
- ".mjs",
30
- ".cjs",
31
- ".mts",
32
- ".cts",
33
- ".jsx"
34
- ];
35
- function defaultLookupModule(filename, basedir) {
36
- const resolveOptions = {
37
- basedir,
38
- extensions: RESOLVE_EXTENSIONS,
39
- // we do not need to check core modules as we cannot import them anyway
40
- includeCoreModules: false
41
- };
42
- try {
43
- return resolve.sync(filename, resolveOptions);
44
- } catch (error) {
45
- const ext = extname(filename);
46
- let newFilename;
47
- switch (ext) {
48
- case ".js":
49
- case ".mjs":
50
- case ".cjs":
51
- newFilename = `${filename.slice(0, -2)}ts`;
52
- break;
53
- case ".jsx":
54
- newFilename = `${filename.slice(0, -3)}tsx`;
55
- break;
56
- default:
57
- throw error;
58
- }
59
- return resolve.sync(newFilename, {
60
- ...resolveOptions,
61
- // we already know that there is an extension at this point, so no need to check other extensions
62
- extensions: []
63
- });
64
- }
65
- }
66
-
67
- // src/loaders/react-docgen-loader.ts
68
- var { getNameOrValue, isReactForwardRefCall } = utils;
69
- var actualNameHandler = function actualNameHandler2(documentation, componentDefinition) {
70
- documentation.set("definedInFile", componentDefinition.hub.file.opts.filename);
71
- if ((componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id")) {
72
- documentation.set(
73
- "actualName",
74
- getNameOrValue(componentDefinition.get("id"))
75
- );
76
- } else if (componentDefinition.isArrowFunctionExpression() || componentDefinition.isFunctionExpression() || isReactForwardRefCall(componentDefinition)) {
77
- let currentPath = componentDefinition;
78
- while (currentPath.parentPath) {
79
- if (currentPath.parentPath.isVariableDeclarator()) {
80
- documentation.set(
81
- "actualName",
82
- getNameOrValue(currentPath.parentPath.get("id"))
83
- );
84
- return;
85
- }
86
- if (currentPath.parentPath.isAssignmentExpression()) {
87
- const leftPath = currentPath.parentPath.get("left");
88
- if (leftPath.isIdentifier() || leftPath.isLiteral()) {
89
- documentation.set("actualName", getNameOrValue(leftPath));
90
- return;
91
- }
92
- }
93
- currentPath = currentPath.parentPath;
94
- }
95
- documentation.set("actualName", "");
96
- }
97
- };
98
- var defaultHandlers = Object.values(builtinHandlers).map((handler) => handler);
99
- var defaultResolver = new builtinResolvers.FindExportedDefinitionsResolver();
100
- var handlers = [...defaultHandlers, actualNameHandler];
101
- var tsconfigPathsInitializeStatus = "uninitialized";
102
- var resolveTsconfigPathsInitialingPromise;
103
- var tsconfigPathsInitialingPromise = new Promise((resolve2) => {
104
- resolveTsconfigPathsInitialingPromise = resolve2;
105
- });
106
- var finishInitialization = () => {
107
- resolveTsconfigPathsInitialingPromise();
108
- tsconfigPathsInitializeStatus = "initialized";
109
- };
110
- var matchPath;
111
- async function reactDocgenLoader(source, map) {
112
- const callback = this.async();
113
- const options = this.getOptions() || {};
114
- const { debug = false } = options;
115
- if (tsconfigPathsInitializeStatus === "uninitialized") {
116
- tsconfigPathsInitializeStatus = "initializing";
117
- const tsconfigPath = await findUp("tsconfig.json", { cwd: process.cwd() });
118
- const tsconfig = TsconfigPaths.loadConfig(tsconfigPath);
119
- if (tsconfig.resultType === "success") {
120
- logger.info("Using tsconfig paths for react-docgen");
121
- matchPath = TsconfigPaths.createMatchPath(
122
- tsconfig.absoluteBaseUrl,
123
- tsconfig.paths,
124
- ["browser", "module", "main"]
125
- );
126
- }
127
- finishInitialization();
128
- }
129
- if (tsconfigPathsInitializeStatus === "initializing") {
130
- await tsconfigPathsInitialingPromise;
131
- }
132
- try {
133
- const docgenResults = parse(source, {
134
- filename: this.resourcePath,
135
- resolver: defaultResolver,
136
- handlers,
137
- importer: getReactDocgenImporter(matchPath),
138
- babelOptions: {
139
- babelrc: false,
140
- configFile: false
141
- }
142
- });
143
- const magicString = new MagicString(source);
144
- for (const info of docgenResults) {
145
- const { actualName, definedInFile, ...docgenInfo } = info;
146
- if (actualName && definedInFile === this.resourcePath) {
147
- const docNode = JSON.stringify(docgenInfo);
148
- magicString.append(`;${actualName}.__docgenInfo=${docNode}`);
149
- }
150
- }
151
- callback(
152
- null,
153
- magicString.toString(),
154
- map ?? magicString.generateMap({
155
- hires: true,
156
- source: this.resourcePath,
157
- includeContent: true
158
- })
159
- );
160
- } catch (error) {
161
- if (error.code === ERROR_CODES.MISSING_DEFINITION) {
162
- callback(null, source);
163
- } else {
164
- if (!debug) {
165
- logger.warn(
166
- `Failed to parse ${this.resourcePath} with react-docgen. Rerun Storybook with --loglevel=debug to get more info.`
167
- );
168
- } else {
169
- logger.warn(
170
- `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`
171
- );
172
- logger.error(error);
173
- }
174
- callback(null, source);
175
- }
176
- }
177
- }
178
- function getReactDocgenImporter(matchingPath) {
179
- return makeFsImporter((filename, basedir) => {
180
- const mappedFilenameByPaths = (() => {
181
- if (matchingPath) {
182
- const match = matchingPath(filename);
183
- return match || filename;
184
- }
185
- return filename;
186
- })();
187
- const result = defaultLookupModule(mappedFilenameByPaths, basedir);
188
- if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
189
- return result;
190
- }
191
- throw new ReactDocgenResolveError(filename);
192
- });
193
- }
194
-
195
- export { reactDocgenLoader as default, getReactDocgenImporter };
@@ -1,6 +0,0 @@
1
- // src/node/index.ts
2
- function defineMain(config) {
3
- return config;
4
- }
5
-
6
- export { defineMain };
package/dist/preset.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { PresetProperty } from 'storybook/internal/types';
2
- import { StorybookConfig } from './index.js';
3
- import '@storybook/react';
4
- import '@storybook/react-docgen-typescript-plugin';
5
- import 'storybook-builder-rsbuild';
6
-
7
- declare const rsbuildFinal: StorybookConfig['rsbuildFinal'];
8
- declare const core: PresetProperty<'core'>;
9
-
10
- export { core, rsbuildFinal };