storybook-react-rsbuild 3.6.1 → 3.6.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,6 +1,7 @@
1
1
  import "node:module";
2
2
  import magic_string from "magic-string";
3
3
  import typescript from "typescript";
4
+ import { isSupportedRuntimeTargetExpression } from "./react-docgen-typescript-b22d46ea.js";
4
5
  function createLiteral(value) {
5
6
  switch(typeof value){
6
7
  case 'string':
@@ -22,8 +23,8 @@ function insertTsIgnoreBeforeStatement(statement) {
22
23
  ]);
23
24
  return statement;
24
25
  }
25
- function setDisplayName(d) {
26
- return insertTsIgnoreBeforeStatement(typescript.factory.createExpressionStatement(typescript.factory.createBinaryExpression(typescript.factory.createPropertyAccessExpression(typescript.factory.createIdentifier(d.displayName), typescript.factory.createIdentifier('displayName')), typescript.SyntaxKind.EqualsToken, typescript.factory.createStringLiteral(d.displayName))));
26
+ function setDisplayName(d, target) {
27
+ return insertTsIgnoreBeforeStatement(typescript.factory.createExpressionStatement(typescript.factory.createBinaryExpression(typescript.factory.createPropertyAccessExpression(typescript.factory.createIdentifier(target), typescript.factory.createIdentifier('displayName')), typescript.SyntaxKind.EqualsToken, typescript.factory.createStringLiteral(d.displayName))));
27
28
  }
28
29
  function createPropDefinition(propName, prop, options) {
29
30
  const setDefaultValue = (defaultValue)=>typescript.factory.createPropertyAssignment(typescript.factory.createStringLiteral('defaultValue'), defaultValue?.value !== void 0 && ('string' == typeof defaultValue.value || 'number' == typeof defaultValue.value || 'boolean' == typeof defaultValue.value) ? typescript.factory.createObjectLiteralExpression([
@@ -52,8 +53,8 @@ function createPropDefinition(propName, prop, options) {
52
53
  setType(prop.type.name, prop.type.value)
53
54
  ]));
54
55
  }
55
- function setComponentDocGen(d, options) {
56
- return insertTsIgnoreBeforeStatement(typescript.factory.createExpressionStatement(typescript.factory.createBinaryExpression(typescript.factory.createPropertyAccessExpression(typescript.factory.createIdentifier(d.displayName), typescript.factory.createIdentifier('__docgenInfo')), typescript.SyntaxKind.EqualsToken, typescript.factory.createObjectLiteralExpression([
56
+ function setComponentDocGen(d, options, target) {
57
+ return insertTsIgnoreBeforeStatement(typescript.factory.createExpressionStatement(typescript.factory.createBinaryExpression(typescript.factory.createPropertyAccessExpression(typescript.factory.createIdentifier(target), typescript.factory.createIdentifier('__docgenInfo')), typescript.SyntaxKind.EqualsToken, typescript.factory.createObjectLiteralExpression([
57
58
  typescript.factory.createPropertyAssignment(typescript.factory.createStringLiteral("description"), typescript.factory.createStringLiteral(d.description)),
58
59
  typescript.factory.createPropertyAssignment(typescript.factory.createStringLiteral('displayName'), typescript.factory.createStringLiteral(d.displayName)),
59
60
  typescript.factory.createPropertyAssignment(typescript.factory.createStringLiteral('props'), typescript.factory.createObjectLiteralExpression(Object.entries(d.props).map(([propName, prop])=>createPropDefinition(propName, prop, options))))
@@ -62,10 +63,16 @@ function setComponentDocGen(d, options) {
62
63
  function generateDocgenCodeBlock(options) {
63
64
  const sourceFile = typescript.createSourceFile(options.filename, options.source, typescript.ScriptTarget.ESNext);
64
65
  const wrapInTryStatement = (statements)=>typescript.factory.createTryStatement(typescript.factory.createBlock(statements, true), typescript.factory.createCatchClause(typescript.factory.createVariableDeclaration(typescript.factory.createIdentifier("__react_docgen_typescript_loader_error")), typescript.factory.createBlock([])), void 0);
65
- const codeBlocks = options.componentDocs.map((d)=>wrapInTryStatement([
66
- options.setDisplayName ? setDisplayName(d) : null,
67
- setComponentDocGen(d, options)
68
- ].filter((s)=>null !== s)));
66
+ const codeBlocks = options.componentDocs.flatMap((d)=>{
67
+ const target = d.targetExpression;
68
+ if (!target || !isSupportedRuntimeTargetExpression(target)) return [];
69
+ return [
70
+ wrapInTryStatement([
71
+ options.setDisplayName ? setDisplayName(d, target) : null,
72
+ setComponentDocGen(d, options, target)
73
+ ].filter((s)=>null !== s))
74
+ ];
75
+ });
69
76
  const printer = typescript.createPrinter({
70
77
  newLine: typescript.NewLineKind.LineFeed
71
78
  });
@@ -73,7 +80,10 @@ function generateDocgenCodeBlock(options) {
73
80
  const s = new magic_string(options.source, {
74
81
  filename: options.filename
75
82
  });
76
- for (const node of codeBlocks)s.append(printNode(node));
83
+ if (codeBlocks.length > 0) {
84
+ const separator = options.source.endsWith('\n') ? '' : '\n';
85
+ s.append(separator + codeBlocks.map(printNode).join('\n'));
86
+ }
77
87
  return {
78
88
  code: s.toString(),
79
89
  map: s.generateMap({
@@ -0,0 +1,327 @@
1
+ import "node:module";
2
+ import { createFilter } from "@rollup/pluginutils";
3
+ import { getDefaultExportForFile } from "react-docgen-typescript";
4
+ const defaultPropFilter = (prop)=>!prop.parent?.fileName.includes('node_modules');
5
+ const IDENTIFIER_PATH_PATTERN = /^[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*(?:\.[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*)*$/u;
6
+ const RESERVED_RUNTIME_TARGET_ROOTS = new Set([
7
+ 'arguments',
8
+ 'await',
9
+ 'break',
10
+ 'case',
11
+ 'catch',
12
+ 'class',
13
+ 'const',
14
+ 'continue',
15
+ 'debugger',
16
+ 'default',
17
+ 'delete',
18
+ 'do',
19
+ 'else',
20
+ 'enum',
21
+ 'eval',
22
+ 'export',
23
+ 'extends',
24
+ 'false',
25
+ 'finally',
26
+ 'for',
27
+ 'function',
28
+ 'if',
29
+ 'implements',
30
+ 'import',
31
+ 'in',
32
+ 'instanceof',
33
+ 'interface',
34
+ 'let',
35
+ 'new',
36
+ 'null',
37
+ 'package',
38
+ 'private',
39
+ 'protected',
40
+ 'public',
41
+ 'return',
42
+ 'static',
43
+ 'super',
44
+ 'switch',
45
+ 'this',
46
+ 'throw',
47
+ 'true',
48
+ 'try',
49
+ 'typeof',
50
+ 'var',
51
+ 'void',
52
+ 'while',
53
+ 'with',
54
+ 'yield'
55
+ ]);
56
+ const isSupportedRuntimeTargetExpression = (value)=>{
57
+ if (!IDENTIFIER_PATH_PATTERN.test(value)) return false;
58
+ const [root] = value.split('.', 1);
59
+ return Boolean(root && !RESERVED_RUNTIME_TARGET_ROOTS.has(root));
60
+ };
61
+ const getNodeModifiers = (node)=>'modifiers' in node ? node.modifiers : void 0;
62
+ const hasModifier = (node, modifierKind)=>Boolean(getNodeModifiers(node)?.some((modifier)=>modifier.kind === modifierKind));
63
+ const getExpressionTargetText = (expression, sourceFile, tsModule)=>{
64
+ if (tsModule.isIdentifier(expression)) return expression.text;
65
+ if (tsModule.isPropertyAccessExpression(expression)) {
66
+ const targetExpression = expression.getText(sourceFile);
67
+ return isSupportedRuntimeTargetExpression(targetExpression) ? targetExpression : null;
68
+ }
69
+ return null;
70
+ };
71
+ const getDeclarationName = (declaration, tsModule)=>{
72
+ const named = tsModule.isArrowFunction(declaration) || tsModule.isFunctionExpression(declaration) || tsModule.isClassExpression(declaration) ? declaration.parent : declaration;
73
+ if ((tsModule.isVariableDeclaration(named) || tsModule.isBindingElement(named) || tsModule.isFunctionDeclaration(named) || tsModule.isClassDeclaration(named)) && named.name && tsModule.isIdentifier(named.name)) return named.name.text;
74
+ return null;
75
+ };
76
+ const getModuleScopePath = (declaration, tsModule)=>{
77
+ const namespacePath = [];
78
+ let node = declaration;
79
+ while(node.parent){
80
+ const parent = node.parent;
81
+ if (tsModule.isSourceFile(parent)) return namespacePath.reverse();
82
+ if (tsModule.isModuleBlock(parent)) {
83
+ const moduleDeclaration = parent.parent;
84
+ if (!hasModifier(node, tsModule.SyntaxKind.ExportKeyword) || !tsModule.isIdentifier(moduleDeclaration.name)) return null;
85
+ namespacePath.push(moduleDeclaration.name.text);
86
+ node = moduleDeclaration;
87
+ continue;
88
+ }
89
+ if (tsModule.isVariableDeclaration(parent) || tsModule.isVariableDeclarationList(parent) || tsModule.isVariableStatement(parent) || tsModule.isObjectBindingPattern(parent) || tsModule.isArrayBindingPattern(parent) || tsModule.isBindingElement(parent)) {
90
+ node = parent;
91
+ continue;
92
+ }
93
+ break;
94
+ }
95
+ return null;
96
+ };
97
+ const getDeclarationTarget = (declaration, sourceFile, tsModule)=>{
98
+ const name = getDeclarationName(declaration, tsModule);
99
+ if (name) {
100
+ const namespacePath = getModuleScopePath(declaration, tsModule);
101
+ return namespacePath ? [
102
+ ...namespacePath,
103
+ name
104
+ ].join('.') : null;
105
+ }
106
+ if (tsModule.isExportAssignment(declaration)) return getExpressionTargetText(declaration.expression, sourceFile, tsModule);
107
+ if (tsModule.isExportSpecifier(declaration)) {
108
+ const exportDeclaration = declaration.parent.parent;
109
+ if (tsModule.isExportDeclaration(exportDeclaration) && exportDeclaration.getSourceFile() === sourceFile && !exportDeclaration.moduleSpecifier) return declaration.propertyName?.text ?? declaration.name.text;
110
+ }
111
+ return null;
112
+ };
113
+ const getTargetFromSymbol = (symbol, checker, sourceFile, tsModule)=>{
114
+ const candidateSymbols = [
115
+ symbol
116
+ ];
117
+ if (symbol.flags & tsModule.SymbolFlags.Alias) try {
118
+ candidateSymbols.unshift(checker.getAliasedSymbol(symbol));
119
+ } catch {}
120
+ for (const candidateSymbol of candidateSymbols){
121
+ const declarations = candidateSymbol.declarations ?? (candidateSymbol.valueDeclaration ? [
122
+ candidateSymbol.valueDeclaration
123
+ ] : []);
124
+ for (const declaration of declarations){
125
+ if (declaration.getSourceFile() !== sourceFile) continue;
126
+ if (tsModule.isShorthandPropertyAssignment(declaration)) {
127
+ const name = declaration.name.text;
128
+ const resolveAlias = (value)=>value && value.flags & tsModule.SymbolFlags.Alias ? checker.getAliasedSymbol(value) : value;
129
+ const valueSymbol = resolveAlias(checker.getShorthandAssignmentValueSymbol(declaration));
130
+ const moduleSymbol = resolveAlias(checker.resolveName(name, sourceFile, tsModule.SymbolFlags.Value | tsModule.SymbolFlags.Alias, false));
131
+ if (valueSymbol && moduleSymbol === valueSymbol && isSupportedRuntimeTargetExpression(name)) return name;
132
+ continue;
133
+ }
134
+ const targetExpression = getDeclarationTarget(declaration, sourceFile, tsModule);
135
+ if (targetExpression && isSupportedRuntimeTargetExpression(targetExpression)) return targetExpression;
136
+ }
137
+ }
138
+ return null;
139
+ };
140
+ const collectBindingTargets = (name, tsModule, targets)=>{
141
+ if (tsModule.isIdentifier(name)) return void targets.push(name.text);
142
+ for (const element of name.elements)if (tsModule.isBindingElement(element)) collectBindingTargets(element.name, tsModule, targets);
143
+ };
144
+ const getDeclarationStatementTarget = (statement, tsModule)=>{
145
+ if (tsModule.isVariableStatement(statement)) {
146
+ const targets = [];
147
+ for (const declaration of statement.declarationList.declarations)collectBindingTargets(declaration.name, tsModule, targets);
148
+ return targets;
149
+ }
150
+ if ((tsModule.isFunctionDeclaration(statement) || tsModule.isClassDeclaration(statement)) && statement.name) return [
151
+ statement.name.text
152
+ ];
153
+ return [];
154
+ };
155
+ const getNamedExportTargets = (sourceFile, tsModule)=>{
156
+ const namedExportTargets = new Set();
157
+ for (const statement of sourceFile.statements){
158
+ if (hasModifier(statement, tsModule.SyntaxKind.ExportKeyword) && !hasModifier(statement, tsModule.SyntaxKind.DefaultKeyword)) getDeclarationStatementTarget(statement, tsModule).forEach((target)=>{
159
+ namedExportTargets.add(target);
160
+ });
161
+ if (tsModule.isExportDeclaration(statement) && statement.exportClause && tsModule.isNamedExports(statement.exportClause) && !statement.moduleSpecifier) statement.exportClause.elements.forEach((element)=>{
162
+ if ('default' === element.name.text) return;
163
+ namedExportTargets.add(element.propertyName?.text ?? element.name.text);
164
+ });
165
+ }
166
+ return namedExportTargets;
167
+ };
168
+ const getDefaultExportTarget = (sourceFile, tsModule)=>{
169
+ for (const statement of sourceFile.statements){
170
+ if (tsModule.isExportAssignment(statement)) return getExpressionTargetText(statement.expression, sourceFile, tsModule);
171
+ if ((tsModule.isFunctionDeclaration(statement) || tsModule.isClassDeclaration(statement)) && hasModifier(statement, tsModule.SyntaxKind.ExportKeyword) && hasModifier(statement, tsModule.SyntaxKind.DefaultKeyword) && statement.name) return statement.name.text;
172
+ if (tsModule.isExportDeclaration(statement) && statement.exportClause && tsModule.isNamedExports(statement.exportClause) && !statement.moduleSpecifier) {
173
+ const defaultSpecifier = statement.exportClause.elements.find((element)=>'default' === element.name.text);
174
+ if (defaultSpecifier) return defaultSpecifier.propertyName?.text ?? defaultSpecifier.name.text;
175
+ }
176
+ }
177
+ return null;
178
+ };
179
+ const resolveTargetExpression = (componentDoc, checker, sourceFile, namedExportTargets, tsModule)=>{
180
+ if (componentDoc.expression) {
181
+ const targetFromExpression = getTargetFromSymbol(componentDoc.expression, checker, sourceFile, tsModule);
182
+ if (targetFromExpression) return targetFromExpression;
183
+ }
184
+ if (namedExportTargets.has(componentDoc.displayName)) return componentDoc.displayName;
185
+ if (componentDoc.displayName.includes('.') && isSupportedRuntimeTargetExpression(componentDoc.displayName)) return componentDoc.displayName;
186
+ return null;
187
+ };
188
+ function resolveComponentDocRuntimeTargets(componentDocs, checker, sourceFile, tsModule) {
189
+ const namedExportTargets = getNamedExportTargets(sourceFile, tsModule);
190
+ const defaultExportTarget = getDefaultExportTarget(sourceFile, tsModule);
191
+ const defaultExportDisplayName = getDefaultExportForFile(sourceFile);
192
+ const usedTargets = new Set();
193
+ const resolvedComponentDocs = componentDocs.map((componentDoc)=>{
194
+ const targetExpression = resolveTargetExpression(componentDoc, checker, sourceFile, namedExportTargets, tsModule);
195
+ if (targetExpression) usedTargets.add(targetExpression);
196
+ return {
197
+ ...componentDoc,
198
+ targetExpression
199
+ };
200
+ });
201
+ if (!defaultExportTarget || usedTargets.has(defaultExportTarget)) return resolvedComponentDocs;
202
+ const unresolvedDocs = resolvedComponentDocs.filter((componentDoc)=>!componentDoc.targetExpression);
203
+ const defaultExportDoc = unresolvedDocs.find((componentDoc)=>componentDoc.displayName === defaultExportDisplayName) ?? (1 === unresolvedDocs.length ? unresolvedDocs[0] : void 0);
204
+ if (defaultExportDoc) defaultExportDoc.targetExpression = defaultExportTarget;
205
+ return resolvedComponentDocs;
206
+ }
207
+ const getDocgen = async (config)=>{
208
+ const docGen = await import("react-docgen-typescript");
209
+ const { tsconfigPath, compilerOptions, propFilter = defaultPropFilter, setDisplayName, typePropName, ...rest } = config;
210
+ const docgenOptions = {
211
+ propFilter,
212
+ ...rest,
213
+ shouldIncludeExpression: true
214
+ };
215
+ return docGen.withCompilerOptions({}, docgenOptions);
216
+ };
217
+ const startProgram = async (config, isBuild, onProgramCreatedOrUpdated)=>{
218
+ const { default: ts } = await import("typescript");
219
+ const { getTSConfigFile } = await import("./typescript-69cd7fa9.js");
220
+ let compilerOptions = {
221
+ jsx: ts.JsxEmit.React,
222
+ module: ts.ModuleKind.CommonJS,
223
+ target: ts.ScriptTarget.Latest
224
+ };
225
+ const tsconfigPath = config.tsconfigPath ?? './tsconfig.json';
226
+ if (config.compilerOptions) compilerOptions = {
227
+ ...compilerOptions,
228
+ ...config.compilerOptions
229
+ };
230
+ else {
231
+ const { options: tsOptions } = getTSConfigFile(tsconfigPath);
232
+ compilerOptions = {
233
+ ...compilerOptions,
234
+ ...tsOptions
235
+ };
236
+ }
237
+ if (isBuild) {
238
+ const tsConfig = getTSConfigFile(tsconfigPath);
239
+ const program = ts.createProgram({
240
+ rootNames: tsConfig.fileNames ?? [],
241
+ options: {
242
+ ...tsConfig.options,
243
+ ...compilerOptions
244
+ },
245
+ projectReferences: tsConfig.projectReferences
246
+ });
247
+ return [
248
+ program,
249
+ ()=>{},
250
+ ts
251
+ ];
252
+ }
253
+ const host = ts.createWatchCompilerHost(tsconfigPath, compilerOptions, ts.sys, ts.createSemanticDiagnosticsBuilderProgram, void 0, ()=>{});
254
+ host.afterProgramCreate = (program)=>{
255
+ onProgramCreatedOrUpdated(program.getProgram());
256
+ };
257
+ return new Promise((resolve)=>{
258
+ const watch = ts.createWatchProgram(host);
259
+ resolve([
260
+ watch.getProgram().getProgram(),
261
+ ()=>watch.close(),
262
+ ts
263
+ ]);
264
+ });
265
+ };
266
+ const react_docgen_typescript = (config = {})=>{
267
+ let tsProgram;
268
+ let tsModule;
269
+ let docGenParser;
270
+ let generateDocgenCodeBlock;
271
+ let generateOptions;
272
+ let filter;
273
+ const moduleInvalidationQueue = new Map();
274
+ let closeWatch;
275
+ return {
276
+ name: "rsbuild-plugin-react-docgen-typescript",
277
+ setup (api) {
278
+ api.modifyRsbuildConfig(async ()=>{
279
+ const { getGenerateOptions } = await import("./options-7e849a08.js");
280
+ generateDocgenCodeBlock = (await import("./generate-edd3f3a5.js")).generateDocgenCodeBlock;
281
+ docGenParser = await getDocgen(config);
282
+ generateOptions = getGenerateOptions(config);
283
+ [tsProgram, closeWatch, tsModule] = await startProgram(config, 'build' === api.context.action, (program)=>{
284
+ tsProgram = program;
285
+ for (const [filepath, invalidateModule] of moduleInvalidationQueue.entries()){
286
+ invalidateModule();
287
+ moduleInvalidationQueue.delete(filepath);
288
+ }
289
+ });
290
+ filter = createFilter(config.include ?? [
291
+ '**/**.tsx'
292
+ ], config.exclude ?? [
293
+ '**/**.stories.tsx'
294
+ ]);
295
+ });
296
+ api.transform({
297
+ test: (id)=>filter(id)
298
+ }, async ({ code: src, resource: id })=>{
299
+ try {
300
+ const componentDocs = docGenParser.parseWithProgramProvider(id, ()=>tsProgram);
301
+ if (!componentDocs.length) return {
302
+ code: src
303
+ };
304
+ const sourceFile = tsProgram.getSourceFile(id);
305
+ if (!sourceFile) return {
306
+ code: src
307
+ };
308
+ const resolvedDocs = resolveComponentDocRuntimeTargets(componentDocs, tsProgram.getTypeChecker(), sourceFile, tsModule);
309
+ const res = generateDocgenCodeBlock({
310
+ filename: id,
311
+ source: src,
312
+ componentDocs: resolvedDocs,
313
+ ...generateOptions
314
+ });
315
+ return res;
316
+ } catch (_e) {
317
+ return src;
318
+ }
319
+ });
320
+ const close = ()=>closeWatch?.();
321
+ api.onCloseBuild(close);
322
+ api.onCloseDevServer(close);
323
+ }
324
+ };
325
+ };
326
+ export default react_docgen_typescript;
327
+ export { isSupportedRuntimeTargetExpression };
@@ -66,7 +66,7 @@ function defaultLookupModule(filename, basedir) {
66
66
  });
67
67
  }
68
68
  }
69
- const { getNameOrValue: getNameOrValue, isReactForwardRefCall: isReactForwardRefCall } = utils;
69
+ const { getNameOrValue, isReactForwardRefCall } = utils;
70
70
  const react_docgen_loader_actualNameHandler = function(documentation, componentDefinition) {
71
71
  documentation.set('definedInFile', componentDefinition.hub.file.opts.filename);
72
72
  if ((componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has('id')) documentation.set('actualName', getNameOrValue(componentDefinition.get('id')));
@@ -98,7 +98,7 @@ async function reactDocgenLoader(source, map) {
98
98
  const docgenResults = parse(source, {
99
99
  filename: this.resourcePath,
100
100
  resolver: defaultResolver,
101
- handlers: handlers,
101
+ handlers,
102
102
  importer: getReactDocgenImporter(matchPath),
103
103
  babelOptions: {
104
104
  babelrc: false,
package/dist/preset.js CHANGED
@@ -41,7 +41,7 @@ const rsbuildFinalDocs = async (config, options)=>{
41
41
  }
42
42
  }
43
43
  });
44
- const reactDocGenTsPlugin = await import("./chunks/react-docgen-typescript-16ec96c4.js");
44
+ const reactDocGenTsPlugin = await import("./chunks/react-docgen-typescript-b22d46ea.js");
45
45
  return mergeRsbuildConfig(config, {
46
46
  tools: {
47
47
  rspack: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-react-rsbuild",
3
- "version": "3.6.1",
3
+ "version": "3.6.2",
4
4
  "description": "Storybook for React and Rsbuild: Develop React components in isolation with Hot Reloading.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -46,32 +46,32 @@
46
46
  "!src/**/*"
47
47
  ],
48
48
  "dependencies": {
49
- "@rollup/pluginutils": "^5.4.0",
50
- "@storybook/react": "^10.6.0",
49
+ "@rollup/pluginutils": "^5.5.1",
50
+ "@storybook/react": "^10.6.5",
51
51
  "@storybook/react-docgen-typescript-plugin": "^1.0.1",
52
- "magic-string": "^1.4.2",
52
+ "magic-string": "^1.4.5",
53
53
  "react-docgen": "^8.0.4",
54
54
  "react-docgen-typescript": "^2.4.0",
55
- "resolve": "^1.22.12",
55
+ "resolve": "^1.22.14",
56
56
  "tsconfig-paths": "^4.2.0",
57
- "storybook-builder-rsbuild": "3.6.1"
57
+ "storybook-builder-rsbuild": "3.6.2"
58
58
  },
59
59
  "devDependencies": {
60
- "@microsoft/api-extractor": "^7.59.3",
61
- "@rsbuild/core": "^2.2.11",
60
+ "@microsoft/api-extractor": "^7.60.1",
61
+ "@rsbuild/core": "^2.2.14",
62
62
  "@types/node": "^22.0.0",
63
63
  "@types/react": "^18.3.31",
64
64
  "@types/resolve": "^1.20.6",
65
65
  "react": "18.3.1",
66
66
  "react-dom": "18.3.1",
67
- "storybook": "10.6.0",
67
+ "storybook": "10.6.5",
68
68
  "typescript": "^5.9.3"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "@rsbuild/core": "^1.5.0 || ^2.0.0-0",
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.6.0",
74
+ "storybook": "^10.6.5",
75
75
  "typescript": ">= 4.2.x"
76
76
  },
77
77
  "peerDependenciesMeta": {
@@ -95,7 +95,7 @@
95
95
  "platform": "node"
96
96
  },
97
97
  "scripts": {
98
- "build": "rstack lib",
99
- "dev": "rstack lib --watch"
98
+ "build": "rs lib",
99
+ "dev": "rs lib --watch"
100
100
  }
101
101
  }
@@ -1,114 +0,0 @@
1
- import "node:module";
2
- import { createFilter } from "@rollup/pluginutils";
3
- const defaultPropFilter = (prop)=>!prop.parent?.fileName.includes('node_modules');
4
- const getDocgen = async (config)=>{
5
- const docGen = await import("react-docgen-typescript");
6
- const { tsconfigPath, compilerOptions, propFilter = defaultPropFilter, setDisplayName, typePropName, ...rest } = config;
7
- const docgenOptions = {
8
- propFilter,
9
- ...rest
10
- };
11
- return docGen.withCompilerOptions({}, docgenOptions);
12
- };
13
- const startProgram = async (config, isBuild, onProgramCreatedOrUpdated)=>{
14
- const { default: ts } = await import("typescript");
15
- const { getTSConfigFile } = await import("./typescript-69cd7fa9.js");
16
- let compilerOptions = {
17
- jsx: ts.JsxEmit.React,
18
- module: ts.ModuleKind.CommonJS,
19
- target: ts.ScriptTarget.Latest
20
- };
21
- const tsconfigPath = config.tsconfigPath ?? './tsconfig.json';
22
- if (config.compilerOptions) compilerOptions = {
23
- ...compilerOptions,
24
- ...config.compilerOptions
25
- };
26
- else {
27
- const { options: tsOptions } = getTSConfigFile(tsconfigPath);
28
- compilerOptions = {
29
- ...compilerOptions,
30
- ...tsOptions
31
- };
32
- }
33
- if (isBuild) {
34
- const tsConfig = getTSConfigFile(tsconfigPath);
35
- const program = ts.createProgram({
36
- rootNames: tsConfig.fileNames ?? [],
37
- options: {
38
- ...tsConfig.options,
39
- ...compilerOptions
40
- },
41
- projectReferences: tsConfig.projectReferences
42
- });
43
- return [
44
- program,
45
- ()=>{}
46
- ];
47
- }
48
- const host = ts.createWatchCompilerHost(tsconfigPath, compilerOptions, ts.sys, ts.createSemanticDiagnosticsBuilderProgram, void 0, ()=>{});
49
- host.afterProgramCreate = (program)=>{
50
- onProgramCreatedOrUpdated(program.getProgram());
51
- };
52
- return new Promise((resolve)=>{
53
- const watch = ts.createWatchProgram(host);
54
- resolve([
55
- watch.getProgram().getProgram(),
56
- ()=>watch.close()
57
- ]);
58
- });
59
- };
60
- const react_docgen_typescript = (config = {})=>{
61
- let tsProgram;
62
- let docGenParser;
63
- let generateDocgenCodeBlock;
64
- let generateOptions;
65
- let filter;
66
- const moduleInvalidationQueue = new Map();
67
- let closeWatch;
68
- return {
69
- name: "rsbuild-plugin-react-docgen-typescript",
70
- setup (api) {
71
- api.modifyRsbuildConfig(async ()=>{
72
- const { getGenerateOptions } = await import("./options-7e849a08.js");
73
- generateDocgenCodeBlock = (await import("./generate-1782ed11.js")).generateDocgenCodeBlock;
74
- docGenParser = await getDocgen(config);
75
- generateOptions = getGenerateOptions(config);
76
- [tsProgram, closeWatch] = await startProgram(config, 'build' === api.context.action, (program)=>{
77
- tsProgram = program;
78
- for (const [filepath, invalidateModule] of moduleInvalidationQueue.entries()){
79
- invalidateModule();
80
- moduleInvalidationQueue.delete(filepath);
81
- }
82
- });
83
- filter = createFilter(config.include ?? [
84
- '**/**.tsx'
85
- ], config.exclude ?? [
86
- '**/**.stories.tsx'
87
- ]);
88
- });
89
- api.transform({
90
- test: (id)=>filter(id)
91
- }, async ({ code: src, resource: id })=>{
92
- try {
93
- const componentDocs = docGenParser.parseWithProgramProvider(id, ()=>tsProgram);
94
- if (!componentDocs.length) return {
95
- code: src
96
- };
97
- const res = generateDocgenCodeBlock({
98
- filename: id,
99
- source: src,
100
- componentDocs,
101
- ...generateOptions
102
- });
103
- return res;
104
- } catch (_e) {
105
- return src;
106
- }
107
- });
108
- const close = ()=>closeWatch?.();
109
- api.onCloseBuild(close);
110
- api.onCloseDevServer(close);
111
- }
112
- };
113
- };
114
- export default react_docgen_typescript;