storybook-react-rsbuild 0.0.9 → 0.0.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.
- package/dist/preset.js +237 -10
- package/package.json +5 -4
package/dist/preset.js
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __create = Object.create;
|
2
3
|
var __defProp = Object.defineProperty;
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __esm = (fn, res) => function __init() {
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
10
|
+
};
|
6
11
|
var __export = (target, all) => {
|
7
12
|
for (var name in all)
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -15,8 +20,225 @@ var __copyProps = (to, from, except, desc) => {
|
|
15
20
|
}
|
16
21
|
return to;
|
17
22
|
};
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
29
|
+
mod
|
30
|
+
));
|
18
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
32
|
|
33
|
+
// src/plugins/docgen-handlers/actualNameHandler.ts
|
34
|
+
var import_react_docgen, getNameOrValue, isReactForwardRefCall, actualNameHandler, actualNameHandler_default;
|
35
|
+
var init_actualNameHandler = __esm({
|
36
|
+
"src/plugins/docgen-handlers/actualNameHandler.ts"() {
|
37
|
+
"use strict";
|
38
|
+
import_react_docgen = require("react-docgen");
|
39
|
+
({ getNameOrValue, isReactForwardRefCall } = import_react_docgen.utils);
|
40
|
+
actualNameHandler = function actualNameHandler2(documentation, componentDefinition) {
|
41
|
+
documentation.set("definedInFile", componentDefinition.hub.file.opts.filename);
|
42
|
+
if ((componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id")) {
|
43
|
+
documentation.set(
|
44
|
+
"actualName",
|
45
|
+
getNameOrValue(componentDefinition.get("id"))
|
46
|
+
);
|
47
|
+
} else if (componentDefinition.isArrowFunctionExpression() || componentDefinition.isFunctionExpression() || isReactForwardRefCall(componentDefinition)) {
|
48
|
+
let currentPath = componentDefinition;
|
49
|
+
while (currentPath.parentPath) {
|
50
|
+
if (currentPath.parentPath.isVariableDeclarator()) {
|
51
|
+
documentation.set(
|
52
|
+
"actualName",
|
53
|
+
getNameOrValue(currentPath.parentPath.get("id"))
|
54
|
+
);
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
if (currentPath.parentPath.isAssignmentExpression()) {
|
58
|
+
const leftPath = currentPath.parentPath.get("left");
|
59
|
+
if (leftPath.isIdentifier() || leftPath.isLiteral()) {
|
60
|
+
documentation.set("actualName", getNameOrValue(leftPath));
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
currentPath = currentPath.parentPath;
|
65
|
+
}
|
66
|
+
documentation.set("actualName", "");
|
67
|
+
}
|
68
|
+
};
|
69
|
+
actualNameHandler_default = actualNameHandler;
|
70
|
+
}
|
71
|
+
});
|
72
|
+
|
73
|
+
// src/plugins/docgen-resolver.ts
|
74
|
+
function defaultLookupModule(filename, basedir) {
|
75
|
+
const resolveOptions = {
|
76
|
+
basedir,
|
77
|
+
extensions: RESOLVE_EXTENSIONS,
|
78
|
+
// we do not need to check core modules as we cannot import them anyway
|
79
|
+
includeCoreModules: false
|
80
|
+
};
|
81
|
+
try {
|
82
|
+
return import_resolve.default.sync(filename, resolveOptions);
|
83
|
+
} catch (error) {
|
84
|
+
const ext = (0, import_node_path.extname)(filename);
|
85
|
+
let newFilename;
|
86
|
+
switch (ext) {
|
87
|
+
case ".js":
|
88
|
+
case ".mjs":
|
89
|
+
case ".cjs":
|
90
|
+
newFilename = `${filename.slice(0, -2)}ts`;
|
91
|
+
break;
|
92
|
+
case ".jsx":
|
93
|
+
newFilename = `${filename.slice(0, -3)}tsx`;
|
94
|
+
break;
|
95
|
+
default:
|
96
|
+
throw error;
|
97
|
+
}
|
98
|
+
return import_resolve.default.sync(newFilename, {
|
99
|
+
...resolveOptions,
|
100
|
+
// we already know that there is an extension at this point, so no need to check other extensions
|
101
|
+
extensions: []
|
102
|
+
});
|
103
|
+
}
|
104
|
+
}
|
105
|
+
var import_node_path, import_resolve, ReactDocgenResolveError, RESOLVE_EXTENSIONS;
|
106
|
+
var init_docgen_resolver = __esm({
|
107
|
+
"src/plugins/docgen-resolver.ts"() {
|
108
|
+
"use strict";
|
109
|
+
import_node_path = require("path");
|
110
|
+
import_resolve = __toESM(require("resolve"));
|
111
|
+
ReactDocgenResolveError = class extends Error {
|
112
|
+
constructor(filename) {
|
113
|
+
super(`'${filename}' was ignored by react-docgen.`);
|
114
|
+
// the magic string that react-docgen uses to check if a module is ignored
|
115
|
+
this.code = "MODULE_NOT_FOUND";
|
116
|
+
}
|
117
|
+
};
|
118
|
+
RESOLVE_EXTENSIONS = [
|
119
|
+
".js",
|
120
|
+
".cts",
|
121
|
+
// These were originally not in the code, I added them
|
122
|
+
".mts",
|
123
|
+
// These were originally not in the code, I added them
|
124
|
+
".ctsx",
|
125
|
+
// These were originally not in the code, I added them
|
126
|
+
".mtsx",
|
127
|
+
// These were originally not in the code, I added them
|
128
|
+
".ts",
|
129
|
+
".tsx",
|
130
|
+
".mjs",
|
131
|
+
".cjs",
|
132
|
+
".mts",
|
133
|
+
".cts",
|
134
|
+
".jsx"
|
135
|
+
];
|
136
|
+
}
|
137
|
+
});
|
138
|
+
|
139
|
+
// src/plugins/react-docgen.ts
|
140
|
+
var react_docgen_exports = {};
|
141
|
+
__export(react_docgen_exports, {
|
142
|
+
getReactDocgenImporter: () => getReactDocgenImporter,
|
143
|
+
reactDocgen: () => reactDocgen
|
144
|
+
});
|
145
|
+
async function reactDocgen({
|
146
|
+
include = /\.(mjs|tsx?|jsx?)$/,
|
147
|
+
exclude = [/node_modules\/.*/]
|
148
|
+
} = {}) {
|
149
|
+
const cwd = process.cwd();
|
150
|
+
const filter = (0, import_pluginutils.createFilter)(include, exclude);
|
151
|
+
const tsconfigPath = await (0, import_find_up.default)("tsconfig.json", { cwd });
|
152
|
+
const tsconfig = TsconfigPaths.loadConfig(tsconfigPath);
|
153
|
+
let matchPath;
|
154
|
+
if (tsconfig.resultType === "success") {
|
155
|
+
import_node_logger.logger.info("Using tsconfig paths for react-docgen");
|
156
|
+
matchPath = TsconfigPaths.createMatchPath(
|
157
|
+
tsconfig.absoluteBaseUrl,
|
158
|
+
tsconfig.paths,
|
159
|
+
["browser", "module", "main"]
|
160
|
+
);
|
161
|
+
}
|
162
|
+
return {
|
163
|
+
name: "storybook:react-docgen-plugin",
|
164
|
+
// enforce: 'pre',
|
165
|
+
setup(api) {
|
166
|
+
api.transform(
|
167
|
+
{
|
168
|
+
test: (id) => {
|
169
|
+
if (!filter(import_node_path2.default.relative(cwd, id))) {
|
170
|
+
return false;
|
171
|
+
}
|
172
|
+
return true;
|
173
|
+
}
|
174
|
+
},
|
175
|
+
async ({ code: src, resource: id }) => {
|
176
|
+
try {
|
177
|
+
const docgenResults = (0, import_react_docgen2.parse)(src, {
|
178
|
+
resolver: defaultResolver,
|
179
|
+
handlers,
|
180
|
+
importer: getReactDocgenImporter(matchPath),
|
181
|
+
filename: id
|
182
|
+
});
|
183
|
+
const s = new import_magic_string.default(src);
|
184
|
+
docgenResults.forEach((info) => {
|
185
|
+
const { actualName, definedInFile, ...docgenInfo } = info;
|
186
|
+
if (actualName && definedInFile == id) {
|
187
|
+
const docNode = JSON.stringify(docgenInfo);
|
188
|
+
s.append(`;${actualName}.__docgenInfo=${docNode}`);
|
189
|
+
}
|
190
|
+
});
|
191
|
+
return {
|
192
|
+
code: s.toString(),
|
193
|
+
map: s.generateMap({ hires: true, source: id }).toString()
|
194
|
+
};
|
195
|
+
} catch (e) {
|
196
|
+
if (e.code === import_react_docgen2.ERROR_CODES.MISSING_DEFINITION) {
|
197
|
+
return src;
|
198
|
+
}
|
199
|
+
throw e;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
);
|
203
|
+
}
|
204
|
+
};
|
205
|
+
}
|
206
|
+
function getReactDocgenImporter(matchPath) {
|
207
|
+
return (0, import_react_docgen2.makeFsImporter)((filename, basedir) => {
|
208
|
+
const mappedFilenameByPaths = (() => {
|
209
|
+
if (matchPath) {
|
210
|
+
const match = matchPath(filename);
|
211
|
+
return match || filename;
|
212
|
+
} else {
|
213
|
+
return filename;
|
214
|
+
}
|
215
|
+
})();
|
216
|
+
const result = defaultLookupModule(mappedFilenameByPaths, basedir);
|
217
|
+
if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
|
218
|
+
return result;
|
219
|
+
}
|
220
|
+
throw new ReactDocgenResolveError(filename);
|
221
|
+
});
|
222
|
+
}
|
223
|
+
var import_node_path2, import_pluginutils, import_find_up, import_magic_string, import_react_docgen2, import_node_logger, TsconfigPaths, defaultHandlers, defaultResolver, handlers;
|
224
|
+
var init_react_docgen = __esm({
|
225
|
+
"src/plugins/react-docgen.ts"() {
|
226
|
+
"use strict";
|
227
|
+
import_node_path2 = __toESM(require("path"));
|
228
|
+
import_pluginutils = require("@rollup/pluginutils");
|
229
|
+
import_find_up = __toESM(require("find-up"));
|
230
|
+
import_magic_string = __toESM(require("magic-string"));
|
231
|
+
import_react_docgen2 = require("react-docgen");
|
232
|
+
import_node_logger = require("storybook/internal/node-logger");
|
233
|
+
TsconfigPaths = __toESM(require("tsconfig-paths"));
|
234
|
+
init_actualNameHandler();
|
235
|
+
init_docgen_resolver();
|
236
|
+
defaultHandlers = Object.values(import_react_docgen2.builtinHandlers).map((handler) => handler);
|
237
|
+
defaultResolver = new import_react_docgen2.builtinResolvers.FindExportedDefinitionsResolver();
|
238
|
+
handlers = [...defaultHandlers, actualNameHandler_default];
|
239
|
+
}
|
240
|
+
});
|
241
|
+
|
20
242
|
// src/preset.ts
|
21
243
|
var preset_exports = {};
|
22
244
|
__export(preset_exports, {
|
@@ -24,15 +246,15 @@ __export(preset_exports, {
|
|
24
246
|
rsbuildFinal: () => rsbuildFinal
|
25
247
|
});
|
26
248
|
module.exports = __toCommonJS(preset_exports);
|
27
|
-
var
|
249
|
+
var import_node_path3 = require("path");
|
28
250
|
|
29
251
|
// src/react-docs.ts
|
30
252
|
var import_core = require("@rsbuild/core");
|
31
253
|
var import_docs_tools = require("storybook/internal/docs-tools");
|
32
254
|
|
33
255
|
// src/requirer.ts
|
34
|
-
function requirer(resolver,
|
35
|
-
return resolver(
|
256
|
+
function requirer(resolver, path2) {
|
257
|
+
return resolver(path2);
|
36
258
|
}
|
37
259
|
|
38
260
|
// src/react-docs.ts
|
@@ -41,11 +263,11 @@ var rsbuildFinalDocs = async (config, options) => {
|
|
41
263
|
return config;
|
42
264
|
const typescriptOptions = await options.presets.apply("typescript", {});
|
43
265
|
const debug = options.loglevel === "debug";
|
44
|
-
const { reactDocgen } = typescriptOptions || {};
|
45
|
-
if (typeof
|
266
|
+
const { reactDocgen: reactDocgen2 } = typescriptOptions || {};
|
267
|
+
if (typeof reactDocgen2 !== "string") {
|
46
268
|
return config;
|
47
269
|
}
|
48
|
-
if (
|
270
|
+
if (reactDocgen2 !== "react-docgen-typescript") {
|
49
271
|
return (0, import_core.mergeRsbuildConfig)(config, {
|
50
272
|
tools: {
|
51
273
|
rspack: {
|
@@ -69,13 +291,18 @@ var rsbuildFinalDocs = async (config, options) => {
|
|
69
291
|
}
|
70
292
|
});
|
71
293
|
}
|
72
|
-
|
73
|
-
|
74
|
-
|
294
|
+
const { reactDocgen: reactDocGenPlugin } = await Promise.resolve().then(() => (init_react_docgen(), react_docgen_exports));
|
295
|
+
return (0, import_core.mergeRsbuildConfig)(config, {
|
296
|
+
plugins: [
|
297
|
+
await reactDocGenPlugin({
|
298
|
+
include: reactDocgen2 === "react-docgen-typescript" ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/
|
299
|
+
})
|
300
|
+
]
|
301
|
+
});
|
75
302
|
};
|
76
303
|
|
77
304
|
// src/preset.ts
|
78
|
-
var getAbsolutePath = (input) => (0,
|
305
|
+
var getAbsolutePath = (input) => (0, import_node_path3.dirname)(require.resolve((0, import_node_path3.join)(input, "package.json")));
|
79
306
|
var rsbuildFinal = async (config, options) => {
|
80
307
|
const finalConfig = rsbuildFinalDocs(config, options);
|
81
308
|
return finalConfig;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "storybook-react-rsbuild",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.11",
|
4
4
|
"description": "Storybook for React and Rsbuild: Develop React components in isolation with Hot Reloading.",
|
5
5
|
"keywords": [
|
6
6
|
"storybook",
|
@@ -49,6 +49,7 @@
|
|
49
49
|
"!src/**/*"
|
50
50
|
],
|
51
51
|
"dependencies": {
|
52
|
+
"@rollup/pluginutils": "^5.1.0",
|
52
53
|
"@storybook/react": "^8.2.1",
|
53
54
|
"@storybook/react-docgen-typescript-plugin": "^1.0.1",
|
54
55
|
"@types/node": "^18.0.0",
|
@@ -57,10 +58,10 @@
|
|
57
58
|
"react-docgen": "^7.0.3",
|
58
59
|
"resolve": "^1.22.8",
|
59
60
|
"tsconfig-paths": "^4.2.0",
|
60
|
-
"storybook-builder-rsbuild": "0.0.
|
61
|
+
"storybook-builder-rsbuild": "0.0.11"
|
61
62
|
},
|
62
63
|
"devDependencies": {
|
63
|
-
"@rsbuild/core": "1.0.1-beta.
|
64
|
+
"@rsbuild/core": "1.0.1-beta.10",
|
64
65
|
"@storybook/types": "^8.2.1",
|
65
66
|
"@types/resolve": "^1.20.6",
|
66
67
|
"add": "^2.0.6",
|
@@ -68,7 +69,7 @@
|
|
68
69
|
"typescript": "^5.3.2"
|
69
70
|
},
|
70
71
|
"peerDependencies": {
|
71
|
-
"@rsbuild/core": ">= 1.0.0-alpha.9",
|
72
|
+
"@rsbuild/core": ">= 1.0.0-alpha.9 || >= 1.0.1-beta || 1.x",
|
72
73
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
|
73
74
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
|
74
75
|
"storybook": "^8.2.1",
|