storybook-react-rsbuild 0.1.8 → 0.1.9

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.
Files changed (2) hide show
  1. package/dist/preset.js +361 -191
  2. package/package.json +4 -2
package/dist/preset.js CHANGED
@@ -30,209 +30,368 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
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"() {
33
+ // src/plugins/react-docgen-typescript/utils/filter.ts
34
+ var defaultPropFilter;
35
+ var init_filter = __esm({
36
+ "src/plugins/react-docgen-typescript/utils/filter.ts"() {
37
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
- }
38
+ defaultPropFilter = (prop) => {
39
+ return !prop.parent?.fileName.includes("node_modules");
68
40
  };
69
- actualNameHandler_default = actualNameHandler;
70
41
  }
71
42
  });
72
43
 
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
- };
44
+ // src/plugins/react-docgen-typescript/utils/typescript.ts
45
+ var typescript_exports = {};
46
+ __export(typescript_exports, {
47
+ getTSConfigFile: () => getTSConfigFile
48
+ });
49
+ function getTSConfigFile(tsconfigPath) {
81
50
  try {
82
- return import_resolve.default.sync(filename, resolveOptions);
51
+ const basePath = (0, import_node_path.dirname)(tsconfigPath);
52
+ const configFile = import_typescript.default.readConfigFile(tsconfigPath, import_typescript.default.sys.readFile);
53
+ return import_typescript.default.parseJsonConfigFileContent(
54
+ configFile.config,
55
+ import_typescript.default.sys,
56
+ basePath,
57
+ {},
58
+ tsconfigPath
59
+ );
83
60
  } 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
- });
61
+ return {};
103
62
  }
104
63
  }
105
- var import_node_path, import_resolve, ReactDocgenResolveError, RESOLVE_EXTENSIONS;
106
- var init_docgen_resolver = __esm({
107
- "src/plugins/docgen-resolver.ts"() {
64
+ var import_node_path, import_typescript;
65
+ var init_typescript = __esm({
66
+ "src/plugins/react-docgen-typescript/utils/typescript.ts"() {
108
67
  "use strict";
109
68
  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
- ];
69
+ import_typescript = __toESM(require("typescript"));
136
70
  }
137
71
  });
138
72
 
139
- // src/plugins/react-docgen.ts
140
- var react_docgen_exports = {};
141
- __export(react_docgen_exports, {
142
- getReactDocgenImporter: () => getReactDocgenImporter,
143
- reactDocgen: () => reactDocgen
73
+ // src/plugins/react-docgen-typescript/utils/options.ts
74
+ var options_exports = {};
75
+ __export(options_exports, {
76
+ getGenerateOptions: () => getGenerateOptions
144
77
  });
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
- }
78
+ function getGenerateOptions(options) {
79
+ const { setDisplayName: setDisplayName2 = true, typePropName = "type" } = options;
162
80
  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
- return src;
197
- }
198
- }
199
- );
200
- }
81
+ setDisplayName: setDisplayName2,
82
+ typePropName
201
83
  };
202
84
  }
203
- function getReactDocgenImporter(matchPath) {
204
- return (0, import_react_docgen2.makeFsImporter)((filename, basedir) => {
205
- const mappedFilenameByPaths = (() => {
206
- if (matchPath) {
207
- const match = matchPath(filename);
208
- return match || filename;
209
- } else {
210
- return filename;
211
- }
212
- })();
213
- const result = defaultLookupModule(mappedFilenameByPaths, basedir);
214
- if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
215
- return result;
85
+ var init_options = __esm({
86
+ "src/plugins/react-docgen-typescript/utils/options.ts"() {
87
+ "use strict";
88
+ }
89
+ });
90
+
91
+ // src/plugins/react-docgen-typescript/utils/generate.ts
92
+ var generate_exports = {};
93
+ __export(generate_exports, {
94
+ generateDocgenCodeBlock: () => generateDocgenCodeBlock
95
+ });
96
+ function createLiteral(value) {
97
+ switch (typeof value) {
98
+ case "string":
99
+ return import_typescript2.default.factory.createStringLiteral(value);
100
+ case "number":
101
+ return import_typescript2.default.factory.createNumericLiteral(value);
102
+ case "boolean":
103
+ return value ? import_typescript2.default.factory.createTrue() : import_typescript2.default.factory.createFalse();
104
+ }
105
+ }
106
+ function insertTsIgnoreBeforeStatement(statement) {
107
+ import_typescript2.default.setSyntheticLeadingComments(statement, [
108
+ {
109
+ text: " @ts-ignore",
110
+ // Leading space is important here
111
+ kind: import_typescript2.default.SyntaxKind.SingleLineCommentTrivia,
112
+ pos: -1,
113
+ end: -1
216
114
  }
217
- throw new ReactDocgenResolveError(filename);
218
- });
115
+ ]);
116
+ return statement;
117
+ }
118
+ function setDisplayName(d) {
119
+ return insertTsIgnoreBeforeStatement(
120
+ import_typescript2.default.factory.createExpressionStatement(
121
+ import_typescript2.default.factory.createBinaryExpression(
122
+ import_typescript2.default.factory.createPropertyAccessExpression(
123
+ import_typescript2.default.factory.createIdentifier(d.displayName),
124
+ import_typescript2.default.factory.createIdentifier("displayName")
125
+ ),
126
+ import_typescript2.default.SyntaxKind.EqualsToken,
127
+ import_typescript2.default.factory.createStringLiteral(d.displayName)
128
+ )
129
+ )
130
+ );
219
131
  }
220
- var import_node_path2, import_pluginutils, import_find_up, import_magic_string, import_react_docgen2, import_node_logger, TsconfigPaths, defaultHandlers, defaultResolver, handlers;
221
- var init_react_docgen = __esm({
222
- "src/plugins/react-docgen.ts"() {
132
+ function createPropDefinition(propName, prop, options) {
133
+ const setDefaultValue = (defaultValue) => import_typescript2.default.factory.createPropertyAssignment(
134
+ import_typescript2.default.factory.createStringLiteral("defaultValue"),
135
+ // Use a more extensive check on defaultValue. Sometimes the parser
136
+ // returns an empty object.
137
+ defaultValue?.value !== void 0 && (typeof defaultValue.value === "string" || typeof defaultValue.value === "number" || typeof defaultValue.value === "boolean") ? import_typescript2.default.factory.createObjectLiteralExpression([
138
+ import_typescript2.default.factory.createPropertyAssignment(
139
+ import_typescript2.default.factory.createIdentifier("value"),
140
+ createLiteral(defaultValue.value)
141
+ )
142
+ ]) : import_typescript2.default.factory.createNull()
143
+ );
144
+ const setStringLiteralField = (fieldName, fieldValue) => import_typescript2.default.factory.createPropertyAssignment(
145
+ import_typescript2.default.factory.createStringLiteral(fieldName),
146
+ import_typescript2.default.factory.createStringLiteral(fieldValue)
147
+ );
148
+ const setDescription = (description) => setStringLiteralField("description", description);
149
+ const setName = (name) => setStringLiteralField("name", name);
150
+ const setRequired = (required) => import_typescript2.default.factory.createPropertyAssignment(
151
+ import_typescript2.default.factory.createStringLiteral("required"),
152
+ required ? import_typescript2.default.factory.createTrue() : import_typescript2.default.factory.createFalse()
153
+ );
154
+ const setValue = (typeValue) => Array.isArray(typeValue) && typeValue.every((value) => typeof value.value === "string") ? import_typescript2.default.factory.createPropertyAssignment(
155
+ import_typescript2.default.factory.createStringLiteral("value"),
156
+ import_typescript2.default.factory.createArrayLiteralExpression(
157
+ typeValue.map(
158
+ (value) => import_typescript2.default.factory.createObjectLiteralExpression([
159
+ setStringLiteralField("value", value.value)
160
+ ])
161
+ )
162
+ )
163
+ ) : void 0;
164
+ const setType = (typeName, typeValue) => {
165
+ const objectFields = [setStringLiteralField("name", typeName)];
166
+ const valueField = setValue(typeValue);
167
+ if (valueField) {
168
+ objectFields.push(valueField);
169
+ }
170
+ return import_typescript2.default.factory.createPropertyAssignment(
171
+ import_typescript2.default.factory.createStringLiteral(options.typePropName),
172
+ import_typescript2.default.factory.createObjectLiteralExpression(objectFields)
173
+ );
174
+ };
175
+ return import_typescript2.default.factory.createPropertyAssignment(
176
+ import_typescript2.default.factory.createStringLiteral(propName),
177
+ import_typescript2.default.factory.createObjectLiteralExpression([
178
+ setDefaultValue(prop.defaultValue),
179
+ setDescription(prop.description),
180
+ setName(prop.name),
181
+ setRequired(prop.required),
182
+ setType(prop.type.name, prop.type.value)
183
+ ])
184
+ );
185
+ }
186
+ function setComponentDocGen(d, options) {
187
+ return insertTsIgnoreBeforeStatement(
188
+ import_typescript2.default.factory.createExpressionStatement(
189
+ import_typescript2.default.factory.createBinaryExpression(
190
+ // SimpleComponent.__docgenInfo
191
+ import_typescript2.default.factory.createPropertyAccessExpression(
192
+ import_typescript2.default.factory.createIdentifier(d.displayName),
193
+ import_typescript2.default.factory.createIdentifier("__docgenInfo")
194
+ ),
195
+ import_typescript2.default.SyntaxKind.EqualsToken,
196
+ import_typescript2.default.factory.createObjectLiteralExpression([
197
+ // SimpleComponent.__docgenInfo.description
198
+ import_typescript2.default.factory.createPropertyAssignment(
199
+ import_typescript2.default.factory.createStringLiteral("description"),
200
+ import_typescript2.default.factory.createStringLiteral(d.description)
201
+ ),
202
+ // SimpleComponent.__docgenInfo.displayName
203
+ import_typescript2.default.factory.createPropertyAssignment(
204
+ import_typescript2.default.factory.createStringLiteral("displayName"),
205
+ import_typescript2.default.factory.createStringLiteral(d.displayName)
206
+ ),
207
+ // SimpleComponent.__docgenInfo.props
208
+ import_typescript2.default.factory.createPropertyAssignment(
209
+ import_typescript2.default.factory.createStringLiteral("props"),
210
+ import_typescript2.default.factory.createObjectLiteralExpression(
211
+ Object.entries(d.props).map(
212
+ ([propName, prop]) => createPropDefinition(propName, prop, options)
213
+ )
214
+ )
215
+ )
216
+ ])
217
+ )
218
+ )
219
+ );
220
+ }
221
+ function generateDocgenCodeBlock(options) {
222
+ const sourceFile = import_typescript2.default.createSourceFile(
223
+ options.filename,
224
+ options.source,
225
+ import_typescript2.default.ScriptTarget.ESNext
226
+ );
227
+ const wrapInTryStatement = (statements) => import_typescript2.default.factory.createTryStatement(
228
+ import_typescript2.default.factory.createBlock(statements, true),
229
+ import_typescript2.default.factory.createCatchClause(
230
+ import_typescript2.default.factory.createVariableDeclaration(
231
+ import_typescript2.default.factory.createIdentifier("__react_docgen_typescript_loader_error")
232
+ ),
233
+ import_typescript2.default.factory.createBlock([])
234
+ ),
235
+ void 0
236
+ );
237
+ const codeBlocks = options.componentDocs.map(
238
+ (d) => wrapInTryStatement(
239
+ [
240
+ options.setDisplayName ? setDisplayName(d) : null,
241
+ setComponentDocGen(d, options)
242
+ ].filter((s2) => s2 !== null)
243
+ )
244
+ );
245
+ const printer = import_typescript2.default.createPrinter({ newLine: import_typescript2.default.NewLineKind.LineFeed });
246
+ const printNode = (sourceNode) => printer.printNode(import_typescript2.default.EmitHint.Unspecified, sourceNode, sourceFile);
247
+ const s = new import_magic_string.default(options.source);
248
+ for (const node of codeBlocks) {
249
+ s.append(printNode(node));
250
+ }
251
+ return {
252
+ code: s.toString(),
253
+ map: s.generateMap()
254
+ };
255
+ }
256
+ var import_magic_string, import_typescript2;
257
+ var init_generate = __esm({
258
+ "src/plugins/react-docgen-typescript/utils/generate.ts"() {
223
259
  "use strict";
224
- import_node_path2 = __toESM(require("path"));
225
- import_pluginutils = require("@rollup/pluginutils");
226
- import_find_up = __toESM(require("find-up"));
227
260
  import_magic_string = __toESM(require("magic-string"));
228
- import_react_docgen2 = require("react-docgen");
229
- import_node_logger = require("storybook/internal/node-logger");
230
- TsconfigPaths = __toESM(require("tsconfig-paths"));
231
- init_actualNameHandler();
232
- init_docgen_resolver();
233
- defaultHandlers = Object.values(import_react_docgen2.builtinHandlers).map((handler) => handler);
234
- defaultResolver = new import_react_docgen2.builtinResolvers.FindExportedDefinitionsResolver();
235
- handlers = [...defaultHandlers, actualNameHandler_default];
261
+ import_typescript2 = __toESM(require("typescript"));
262
+ }
263
+ });
264
+
265
+ // src/plugins/react-docgen-typescript/index.ts
266
+ var react_docgen_typescript_exports = {};
267
+ __export(react_docgen_typescript_exports, {
268
+ default: () => react_docgen_typescript_default
269
+ });
270
+ var import_pluginutils, getDocgen, startWatch, react_docgen_typescript_default;
271
+ var init_react_docgen_typescript = __esm({
272
+ "src/plugins/react-docgen-typescript/index.ts"() {
273
+ "use strict";
274
+ import_pluginutils = require("@rollup/pluginutils");
275
+ init_filter();
276
+ getDocgen = async (config) => {
277
+ const docGen = await import("react-docgen-typescript");
278
+ const {
279
+ tsconfigPath,
280
+ compilerOptions,
281
+ propFilter = defaultPropFilter,
282
+ setDisplayName: setDisplayName2,
283
+ typePropName,
284
+ ...rest
285
+ } = config;
286
+ const docgenOptions = {
287
+ propFilter,
288
+ ...rest
289
+ };
290
+ return docGen.withCompilerOptions(
291
+ // Compiler Options are passed in to the custom program.
292
+ {},
293
+ docgenOptions
294
+ );
295
+ };
296
+ startWatch = async (config, onProgramCreatedOrUpdated) => {
297
+ const { default: ts3 } = await import("typescript");
298
+ const { getTSConfigFile: getTSConfigFile2 } = await Promise.resolve().then(() => (init_typescript(), typescript_exports));
299
+ let compilerOptions = {
300
+ jsx: ts3.JsxEmit.React,
301
+ module: ts3.ModuleKind.CommonJS,
302
+ target: ts3.ScriptTarget.Latest
303
+ };
304
+ const tsconfigPath = config.tsconfigPath ?? "./tsconfig.json";
305
+ if (config.compilerOptions) {
306
+ compilerOptions = {
307
+ ...compilerOptions,
308
+ ...config.compilerOptions
309
+ };
310
+ } else {
311
+ const { options: tsOptions } = getTSConfigFile2(tsconfigPath);
312
+ compilerOptions = { ...compilerOptions, ...tsOptions };
313
+ }
314
+ const host = ts3.createWatchCompilerHost(
315
+ tsconfigPath,
316
+ compilerOptions,
317
+ ts3.sys,
318
+ ts3.createSemanticDiagnosticsBuilderProgram,
319
+ void 0,
320
+ () => {
321
+ }
322
+ );
323
+ host.afterProgramCreate = (program) => {
324
+ onProgramCreatedOrUpdated(program.getProgram());
325
+ };
326
+ return new Promise((resolve) => {
327
+ const watch = ts3.createWatchProgram(host);
328
+ resolve([watch.getProgram().getProgram(), watch.close]);
329
+ });
330
+ };
331
+ react_docgen_typescript_default = (config = {}) => {
332
+ let tsProgram;
333
+ let docGenParser;
334
+ let generateDocgenCodeBlock2;
335
+ let generateOptions;
336
+ let filter;
337
+ const moduleInvalidationQueue = /* @__PURE__ */ new Map();
338
+ let closeWatch;
339
+ return {
340
+ name: "rsbuild-plugin-react-docgen-typescript",
341
+ setup(api) {
342
+ api.modifyRsbuildConfig(async () => {
343
+ const { getGenerateOptions: getGenerateOptions2 } = await Promise.resolve().then(() => (init_options(), options_exports));
344
+ generateDocgenCodeBlock2 = (await Promise.resolve().then(() => (init_generate(), generate_exports))).generateDocgenCodeBlock;
345
+ docGenParser = await getDocgen(config);
346
+ generateOptions = getGenerateOptions2(config);
347
+ [tsProgram, closeWatch] = await startWatch(config, (program) => {
348
+ tsProgram = program;
349
+ for (const [
350
+ filepath,
351
+ invalidateModule
352
+ ] of moduleInvalidationQueue.entries()) {
353
+ invalidateModule();
354
+ moduleInvalidationQueue.delete(filepath);
355
+ }
356
+ });
357
+ filter = (0, import_pluginutils.createFilter)(
358
+ config.include ?? ["**/**.tsx"],
359
+ config.exclude ?? ["**/**.stories.tsx"]
360
+ );
361
+ });
362
+ api.transform(
363
+ {
364
+ test: (id) => {
365
+ return filter(id);
366
+ }
367
+ },
368
+ async ({ code: src, resource: id }) => {
369
+ try {
370
+ const componentDocs = docGenParser.parseWithProgramProvider(
371
+ id,
372
+ () => tsProgram
373
+ );
374
+ if (!componentDocs.length) {
375
+ return { code: src };
376
+ }
377
+ const res = generateDocgenCodeBlock2({
378
+ filename: id,
379
+ source: src,
380
+ componentDocs,
381
+ ...generateOptions
382
+ });
383
+ return res;
384
+ } catch (e) {
385
+ return src;
386
+ }
387
+ }
388
+ );
389
+ api.onCloseBuild(() => {
390
+ closeWatch();
391
+ });
392
+ }
393
+ };
394
+ };
236
395
  }
237
396
  });
238
397
 
@@ -243,15 +402,15 @@ __export(preset_exports, {
243
402
  rsbuildFinal: () => rsbuildFinal
244
403
  });
245
404
  module.exports = __toCommonJS(preset_exports);
246
- var import_node_path3 = require("path");
405
+ var import_node_path2 = require("path");
247
406
 
248
407
  // src/react-docs.ts
249
408
  var import_core = require("@rsbuild/core");
250
409
  var import_docs_tools = require("storybook/internal/docs-tools");
251
410
 
252
411
  // src/requirer.ts
253
- function requirer(resolver, path2) {
254
- return resolver(path2);
412
+ function requirer(resolver, path) {
413
+ return resolver(path);
255
414
  }
256
415
 
257
416
  // src/react-docs.ts
@@ -260,11 +419,11 @@ var rsbuildFinalDocs = async (config, options) => {
260
419
  return config;
261
420
  const typescriptOptions = await options.presets.apply("typescript", {});
262
421
  const debug = options.loglevel === "debug";
263
- const { reactDocgen: reactDocgen2 } = typescriptOptions || {};
264
- if (typeof reactDocgen2 !== "string") {
422
+ const { reactDocgen, reactDocgenTypescriptOptions } = typescriptOptions || {};
423
+ if (typeof reactDocgen !== "string") {
265
424
  return config;
266
425
  }
267
- if (reactDocgen2 !== "react-docgen-typescript") {
426
+ if (reactDocgen !== "react-docgen-typescript") {
268
427
  return (0, import_core.mergeRsbuildConfig)(config, {
269
428
  tools: {
270
429
  rspack: {
@@ -288,18 +447,29 @@ var rsbuildFinalDocs = async (config, options) => {
288
447
  }
289
448
  });
290
449
  }
291
- const { reactDocgen: reactDocGenPlugin } = await Promise.resolve().then(() => (init_react_docgen(), react_docgen_exports));
450
+ let typescriptPresent;
451
+ try {
452
+ require.resolve("typescript");
453
+ typescriptPresent = true;
454
+ } catch (e) {
455
+ typescriptPresent = false;
456
+ }
457
+ if (reactDocgen === "react-docgen-typescript" && typescriptPresent) {
458
+ }
459
+ const reactDocGenTsPlugin = await Promise.resolve().then(() => (init_react_docgen_typescript(), react_docgen_typescript_exports));
292
460
  return (0, import_core.mergeRsbuildConfig)(config, {
293
461
  plugins: [
294
- await reactDocGenPlugin({
295
- include: reactDocgen2 === "react-docgen-typescript" ? /\.(mjs|tsx?|jsx?)$/ : /\.(mjs|jsx?)$/
462
+ await reactDocGenTsPlugin.default({
463
+ ...reactDocgenTypescriptOptions,
464
+ // We *need* this set so that RDT returns default values in the same format as react-docgen
465
+ savePropValueAsString: true
296
466
  })
297
467
  ]
298
468
  });
299
469
  };
300
470
 
301
471
  // src/preset.ts
302
- var getAbsolutePath = (input) => (0, import_node_path3.dirname)(require.resolve((0, import_node_path3.join)(input, "package.json")));
472
+ var getAbsolutePath = (input) => (0, import_node_path2.dirname)(require.resolve((0, import_node_path2.join)(input, "package.json")));
303
473
  var rsbuildFinal = async (config, options) => {
304
474
  const finalConfig = rsbuildFinalDocs(config, options);
305
475
  return finalConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-react-rsbuild",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Storybook for React and Rsbuild: Develop React components in isolation with Hot Reloading.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -57,13 +57,15 @@
57
57
  "find-up": "^5.0.0",
58
58
  "magic-string": "^0.30.17",
59
59
  "react-docgen": "^7.1.0",
60
+ "react-docgen-typescript": "^2.2.2",
60
61
  "resolve": "^1.22.10",
61
62
  "tsconfig-paths": "^4.2.0",
62
- "storybook-builder-rsbuild": "0.1.8"
63
+ "storybook-builder-rsbuild": "0.1.9"
63
64
  },
64
65
  "devDependencies": {
65
66
  "@rsbuild/core": "^1.1.13",
66
67
  "@storybook/types": "8.5.0-beta.8",
68
+ "@types/react": "^18.3.18",
67
69
  "@types/resolve": "^1.20.6",
68
70
  "react": "18.3.1",
69
71
  "react-dom": "18.3.1",