@renr/parcel-reporter-docgen 0.1.0-alpha.5 → 0.1.0-beta.10

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/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # @renr/parcel-reporter-docgen
2
+
3
+ A Parcel reporter plugin that extracts UI component documentation and prop types as JSON using `react-docgen-typescript`.
4
+
5
+ ## Features
6
+
7
+ - **Automated Prop Extraction**: Parses component props, types, descriptions, default values, and required status.
8
+ - **Compound Component Support**: Handles dot-notation subcomponents (`Dialog.Title`) and `Object.assign` assignment patterns (`Object.assign(Base, { Sub })`).
9
+ - **Incremental Caching**: Tracks file modification times (`mtime`) to only reparse changed components in watch mode.
10
+ - **Configurable TSConfig**: Supports custom `tsconfig.json` paths for complex workspaces.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add -D @renr/parcel-reporter-docgen
16
+ # or
17
+ npm install -D @renr/parcel-reporter-docgen
18
+ # or
19
+ yarn add -D @renr/parcel-reporter-docgen
20
+ ```
21
+
22
+ ## Setup
23
+
24
+ ### 1. Add to `.parcelrc`
25
+
26
+ Add `@renr/parcel-reporter-docgen` to your `.parcelrc` reporters:
27
+
28
+ ```json
29
+ {
30
+ "extends": "@parcel/config-default",
31
+ "reporters": ["...", "@renr/parcel-reporter-docgen"]
32
+ }
33
+ ```
34
+
35
+ ### 2. Configure in `package.json`
36
+
37
+ Add the `@renr/parcel-reporter-docgen` configuration object to your `package.json`:
38
+
39
+ ```json
40
+ {
41
+ "@renr/parcel-reporter-docgen": {
42
+ "source": "src/components/**/*.{ts,tsx}",
43
+ "output": "docs/components",
44
+ "tsconfig": "./tsconfig.json"
45
+ }
46
+ }
47
+ ```
48
+
49
+ ### Options
50
+
51
+ | Option | Type | Required | Default | Description |
52
+ | ---------- | -------- | -------- | ------------------- | --------------------------------------------------------------------- |
53
+ | `source` | `string` | **Yes** | - | Glob pattern for component source files |
54
+ | `output` | `string` | No | `"docgen"` | Directory where JSON documentation files will be saved |
55
+ | `tsconfig` | `string` | No | `"./tsconfig.json"` | Relative path to the TypeScript config file to use for docgen parsing |
56
+
57
+ ## Output Format
58
+
59
+ For each component, a JSON file `<ComponentName>.json` is generated:
60
+
61
+ ```json
62
+ {
63
+ "name": "Counter",
64
+ "description": "A counter client component with custom starting value.",
65
+ "path": "src/components/Counter.tsx",
66
+ "fileName": "Counter.tsx",
67
+ "props": {
68
+ "initialCount": {
69
+ "name": "initialCount",
70
+ "required": false,
71
+ "type": { "name": "number | undefined" },
72
+ "defaultValue": { "value": "0" },
73
+ "description": "Initial number to start counting from.",
74
+ "shortPropTypeName": "number"
75
+ }
76
+ },
77
+ "subcomponents": {
78
+ "Button": {
79
+ "name": "Counter.Button",
80
+ "props": { ... }
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ ## License
87
+
88
+ MIT
@@ -8,8 +8,8 @@ import ts from "typescript";
8
8
  const __filename = fileURLToPath(import.meta.url);
9
9
  path.dirname(__filename);
10
10
  const fileMtimeCache = /* @__PURE__ */ new Map();
11
- async function generateProps(pagesPattern, rootDir, outputPath, log = console.log) {
12
- const files = await glob(pagesPattern, { cwd: rootDir });
11
+ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log = console.log, customTsconfigPath) {
12
+ const files = (await glob(pagesPattern, { cwd: rootDir })).sort(compareStrings);
13
13
  if (files.length === 0) {
14
14
  log(`No files found for pattern: ${pagesPattern}`);
15
15
  return;
@@ -43,9 +43,10 @@ async function generateProps(pagesPattern, rootDir, outputPath, log = console.lo
43
43
  }
44
44
  if (filesToProcess.length === 0) return;
45
45
  log(`Found ${filesToProcess.length} changed file(s) for pattern: ${pagesPattern}`);
46
- const tsconfigPath = path.resolve(rootDir, "./tsconfig.json");
47
- const docgenParser = withCustomConfig(tsconfigPath, {
46
+ const resolvedTsconfigPath = customTsconfigPath ? path.resolve(rootDir, customTsconfigPath) : path.resolve(rootDir, "./tsconfig.json");
47
+ const docgenParser = withCustomConfig(resolvedTsconfigPath, {
48
48
  shouldExtractLiteralValuesFromEnum: true,
49
+ shouldSortUnions: true,
49
50
  savePropValueAsString: true,
50
51
  propFilter: (prop) => {
51
52
  if (Array.isArray(prop.declarations) && prop.declarations[0]) {
@@ -70,31 +71,41 @@ async function generateProps(pagesPattern, rootDir, outputPath, log = console.lo
70
71
  log(`parsing file: : ${relFile}`);
71
72
  const fileDocs = docsByFilePath.get(path.resolve(absPath)) || [];
72
73
  const assignedInfo = getAssignedInfo(await fs.readFile(absPath, "utf-8"), componentName);
73
- const primaryDoc = fileDocs.find((d) => d.displayName === componentName) || (assignedInfo.baseIdentifier ? fileDocs.find((d) => d.displayName === assignedInfo.baseIdentifier) : void 0) || fileDocs.find((d) => Object.keys(d.props).length > 0) || fileDocs[0];
74
+ const usedDocs = /* @__PURE__ */ new Set();
75
+ let primaryDoc = fileDocs.find((d) => d.displayName === componentName) || (assignedInfo.baseIdentifier ? fileDocs.find((d) => d.displayName === assignedInfo.baseIdentifier) : void 0);
76
+ if (primaryDoc) usedDocs.add(primaryDoc);
74
77
  let primaryProps = primaryDoc ? primaryDoc.props : {};
75
- if (assignedInfo.baseIdentifier && primaryDoc && primaryDoc.displayName === componentName) {
78
+ if (assignedInfo.baseIdentifier) {
76
79
  const baseDoc = fileDocs.find((d) => d.displayName === assignedInfo.baseIdentifier);
77
- if (baseDoc && Object.keys(baseDoc.props).length > Object.keys(primaryProps).length) primaryProps = baseDoc.props;
80
+ if (baseDoc) {
81
+ if (assignedInfo.baseIdentifier !== assignedInfo.subcomponentsMap.get("Root")) usedDocs.add(baseDoc);
82
+ if (primaryDoc && Object.keys(baseDoc.props).length > Object.keys(primaryProps).length) primaryProps = baseDoc.props;
83
+ }
78
84
  }
79
- const formattedPrimaryProps = formatProps(primaryProps);
80
85
  const subcomponents = {};
81
86
  for (const [subName, targetName] of assignedInfo.subcomponentsMap) {
82
- const subDoc = fileDocs.find((d) => d.displayName === targetName || d.displayName === `${componentName}.${subName}`);
83
- if (subDoc) subcomponents[subName] = {
84
- name: `${componentName}.${subName}`,
85
- description: subDoc.description || void 0,
86
- props: formatProps(subDoc.props)
87
- };
87
+ if (subName === componentName) continue;
88
+ const subDoc = fileDocs.find((d) => d.displayName === targetName || d.displayName === `${componentName}.${subName}` || d.displayName === `${componentName}${subName}` || d.displayName === subName);
89
+ if (subDoc) {
90
+ usedDocs.add(subDoc);
91
+ subcomponents[subName] = {
92
+ name: `${componentName}.${subName}`,
93
+ description: subDoc.description || void 0,
94
+ props: formatProps(subDoc.props)
95
+ };
96
+ }
88
97
  }
98
+ const hasRoot = Boolean(subcomponents.Root) || fileDocs.some((d) => d.displayName === "Root" || d.displayName === `${componentName}Root` || d.displayName === `${componentName}.Root`);
89
99
  for (const doc of fileDocs) {
90
- if (doc === primaryDoc) continue;
91
- if (assignedInfo.baseIdentifier && doc.displayName === assignedInfo.baseIdentifier) continue;
100
+ if (usedDocs.has(doc)) continue;
92
101
  let subName;
93
102
  if (doc.displayName.startsWith(`${componentName}.`)) subName = doc.displayName.slice(componentName.length + 1);
94
- else if (doc.displayName.startsWith(componentName)) subName = doc.displayName.slice(componentName.length);
95
- if (subName) {
103
+ else if (doc.displayName.startsWith(componentName) && doc.displayName.length > componentName.length) subName = doc.displayName.slice(componentName.length);
104
+ else if (hasRoot) subName = doc.displayName;
105
+ if (subName && subName !== componentName) {
96
106
  const existing = subcomponents[subName];
97
107
  if (existing && Object.keys(existing.props).length >= Object.keys(doc.props).length) continue;
108
+ usedDocs.add(doc);
98
109
  subcomponents[subName] = {
99
110
  name: `${componentName}.${subName}`,
100
111
  description: doc.description || void 0,
@@ -102,11 +113,18 @@ async function generateProps(pagesPattern, rootDir, outputPath, log = console.lo
102
113
  };
103
114
  }
104
115
  }
116
+ const promotedRoot = !(Boolean(primaryDoc) && Object.keys(primaryProps).length > 0 && (primaryDoc === null || primaryDoc === void 0 ? void 0 : primaryDoc.displayName) !== "Root" && (primaryDoc === null || primaryDoc === void 0 ? void 0 : primaryDoc.displayName) !== `${componentName}Root` && (primaryDoc === null || primaryDoc === void 0 ? void 0 : primaryDoc.displayName) !== `${componentName}.Root` && assignedInfo.baseIdentifier !== assignedInfo.subcomponentsMap.get("Root")) && subcomponents.Root ? subcomponents.Root : void 0;
117
+ if (promotedRoot) delete subcomponents.Root;
118
+ else if (!primaryDoc) {
119
+ primaryDoc = fileDocs.find((d) => Object.keys(d.props).length > 0) || fileDocs[0];
120
+ primaryProps = primaryDoc ? primaryDoc.props : {};
121
+ }
122
+ const formattedPrimaryProps = promotedRoot ? promotedRoot.props : formatProps(primaryProps);
105
123
  const componentJSON = JSON.stringify({
106
- name: componentName,
107
- description: (primaryDoc === null || primaryDoc === void 0 ? void 0 : primaryDoc.description) || void 0,
108
- path: relFile,
109
- fileName: relFile.split("/").pop(),
124
+ name: promotedRoot ? promotedRoot.name : componentName,
125
+ description: (promotedRoot ? promotedRoot.description : primaryDoc === null || primaryDoc === void 0 ? void 0 : primaryDoc.description) || void 0,
126
+ path: relFile.replace(/\\/g, "/"),
127
+ fileName: path.basename(relFile),
110
128
  props: formattedPrimaryProps,
111
129
  subcomponents: Object.keys(subcomponents).length > 0 ? subcomponents : void 0
112
130
  }, null, 2);
@@ -144,16 +162,66 @@ function getShortPropType(name, type) {
144
162
  detailedType: true
145
163
  };
146
164
  }
165
+ function compareStrings(a, b) {
166
+ return a < b ? -1 : a > b ? 1 : 0;
167
+ }
168
+ function sortUnionString(str) {
169
+ if (!str.includes("|")) return str;
170
+ const parts = [];
171
+ let current = "";
172
+ let depthParen = 0;
173
+ let depthAngle = 0;
174
+ let depthBrace = 0;
175
+ let depthBracket = 0;
176
+ let inQuote = null;
177
+ for (let i = 0; i < str.length; i++) {
178
+ const ch = str[i];
179
+ if (inQuote) {
180
+ current += ch;
181
+ if (ch === inQuote && str[i - 1] !== "\\") inQuote = null;
182
+ continue;
183
+ }
184
+ if (ch === "\"" || ch === "'") {
185
+ inQuote = ch;
186
+ current += ch;
187
+ continue;
188
+ }
189
+ if (ch === "(") depthParen++;
190
+ else if (ch === ")") depthParen = Math.max(0, depthParen - 1);
191
+ else if (ch === "<") depthAngle++;
192
+ else if (ch === ">" && str[i - 1] !== "=") depthAngle = Math.max(0, depthAngle - 1);
193
+ else if (ch === "{") depthBrace++;
194
+ else if (ch === "}") depthBrace = Math.max(0, depthBrace - 1);
195
+ else if (ch === "[") depthBracket++;
196
+ else if (ch === "]") depthBracket = Math.max(0, depthBracket - 1);
197
+ if (ch === "|" && depthParen === 0 && depthAngle === 0 && depthBrace === 0 && depthBracket === 0) {
198
+ parts.push(current.trim());
199
+ current = "";
200
+ } else current += ch;
201
+ }
202
+ parts.push(current.trim());
203
+ if (parts.length <= 1) return str;
204
+ parts.sort((a, b) => {
205
+ if (a === "undefined" && b !== "undefined") return 1;
206
+ if (b === "undefined" && a !== "undefined") return -1;
207
+ return compareStrings(a, b);
208
+ });
209
+ return parts.join(" | ");
210
+ }
147
211
  function formatProps(rawProps) {
148
212
  const props = {};
149
- for (const propName in rawProps) {
213
+ const sortedPropNames = Object.keys(rawProps).sort(compareStrings);
214
+ for (const propName of sortedPropNames) {
150
215
  const rawProp = rawProps[propName];
151
216
  if (!rawProp) continue;
152
217
  const prop = { ...rawProp };
153
218
  if (prop.type && prop.type.name) {
154
- const { type: shortPropTypeName, detailedType } = getShortPropType(propName, prop.type.name);
219
+ prop.type = { ...prop.type };
220
+ if (typeof prop.type.raw === "string") prop.type.raw = sortUnionString(prop.type.raw);
221
+ const sortedTypeName = sortUnionString(prop.type.name);
222
+ const { type: shortPropTypeName, detailedType } = getShortPropType(propName, sortedTypeName);
155
223
  const hasExpandedType = Boolean(detailedType);
156
- prop.type.name = hasExpandedType && prop.type.name.split("|").length > 3 ? prop.type.name.split("|").map((line) => `| ${line}\n`).join("") : prop.type.name;
224
+ prop.type.name = hasExpandedType && sortedTypeName.split("|").length > 3 ? sortedTypeName.split("|").map((line) => `| ${line}\n`).join("") : sortedTypeName;
157
225
  prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;
158
226
  }
159
227
  props[propName] = prop;
@@ -165,6 +233,16 @@ function getAssignedInfo(sourceText, compName) {
165
233
  let baseIdentifier = null;
166
234
  const subcomponentsMap = /* @__PURE__ */ new Map();
167
235
  ts.forEachChild(sourceFile, (node) => {
236
+ if (ts.isExportDeclaration(node)) {
237
+ if (!node.isTypeOnly && node.exportClause && ts.isNamedExports(node.exportClause)) {
238
+ for (const element of node.exportClause.elements) if (!element.isTypeOnly && element.propertyName) {
239
+ const exportName = element.name.getText(sourceFile);
240
+ const localName = element.propertyName.getText(sourceFile);
241
+ if (exportName === compName) baseIdentifier = localName;
242
+ else if (/^[A-Z]/.test(exportName)) subcomponentsMap.set(exportName, localName);
243
+ }
244
+ }
245
+ }
168
246
  if (ts.isVariableStatement(node)) {
169
247
  for (const decl of node.declarationList.declarations) if (decl.name.getText(sourceFile) === compName && decl.initializer && ts.isCallExpression(decl.initializer)) {
170
248
  const call = decl.initializer;
@@ -173,12 +251,29 @@ function getAssignedInfo(sourceText, compName) {
173
251
  const firstArg = call.arguments[0];
174
252
  if (firstArg) baseIdentifier = firstArg.getText(sourceFile);
175
253
  if (call.arguments.length > 1 && ts.isObjectLiteralExpression(call.arguments[1])) {
176
- for (const prop of call.arguments[1].properties) if (ts.isPropertyAssignment(prop)) subcomponentsMap.set(prop.name.getText(sourceFile), prop.initializer.getText(sourceFile));
177
- else if (ts.isShorthandPropertyAssignment(prop)) subcomponentsMap.set(prop.name.getText(sourceFile), prop.name.getText(sourceFile));
254
+ for (const prop of call.arguments[1].properties) if (ts.isPropertyAssignment(prop)) {
255
+ const propName = prop.name.getText(sourceFile);
256
+ const initName = prop.initializer.getText(sourceFile);
257
+ subcomponentsMap.set(propName, initName);
258
+ } else if (ts.isShorthandPropertyAssignment(prop)) {
259
+ const propName = prop.name.getText(sourceFile);
260
+ subcomponentsMap.set(propName, propName);
261
+ }
178
262
  }
179
263
  }
180
264
  }
181
265
  }
266
+ if (ts.isExpressionStatement(node) && ts.isBinaryExpression(node.expression)) {
267
+ const bin = node.expression;
268
+ if (bin.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isPropertyAccessExpression(bin.left)) {
269
+ const objText = bin.left.expression.getText(sourceFile);
270
+ const propText = bin.left.name.getText(sourceFile);
271
+ if (objText === compName && /^[A-Z]/.test(propText)) {
272
+ const targetName = bin.right.getText(sourceFile);
273
+ subcomponentsMap.set(propText, targetName);
274
+ }
275
+ }
276
+ }
182
277
  });
183
278
  return {
184
279
  baseIdentifier,
@@ -1 +1 @@
1
- {"version":3,"file":"generate-props.mjs","names":[],"sources":["../../src/generate-props.ts"],"sourcesContent":["import fs from \"fs/promises\";\nimport path from \"path\";\nimport { PropItem, withCustomConfig } from \"react-docgen-typescript\";\nimport { glob } from \"tinyglobby\";\nimport ts from \"typescript\";\nimport { fileURLToPath } from \"url\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n// cache for watch mode across buildStart events\nconst fileMtimeCache = new Map<string, number>();\n\nexport async function generateProps(\n pagesPattern: string,\n rootDir: string,\n outputPath: string,\n log = console.log\n) {\n const files = await glob(pagesPattern, {\n cwd: rootDir,\n });\n\n if (files.length === 0) {\n log(`No files found for pattern: ${pagesPattern}`);\n return;\n }\n\n const resolvedOutputPath = path.resolve(rootDir, outputPath);\n await fs.mkdir(resolvedOutputPath, { recursive: true });\n\n const filesToProcess: {\n relFile: string;\n absPath: string;\n componentName: string;\n }[] = [];\n\n for (const file of files) {\n const filePath = path.resolve(rootDir, file);\n const componentName = path.basename(file, path.extname(file));\n const outputFilePath = path.join(\n resolvedOutputPath,\n `${componentName}.json`\n );\n\n try {\n const sourceStat = await fs.stat(filePath);\n const cachedMtime = fileMtimeCache.get(filePath);\n\n let isUpToDate = false;\n try {\n const outStat = await fs.stat(outputFilePath);\n if (\n (cachedMtime !== undefined && cachedMtime === sourceStat.mtimeMs) ||\n outStat.mtimeMs >= sourceStat.mtimeMs\n ) {\n isUpToDate = true;\n fileMtimeCache.set(filePath, sourceStat.mtimeMs);\n }\n } catch {\n // output file does not exist\n }\n\n if (isUpToDate) {\n continue;\n }\n\n filesToProcess.push({\n relFile: file,\n absPath: filePath,\n componentName,\n });\n fileMtimeCache.set(filePath, sourceStat.mtimeMs);\n } catch {\n // source file not accessible\n }\n }\n\n if (filesToProcess.length === 0) {\n return;\n }\n\n log(\n `Found ${filesToProcess.length} changed file(s) for pattern: ${pagesPattern}`\n );\n\n // TODO - should this be the root tsconfig, the parcel project tsconfig, or the ui library tsconfig?\n // TODO - make this configurable\n const tsconfigPath = path.resolve(rootDir, \"./tsconfig.json\");\n\n const docgenParser = withCustomConfig(tsconfigPath, {\n shouldExtractLiteralValuesFromEnum: true,\n savePropValueAsString: true,\n propFilter: (prop) => {\n if (Array.isArray(prop.declarations) && prop.declarations[0]) {\n const declaration = prop.declarations[0];\n\n if (declaration.fileName.includes(\"node_modules/@types/react\")) {\n if (prop.name !== \"ref\" && prop.name !== \"className\") {\n return false;\n }\n }\n }\n return true;\n },\n });\n\n try {\n const absPaths = filesToProcess.map((f) => f.absPath);\n const allDocs = docgenParser.parse(absPaths);\n\n const docsByFilePath = new Map<string, typeof allDocs>();\n for (const doc of allDocs) {\n if (doc.filePath) {\n const key = path.resolve(doc.filePath);\n const list = docsByFilePath.get(key) || [];\n list.push(doc);\n docsByFilePath.set(key, list);\n }\n }\n\n await Promise.all(\n filesToProcess.map(async ({ relFile, absPath, componentName }) => {\n log(`parsing file: : ${relFile}`);\n\n const fileDocs = docsByFilePath.get(path.resolve(absPath)) || [];\n\n // Check if the component was composed using Object.assign(Base, { SubName: Target, ... })\n const sourceText = await fs.readFile(absPath, \"utf-8\");\n const assignedInfo = getAssignedInfo(sourceText, componentName);\n\n // 1. Identify primary component doc matching componentName or assigned base\n const primaryDoc =\n fileDocs.find((d) => d.displayName === componentName) ||\n (assignedInfo.baseIdentifier\n ? fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n )\n : undefined) ||\n fileDocs.find((d) => Object.keys(d.props).length > 0) ||\n fileDocs[0];\n\n // If primaryDoc was created by Object.assign and lost props, recover from base\n let primaryProps = primaryDoc ? primaryDoc.props : {};\n if (\n assignedInfo.baseIdentifier &&\n primaryDoc &&\n primaryDoc.displayName === componentName\n ) {\n const baseDoc = fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n );\n if (\n baseDoc &&\n Object.keys(baseDoc.props).length > Object.keys(primaryProps).length\n ) {\n primaryProps = baseDoc.props;\n }\n }\n\n const formattedPrimaryProps = formatProps(primaryProps);\n\n // 2. Identify subcomponents\n const subcomponents: Record<\n string,\n {\n name: string;\n description?: string;\n props: ReturnType<typeof formatProps>;\n }\n > = {};\n\n // a) Handle subcomponents explicitly assigned via Object.assign(Base, { SubName: Target })\n for (const [subName, targetName] of assignedInfo.subcomponentsMap) {\n const subDoc = fileDocs.find(\n (d) =>\n d.displayName === targetName ||\n d.displayName === `${componentName}.${subName}`\n );\n if (subDoc) {\n subcomponents[subName] = {\n name: `${componentName}.${subName}`,\n description: subDoc.description || undefined,\n props: formatProps(subDoc.props),\n };\n }\n }\n\n // b) Handle subcomponents matching standard React dot notation or component prefix\n for (const doc of fileDocs) {\n if (doc === primaryDoc) continue;\n if (\n assignedInfo.baseIdentifier &&\n doc.displayName === assignedInfo.baseIdentifier\n ) {\n continue;\n }\n\n let subName: string | undefined;\n if (doc.displayName.startsWith(`${componentName}.`)) {\n subName = doc.displayName.slice(componentName.length + 1);\n } else if (doc.displayName.startsWith(componentName)) {\n subName = doc.displayName.slice(componentName.length);\n }\n\n if (subName) {\n const existing = subcomponents[subName];\n if (\n existing &&\n Object.keys(existing.props).length >=\n Object.keys(doc.props).length\n ) {\n continue;\n }\n\n subcomponents[subName] = {\n name: `${componentName}.${subName}`,\n description: doc.description || undefined,\n props: formatProps(doc.props),\n };\n }\n }\n\n const componentJSON = JSON.stringify(\n {\n name: componentName,\n description: primaryDoc?.description || undefined,\n path: relFile,\n fileName: relFile.split(\"/\").pop(),\n props: formattedPrimaryProps,\n subcomponents:\n Object.keys(subcomponents).length > 0 ? subcomponents : undefined,\n },\n null,\n 2\n );\n\n const outputFilePath = path.join(\n resolvedOutputPath,\n `${componentName}.json`\n );\n await fs.writeFile(outputFilePath, componentJSON + \"\\n\", \"utf-8\");\n\n log(`Generated props for ${componentName}`);\n })\n );\n } catch (err) {\n log(`Error generating props: ${(err as Error).message}`);\n }\n}\n\n// based on https://github.com/mui/base-ui/blob/master/docs/src/components/ReferenceTable/PropsReferenceAccordion.tsx\nfunction getShortPropType(name: string, type: string) {\n if (/^(on|get)[A-Z].*/.test(name)) {\n return { type: \"function\", detailedType: true };\n }\n\n if (type === undefined || type === null) {\n return { type: String(type), detailedType: false };\n }\n\n if (name === \"className\") {\n return { type: \"string | function\", detailedType: true };\n }\n\n if (name === \"render\") {\n return { type: \"ReactElement | function\", detailedType: true };\n }\n\n if (\n name.endsWith(\"Ref\") ||\n name === \"children\" ||\n type === \"boolean\" ||\n type === \"string\" ||\n type === \"number\" ||\n type.indexOf(\" | \") === -1 ||\n (type.split(\"|\").length < 3 && type.length < 30)\n ) {\n return { type, detailedType: false };\n }\n\n return { type: \"Union\", detailedType: true };\n}\n\nfunction formatProps(rawProps: Record<string, PropItem>) {\n const props: Record<\n string,\n PropItem & {\n shortPropTypeName: string | null;\n }\n > = {};\n\n for (const propName in rawProps) {\n const rawProp = rawProps[propName];\n if (!rawProp) {\n continue;\n }\n\n const prop = { ...rawProp } as PropItem & {\n shortPropTypeName: string | null;\n };\n\n if (prop.type && prop.type.name) {\n const { type: shortPropTypeName, detailedType } = getShortPropType(\n propName,\n prop.type.name\n );\n\n const hasExpandedType = Boolean(detailedType);\n\n prop.type.name =\n hasExpandedType && prop.type.name.split(\"|\").length > 3\n ? prop.type.name\n .split(\"|\")\n .map((line) => `| ${line}\\n`)\n .join(\"\")\n : prop.type.name;\n\n prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;\n }\n\n props[propName] = prop;\n }\n\n return props;\n}\n\nfunction getAssignedInfo(sourceText: string, compName: string) {\n const sourceFile = ts.createSourceFile(\n \"temp.tsx\",\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n let baseIdentifier: string | null = null;\n const subcomponentsMap = new Map<string, string>();\n\n ts.forEachChild(sourceFile, (node) => {\n if (ts.isVariableStatement(node)) {\n for (const decl of node.declarationList.declarations) {\n if (\n decl.name.getText(sourceFile) === compName &&\n decl.initializer &&\n ts.isCallExpression(decl.initializer)\n ) {\n const call = decl.initializer;\n const exprText = call.expression.getText(sourceFile);\n if (\n (exprText === \"Object.assign\" || exprText.endsWith(\".assign\")) &&\n call.arguments.length > 0\n ) {\n const firstArg = call.arguments[0];\n if (firstArg) {\n baseIdentifier = firstArg.getText(sourceFile);\n }\n if (\n call.arguments.length > 1 &&\n ts.isObjectLiteralExpression(call.arguments[1]!)\n ) {\n for (const prop of call.arguments[1]!.properties) {\n if (ts.isPropertyAssignment(prop)) {\n subcomponentsMap.set(\n prop.name.getText(sourceFile),\n prop.initializer.getText(sourceFile)\n );\n } else if (ts.isShorthandPropertyAssignment(prop)) {\n subcomponentsMap.set(\n prop.name.getText(sourceFile),\n prop.name.getText(sourceFile)\n );\n }\n }\n }\n }\n }\n }\n }\n });\n\n return { baseIdentifier, subcomponentsMap };\n}\n"],"mappings":";;;;;;;AAOA,MAAM,aAAa,cAAc,YAAY,GAAG;AAC9B,KAAK,QAAQ,UAAU;AAGzC,MAAM,iCAAiB,IAAI,IAAoB;AAE/C,eAAsB,cACpB,cACA,SACA,YACA,MAAM,QAAQ,KACd;CACA,MAAM,QAAQ,MAAM,KAAK,cAAc,EACrC,KAAK,QACP,CAAC;CAED,IAAI,MAAM,WAAW,GAAG;EACtB,IAAI,+BAA+B,cAAc;EACjD;CACF;CAEA,MAAM,qBAAqB,KAAK,QAAQ,SAAS,UAAU;CAC3D,MAAM,GAAG,MAAM,oBAAoB,EAAE,WAAW,KAAK,CAAC;CAEtD,MAAM,iBAI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,KAAK,gBAAgB,cACtC,IACE,KAAK,KAAK,QAAQ,UAAU,MAAM,YAClC,KAAK,eACL,GAAG,iBAAiB,KAAK,WAAW,GACpC;IACA,MAAM,OAAO,KAAK;IAClB,MAAM,WAAW,KAAK,WAAW,QAAQ,UAAU;IACnD,KACG,aAAa,mBAAmB,SAAS,SAAS,SAAS,MAC5D,KAAK,UAAU,SAAS,GACxB;KACA,MAAM,WAAW,KAAK,UAAU;KAChC,IAAI,UACF,iBAAiB,SAAS,QAAQ,UAAU;KAE9C,IACE,KAAK,UAAU,SAAS,KACxB,GAAG,0BAA0B,KAAK,UAAU,EAAG,GAE1C;WAAA,MAAM,QAAQ,KAAK,UAAU,EAAE,CAAE,YACpC,IAAI,GAAG,qBAAqB,IAAI,GAC9B,iBAAiB,IACf,KAAK,KAAK,QAAQ,UAAU,GAC5B,KAAK,YAAY,QAAQ,UAAU,CACrC;WACK,IAAI,GAAG,8BAA8B,IAAI,GAC9C,iBAAiB,IACf,KAAK,KAAK,QAAQ,UAAU,GAC5B,KAAK,KAAK,QAAQ,UAAU,CAC9B;KAAA;IAIR;GACF;;CAGN,CAAC;CAED,OAAO;EAAE;EAAgB;CAAiB;AAC5C"}
1
+ {"version":3,"file":"generate-props.mjs","names":[],"sources":["../../src/generate-props.ts"],"sourcesContent":["import fs from \"fs/promises\";\nimport path from \"path\";\nimport { PropItem, withCustomConfig } from \"react-docgen-typescript\";\nimport { glob } from \"tinyglobby\";\nimport ts from \"typescript\";\nimport { fileURLToPath } from \"url\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\n// cache for watch mode across buildStart events\nconst fileMtimeCache = new Map<string, number>();\n\nexport async function generateProps(\n pagesPattern: string,\n rootDir: string,\n outputPath: string = \"docgen\",\n log: (...args: unknown[]) => void = console.log,\n customTsconfigPath?: string\n) {\n const files = (\n await glob(pagesPattern, {\n cwd: rootDir,\n })\n ).sort(compareStrings);\n\n if (files.length === 0) {\n log(`No files found for pattern: ${pagesPattern}`);\n return;\n }\n\n const resolvedOutputPath = path.resolve(rootDir, outputPath);\n await fs.mkdir(resolvedOutputPath, { recursive: true });\n\n const filesToProcess: {\n relFile: string;\n absPath: string;\n componentName: string;\n }[] = [];\n\n for (const file of files) {\n const filePath = path.resolve(rootDir, file);\n const componentName = path.basename(file, path.extname(file));\n const outputFilePath = path.join(\n resolvedOutputPath,\n `${componentName}.json`\n );\n\n try {\n const sourceStat = await fs.stat(filePath);\n const cachedMtime = fileMtimeCache.get(filePath);\n\n let isUpToDate = false;\n try {\n const outStat = await fs.stat(outputFilePath);\n if (\n (cachedMtime !== undefined && cachedMtime === sourceStat.mtimeMs) ||\n outStat.mtimeMs >= sourceStat.mtimeMs\n ) {\n isUpToDate = true;\n fileMtimeCache.set(filePath, sourceStat.mtimeMs);\n }\n } catch {\n // output file does not exist\n }\n\n if (isUpToDate) {\n continue;\n }\n\n filesToProcess.push({\n relFile: file,\n absPath: filePath,\n componentName,\n });\n fileMtimeCache.set(filePath, sourceStat.mtimeMs);\n } catch {\n // source file not accessible\n }\n }\n\n if (filesToProcess.length === 0) {\n return;\n }\n\n log(\n `Found ${filesToProcess.length} changed file(s) for pattern: ${pagesPattern}`\n );\n\n const resolvedTsconfigPath = customTsconfigPath\n ? path.resolve(rootDir, customTsconfigPath)\n : path.resolve(rootDir, \"./tsconfig.json\");\n\n const docgenParser = withCustomConfig(resolvedTsconfigPath, {\n shouldExtractLiteralValuesFromEnum: true,\n shouldSortUnions: true,\n savePropValueAsString: true,\n propFilter: (prop) => {\n if (Array.isArray(prop.declarations) && prop.declarations[0]) {\n const declaration = prop.declarations[0];\n\n if (declaration.fileName.includes(\"node_modules/@types/react\")) {\n if (prop.name !== \"ref\" && prop.name !== \"className\") {\n return false;\n }\n }\n }\n return true;\n },\n });\n\n try {\n const absPaths = filesToProcess.map((f) => f.absPath);\n const allDocs = docgenParser.parse(absPaths);\n\n const docsByFilePath = new Map<string, typeof allDocs>();\n for (const doc of allDocs) {\n if (doc.filePath) {\n const key = path.resolve(doc.filePath);\n const list = docsByFilePath.get(key) || [];\n list.push(doc);\n docsByFilePath.set(key, list);\n }\n }\n\n await Promise.all(\n filesToProcess.map(async ({ relFile, absPath, componentName }) => {\n log(`parsing file: : ${relFile}`);\n\n const fileDocs = docsByFilePath.get(path.resolve(absPath)) || [];\n\n // Check if the component was composed using Object.assign or exports compound parts\n const sourceText = await fs.readFile(absPath, \"utf-8\");\n const assignedInfo = getAssignedInfo(sourceText, componentName);\n\n const usedDocs = new Set<(typeof fileDocs)[number]>();\n\n // 1. Identify explicit primary component doc matching componentName or assigned base\n let primaryDoc =\n fileDocs.find((d) => d.displayName === componentName) ||\n (assignedInfo.baseIdentifier\n ? fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n )\n : undefined);\n\n if (primaryDoc) {\n usedDocs.add(primaryDoc);\n }\n\n // If primaryDoc was created by Object.assign and lost props, recover from base\n let primaryProps = primaryDoc ? primaryDoc.props : {};\n if (assignedInfo.baseIdentifier) {\n const baseDoc = fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n );\n if (baseDoc) {\n if (\n assignedInfo.baseIdentifier !==\n assignedInfo.subcomponentsMap.get(\"Root\")\n ) {\n usedDocs.add(baseDoc);\n }\n if (\n primaryDoc &&\n Object.keys(baseDoc.props).length >\n Object.keys(primaryProps).length\n ) {\n primaryProps = baseDoc.props;\n }\n }\n }\n\n // 2. Identify subcomponents (including Root if present)\n const subcomponents: Record<\n string,\n {\n name: string;\n description?: string;\n props: ReturnType<typeof formatProps>;\n }\n > = {};\n\n // a) Handle subcomponents explicitly assigned or exported\n for (const [subName, targetName] of assignedInfo.subcomponentsMap) {\n if (subName === componentName) continue;\n const subDoc = fileDocs.find(\n (d) =>\n d.displayName === targetName ||\n d.displayName === `${componentName}.${subName}` ||\n d.displayName === `${componentName}${subName}` ||\n d.displayName === subName\n );\n if (subDoc) {\n usedDocs.add(subDoc);\n subcomponents[subName] = {\n name: `${componentName}.${subName}`,\n description: subDoc.description || undefined,\n props: formatProps(subDoc.props),\n };\n }\n }\n\n const hasRoot =\n Boolean(subcomponents.Root) ||\n fileDocs.some(\n (d) =>\n d.displayName === \"Root\" ||\n d.displayName === `${componentName}Root` ||\n d.displayName === `${componentName}.Root`\n );\n\n // b) Handle subcomponents matching standard React dot notation or component prefix\n for (const doc of fileDocs) {\n if (usedDocs.has(doc)) continue;\n\n let subName: string | undefined;\n if (doc.displayName.startsWith(`${componentName}.`)) {\n subName = doc.displayName.slice(componentName.length + 1);\n } else if (\n doc.displayName.startsWith(componentName) &&\n doc.displayName.length > componentName.length\n ) {\n subName = doc.displayName.slice(componentName.length);\n } else if (hasRoot) {\n subName = doc.displayName;\n }\n\n if (subName && subName !== componentName) {\n const existing = subcomponents[subName];\n if (\n existing &&\n Object.keys(existing.props).length >=\n Object.keys(doc.props).length\n ) {\n continue;\n }\n\n usedDocs.add(doc);\n subcomponents[subName] = {\n name: `${componentName}.${subName}`,\n description: doc.description || undefined,\n props: formatProps(doc.props),\n };\n }\n }\n\n const hasDistinctPrimary =\n Boolean(primaryDoc) &&\n Object.keys(primaryProps).length > 0 &&\n primaryDoc?.displayName !== \"Root\" &&\n primaryDoc?.displayName !== `${componentName}Root` &&\n primaryDoc?.displayName !== `${componentName}.Root` &&\n assignedInfo.baseIdentifier !==\n assignedInfo.subcomponentsMap.get(\"Root\");\n\n // Promote Root subcomponent to primary component only when no distinct primary component exists\n const promotedRoot =\n !hasDistinctPrimary && subcomponents.Root\n ? subcomponents.Root\n : undefined;\n if (promotedRoot) {\n delete subcomponents.Root;\n } else if (!primaryDoc) {\n primaryDoc =\n fileDocs.find((d) => Object.keys(d.props).length > 0) ||\n fileDocs[0];\n primaryProps = primaryDoc ? primaryDoc.props : {};\n }\n\n const formattedPrimaryProps = promotedRoot\n ? promotedRoot.props\n : formatProps(primaryProps);\n\n const componentJSON = JSON.stringify(\n {\n name: promotedRoot ? promotedRoot.name : componentName,\n description:\n (promotedRoot\n ? promotedRoot.description\n : primaryDoc?.description) || undefined,\n path: relFile.replace(/\\\\/g, \"/\"),\n fileName: path.basename(relFile),\n props: formattedPrimaryProps,\n subcomponents:\n Object.keys(subcomponents).length > 0 ? subcomponents : undefined,\n },\n null,\n 2\n );\n\n const outputFilePath = path.join(\n resolvedOutputPath,\n `${componentName}.json`\n );\n await fs.writeFile(outputFilePath, componentJSON + \"\\n\", \"utf-8\");\n\n log(`Generated props for ${componentName}`);\n })\n );\n } catch (err) {\n log(`Error generating props: ${(err as Error).message}`);\n }\n}\n\n// based on https://github.com/mui/base-ui/blob/master/docs/src/components/ReferenceTable/PropsReferenceAccordion.tsx\nfunction getShortPropType(name: string, type: string) {\n if (/^(on|get)[A-Z].*/.test(name)) {\n return { type: \"function\", detailedType: true };\n }\n\n if (type === undefined || type === null) {\n return { type: String(type), detailedType: false };\n }\n\n if (name === \"className\") {\n return { type: \"string | function\", detailedType: true };\n }\n\n if (name === \"render\") {\n return { type: \"ReactElement | function\", detailedType: true };\n }\n\n if (\n name.endsWith(\"Ref\") ||\n name === \"children\" ||\n type === \"boolean\" ||\n type === \"string\" ||\n type === \"number\" ||\n type.indexOf(\" | \") === -1 ||\n (type.split(\"|\").length < 3 && type.length < 30)\n ) {\n return { type, detailedType: false };\n }\n\n return { type: \"Union\", detailedType: true };\n}\n\nfunction compareStrings(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n\nfunction sortUnionString(str: string): string {\n if (!str.includes(\"|\")) {\n return str;\n }\n\n const parts: string[] = [];\n let current = \"\";\n let depthParen = 0;\n let depthAngle = 0;\n let depthBrace = 0;\n let depthBracket = 0;\n let inQuote: string | null = null;\n\n for (let i = 0; i < str.length; i++) {\n const ch = str[i]!;\n if (inQuote) {\n current += ch;\n if (ch === inQuote && str[i - 1] !== \"\\\\\") {\n inQuote = null;\n }\n continue;\n }\n\n if (ch === '\"' || ch === \"'\") {\n inQuote = ch;\n current += ch;\n continue;\n }\n\n if (ch === \"(\") depthParen++;\n else if (ch === \")\") depthParen = Math.max(0, depthParen - 1);\n else if (ch === \"<\") depthAngle++;\n else if (ch === \">\" && str[i - 1] !== \"=\")\n depthAngle = Math.max(0, depthAngle - 1);\n else if (ch === \"{\") depthBrace++;\n else if (ch === \"}\") depthBrace = Math.max(0, depthBrace - 1);\n else if (ch === \"[\") depthBracket++;\n else if (ch === \"]\") depthBracket = Math.max(0, depthBracket - 1);\n\n if (\n ch === \"|\" &&\n depthParen === 0 &&\n depthAngle === 0 &&\n depthBrace === 0 &&\n depthBracket === 0\n ) {\n parts.push(current.trim());\n current = \"\";\n } else {\n current += ch;\n }\n }\n\n parts.push(current.trim());\n\n if (parts.length <= 1) {\n return str;\n }\n\n parts.sort((a, b) => {\n if (a === \"undefined\" && b !== \"undefined\") return 1;\n if (b === \"undefined\" && a !== \"undefined\") return -1;\n return compareStrings(a, b);\n });\n\n return parts.join(\" | \");\n}\n\nfunction formatProps(rawProps: Record<string, PropItem>) {\n const props: Record<\n string,\n PropItem & {\n shortPropTypeName: string | null;\n }\n > = {};\n\n const sortedPropNames = Object.keys(rawProps).sort(compareStrings);\n\n for (const propName of sortedPropNames) {\n const rawProp = rawProps[propName];\n if (!rawProp) {\n continue;\n }\n\n const prop = { ...rawProp } as PropItem & {\n shortPropTypeName: string | null;\n };\n\n if (prop.type && prop.type.name) {\n prop.type = { ...prop.type };\n\n if (typeof prop.type.raw === \"string\") {\n prop.type.raw = sortUnionString(prop.type.raw);\n }\n\n const sortedTypeName = sortUnionString(prop.type.name);\n const { type: shortPropTypeName, detailedType } = getShortPropType(\n propName,\n sortedTypeName\n );\n\n const hasExpandedType = Boolean(detailedType);\n\n prop.type.name =\n hasExpandedType && sortedTypeName.split(\"|\").length > 3\n ? sortedTypeName\n .split(\"|\")\n .map((line) => `| ${line}\\n`)\n .join(\"\")\n : sortedTypeName;\n\n prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;\n }\n\n props[propName] = prop;\n }\n\n return props;\n}\n\nfunction getAssignedInfo(sourceText: string, compName: string) {\n const sourceFile = ts.createSourceFile(\n \"temp.tsx\",\n sourceText,\n ts.ScriptTarget.Latest,\n true\n );\n let baseIdentifier: string | null = null;\n const subcomponentsMap = new Map<string, string>();\n\n ts.forEachChild(sourceFile, (node) => {\n // 1. export { Local as Exported, ... }\n if (ts.isExportDeclaration(node)) {\n if (\n !node.isTypeOnly &&\n node.exportClause &&\n ts.isNamedExports(node.exportClause)\n ) {\n for (const element of node.exportClause.elements) {\n if (!element.isTypeOnly && element.propertyName) {\n const exportName = element.name.getText(sourceFile);\n const localName = element.propertyName.getText(sourceFile);\n if (exportName === compName) {\n baseIdentifier = localName;\n } else if (/^[A-Z]/.test(exportName)) {\n subcomponentsMap.set(exportName, localName);\n }\n }\n }\n }\n }\n\n // 2. export const Comp = Object.assign(Base, { SubName: Target, ... })\n if (ts.isVariableStatement(node)) {\n for (const decl of node.declarationList.declarations) {\n if (\n decl.name.getText(sourceFile) === compName &&\n decl.initializer &&\n ts.isCallExpression(decl.initializer)\n ) {\n const call = decl.initializer;\n const exprText = call.expression.getText(sourceFile);\n if (\n (exprText === \"Object.assign\" || exprText.endsWith(\".assign\")) &&\n call.arguments.length > 0\n ) {\n const firstArg = call.arguments[0];\n if (firstArg) {\n baseIdentifier = firstArg.getText(sourceFile);\n }\n if (\n call.arguments.length > 1 &&\n ts.isObjectLiteralExpression(call.arguments[1]!)\n ) {\n for (const prop of call.arguments[1]!.properties) {\n if (ts.isPropertyAssignment(prop)) {\n const propName = prop.name.getText(sourceFile);\n const initName = prop.initializer.getText(sourceFile);\n subcomponentsMap.set(propName, initName);\n } else if (ts.isShorthandPropertyAssignment(prop)) {\n const propName = prop.name.getText(sourceFile);\n subcomponentsMap.set(propName, propName);\n }\n }\n }\n }\n }\n }\n }\n\n // 3. Comp.Sub = Target\n if (\n ts.isExpressionStatement(node) &&\n ts.isBinaryExpression(node.expression)\n ) {\n const bin = node.expression;\n if (\n bin.operatorToken.kind === ts.SyntaxKind.EqualsToken &&\n ts.isPropertyAccessExpression(bin.left)\n ) {\n const objText = bin.left.expression.getText(sourceFile);\n const propText = bin.left.name.getText(sourceFile);\n if (objText === compName && /^[A-Z]/.test(propText)) {\n const targetName = bin.right.getText(sourceFile);\n subcomponentsMap.set(propText, targetName);\n }\n }\n }\n });\n\n return { baseIdentifier, subcomponentsMap };\n}\n"],"mappings":";;;;;;;AAOA,MAAM,aAAa,cAAc,YAAY,GAAG;AAC9B,KAAK,QAAQ,UAAU;AAGzC,MAAM,iCAAiB,IAAI,IAAoB;AAE/C,eAAsB,cACpB,cACA,SACA,aAAqB,UACrB,MAAoC,QAAQ,KAC5C,oBACA;CACA,MAAM,SACJ,MAAM,KAAK,cAAc,EACvB,KAAK,QACP,CAAC,EAAA,CACD,KAAK,cAAc;CAErB,IAAI,MAAM,WAAW,GAAG;EACtB,IAAI,+BAA+B,cAAc;EACjD;CACF;CAEA,MAAM,qBAAqB,KAAK,QAAQ,SAAS,UAAU;CAC3D,MAAM,GAAG,MAAM,oBAAoB,EAAE,WAAW,KAAK,CAAC;CAEtD,MAAM,iBAIA,CAAC;CAEP,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAW,KAAK,QAAQ,SAAS,IAAI;EAC3C,MAAM,gBAAgB,KAAK,SAAS,MAAM,KAAK,QAAQ,IAAI,CAAC;EAC5D,MAAM,iBAAiB,KAAK,KAC1B,oBACA,GAAG,cAAc,MACnB;EAEA,IAAI;GACF,MAAM,aAAa,MAAM,GAAG,KAAK,QAAQ;GACzC,MAAM,cAAc,eAAe,IAAI,QAAQ;GAE/C,IAAI,aAAa;GACjB,IAAI;IACF,MAAM,UAAU,MAAM,GAAG,KAAK,cAAc;IAC5C,IACG,gBAAgB,KAAA,KAAa,gBAAgB,WAAW,WACzD,QAAQ,WAAW,WAAW,SAC9B;KACA,aAAa;KACb,eAAe,IAAI,UAAU,WAAW,OAAO;IACjD;GACF,SAAA,SAAQ,CAER;GAEA,IAAI,YACF;GAGF,eAA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,GAAG,iBAAiB,KAAK,WAAW,GACpC;IACA,MAAM,OAAO,KAAK;IAClB,MAAM,WAAW,KAAK,WAAW,QAAQ,UAAU;IACnD,KACG,aAAa,mBAAmB,SAAS,SAAS,SAAS,MAC5D,KAAK,UAAU,SAAS,GACxB;KACA,MAAM,WAAW,KAAK,UAAU;KAChC,IAAI,UACF,iBAAiB,SAAS,QAAQ,UAAU;KAE9C,IACE,KAAK,UAAU,SAAS,KACxB,GAAG,0BAA0B,KAAK,UAAU,EAAG,GAE1C;WAAA,MAAM,QAAQ,KAAK,UAAU,EAAE,CAAE,YACpC,IAAI,GAAG,qBAAqB,IAAI,GAAG;OACjC,MAAM,WAAW,KAAK,KAAK,QAAQ,UAAU;OAC7C,MAAM,WAAW,KAAK,YAAY,QAAQ,UAAU;OACpD,iBAAiB,IAAI,UAAU,QAAQ;MACzC,OAAO,IAAI,GAAG,8BAA8B,IAAI,GAAG;OACjD,MAAM,WAAW,KAAK,KAAK,QAAQ,UAAU;OAC7C,iBAAiB,IAAI,UAAU,QAAQ;MACzC;;IAGN;GACF;;EAKJ,IACE,GAAG,sBAAsB,IAAI,KAC7B,GAAG,mBAAmB,KAAK,UAAU,GACrC;GACA,MAAM,MAAM,KAAK;GACjB,IACE,IAAI,cAAc,SAAS,GAAG,WAAW,eACzC,GAAG,2BAA2B,IAAI,IAAI,GACtC;IACA,MAAM,UAAU,IAAI,KAAK,WAAW,QAAQ,UAAU;IACtD,MAAM,WAAW,IAAI,KAAK,KAAK,QAAQ,UAAU;IACjD,IAAI,YAAY,YAAY,SAAS,KAAK,QAAQ,GAAG;KACnD,MAAM,aAAa,IAAI,MAAM,QAAQ,UAAU;KAC/C,iBAAiB,IAAI,UAAU,UAAU;IAC3C;GACF;EACF;CACF,CAAC;CAED,OAAO;EAAE;EAAgB;CAAiB;AAC5C"}
@@ -10,12 +10,13 @@ const origin = name;
10
10
  var src_default = new Reporter({ async report({ event, options, logger }) {
11
11
  if (event.type === "buildStart") {
12
12
  try {
13
- var _config$origin, _config$origin2;
14
- const packageJSON = path.join(options.projectRoot, "package.json");
15
- const config = await import(pathToFileURL(packageJSON).toString(), { with: { type: "json" } }).then((mod) => mod.default);
13
+ var _config$origin, _config$origin2, _config$origin3;
14
+ const projectPackageJSON = path.join(options.projectRoot, "package.json");
15
+ const config = await import(pathToFileURL(projectPackageJSON).toString(), { with: { type: "json" } }).then((mod) => mod.default);
16
16
  const source = (_config$origin = config[origin]) === null || _config$origin === void 0 ? void 0 : _config$origin.source;
17
17
  const output = (_config$origin2 = config[origin]) === null || _config$origin2 === void 0 ? void 0 : _config$origin2.output;
18
- if (!source) throw new ThrowableDiagnostic.default({ diagnostic: {
18
+ const tsconfig = (_config$origin3 = config[origin]) === null || _config$origin3 === void 0 ? void 0 : _config$origin3.tsconfig;
19
+ if (!source) throw new ThrowableDiagnostic({ diagnostic: {
19
20
  origin,
20
21
  message: dedent`No "@renr/parcel-reporter-docgen" source found in package.json.
21
22
  NOTE: if you are using a monorepo, you need to run parcel from the package that contains your pages rather than the project root.
@@ -34,7 +35,7 @@ var src_default = new Reporter({ async report({ event, options, logger }) {
34
35
  message: "Add a \"@renr/parcel-reporter-docgen\" source to generate docs for your UI components."
35
36
  }],
36
37
  language: "json",
37
- filePath: packageJSON,
38
+ filePath: projectPackageJSON,
38
39
  code: dedent`{
39
40
  "@renr/parcel-reporter-docgen": {
40
41
  "source": "../packages/ui/src/**/*.{ts,tsx}",
@@ -47,7 +48,7 @@ var src_default = new Reporter({ async report({ event, options, logger }) {
47
48
  await generateProps(source, options.projectRoot, output || "docgen", (...args) => logger.info({
48
49
  origin,
49
50
  message: args.join(" ")
50
- }));
51
+ }), tsconfig);
51
52
  } catch (error) {
52
53
  throwError(error);
53
54
  }
@@ -58,7 +59,7 @@ var src_default = new Reporter({ async report({ event, options, logger }) {
58
59
  }
59
60
  } });
60
61
  function throwError(error) {
61
- throw new ThrowableDiagnostic.default({ diagnostic: {
62
+ throw new ThrowableDiagnostic({ diagnostic: {
62
63
  origin,
63
64
  message: error.message,
64
65
  stack: error.stack
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["pacakgeJSON.name"],"sources":["../../src/index.ts"],"sourcesContent":["import ThrowableDiagnostic from \"@parcel/diagnostic\";\nimport { Reporter } from \"@parcel/plugin\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport { generateProps } from \"./generate-props.js\";\nimport pacakgeJSON from \"../package.json\" with { type: \"json\" };\nimport dedent from \"dedent\";\n\nconst origin = pacakgeJSON.name;\n\nexport default new Reporter({\n async report({ event, options, logger }) {\n if (event.type === \"buildStart\") {\n try {\n const packageJSON = path.join(options.projectRoot, \"package.json\");\n\n const fileURL = pathToFileURL(packageJSON).toString();\n\n const config = (await import(fileURL, {\n with: {\n type: \"json\",\n },\n }).then((mod) => mod.default)) as {\n [origin]?: {\n source: string;\n output?: string;\n };\n };\n\n const source = config[origin]?.source;\n const output = config[origin]?.output;\n\n if (!source) {\n // @ts-expect-error compiled verison needs to use default\n throw new ThrowableDiagnostic.default({\n diagnostic: {\n origin,\n message: dedent`No \"@renr/parcel-reporter-docgen\" source found in package.json. \n NOTE: if you are using a monorepo, you need to run parcel from the package that contains your pages rather than the project root.\n See https://github.com/parcel-bundler/parcel/issues/7206 for a workaround.`,\n // TODO why isn't the hint/documentation showing up in the terminal/error page?\n hints: [\n 'Add a \"@renr/parcel-reporter-docgen\" source to your package.json with a source e.g `../packages/ui/src/**/*.{ts,tsx}`.',\n ],\n\n codeFrames: [\n {\n codeHighlights: [\n {\n start: { line: 3, column: 2 },\n end: { line: 7, column: 44 },\n message:\n 'Add a \"@renr/parcel-reporter-docgen\" source to generate docs for your UI components.',\n },\n ],\n language: \"json\",\n filePath: packageJSON,\n code: dedent`{\n \"@renr/parcel-reporter-docgen\": {\n \"source\": \"../packages/ui/src/**/*.{ts,tsx}\",\n \"output\": \"docs/components\"\n }\n } `,\n },\n ],\n },\n });\n }\n try {\n await generateProps(\n source,\n options.projectRoot,\n output || \"docgen\",\n (...args) => logger.info({ origin, message: args.join(\" \") })\n );\n } catch (error) {\n throwError(error as Error);\n }\n } catch (error) {\n throwError(error as Error);\n }\n return;\n }\n },\n});\n\nfunction throwError(error: Error) {\n // @ts-expect-error compiled verison needs to use default\n throw new ThrowableDiagnostic.default({\n diagnostic: {\n origin,\n message: error.message,\n stack: error.stack,\n },\n });\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,SAASA;AAEf,IAAA,cAAe,IAAI,SAAS,EAC1B,MAAM,OAAO,EAAE,OAAO,SAAS,UAAU;CACvC,IAAI,MAAM,SAAS,cAAc;EAC/B,IAAI;;GACF,MAAM,cAAc,KAAK,KAAK,QAAQ,aAAa,cAAc;GAIjE,MAAM,SAAU,MAAM,OAFN,cAAc,WAAW,CAAC,CAAC,SAER,GAAG,EACpC,MAAM,EACJ,MAAM,OACR,EACF,EAAE,CAAC,MAAM,QAAQ,IAAI,OAAO;GAO5B,MAAM,UAAA,iBAAS,OAAO,aAAA,QAAA,mBAAA,KAAA,IAAA,KAAA,IAAA,eAAS;GAC/B,MAAM,UAAA,kBAAS,OAAO,aAAA,QAAA,oBAAA,KAAA,IAAA,KAAA,IAAA,gBAAS;GAE/B,IAAI,CAAC,QAEH,MAAM,IAAI,oBAAoB,QAAQ,EACpC,YAAY;IACV;IACA,SAAS,MAAM;;;IAIf,OAAO,CACL,0HACF;IAEA,YAAY,CACV;KACE,gBAAgB,CACd;MACE,OAAO;OAAE,MAAM;OAAG,QAAQ;MAAE;MAC5B,KAAK;OAAE,MAAM;OAAG,QAAQ;MAAG;MAC3B,SACE;KACJ,CACF;KACA,UAAU;KACV,UAAU;KACV,MAAM,MAAM;;;;;;IAMd,CACF;GACF,EACF,CAAC;GAEH,IAAI;IACF,MAAM,cACJ,QACA,QAAQ,aACR,UAAU,WACT,GAAG,SAAS,OAAO,KAAK;KAAE;KAAQ,SAAS,KAAK,KAAK,GAAG;IAAE,CAAC,CAC9D;GACF,SAAS,OAAO;IACd,WAAW,KAAc;GAC3B;EACF,SAAS,OAAO;GACd,WAAW,KAAc;EAC3B;EACA;CACF;AACF,EACF,CAAC;AAED,SAAS,WAAW,OAAc;CAEhC,MAAM,IAAI,oBAAoB,QAAQ,EACpC,YAAY;EACV;EACA,SAAS,MAAM;EACf,OAAO,MAAM;CACf,EACF,CAAC;AACH"}
1
+ {"version":3,"file":"index.mjs","names":["packageJSON.name"],"sources":["../../src/index.ts"],"sourcesContent":["import ThrowableDiagnostic from \"@parcel/diagnostic\";\nimport { Reporter } from \"@parcel/plugin\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport { generateProps } from \"./generate-props.js\";\nimport packageJSON from \"../package.json\" with { type: \"json\" };\nimport dedent from \"dedent\";\n\nconst origin = packageJSON.name;\n\nexport default new Reporter({\n async report({ event, options, logger }) {\n if (event.type === \"buildStart\") {\n try {\n const projectPackageJSON = path.join(\n options.projectRoot,\n \"package.json\"\n );\n\n const fileURL = pathToFileURL(projectPackageJSON).toString();\n\n const config = (await import(fileURL, {\n with: {\n type: \"json\",\n },\n }).then((mod) => mod.default)) as {\n [origin]?: {\n source: string;\n output?: string;\n tsconfig?: string;\n };\n };\n\n const source = config[origin]?.source;\n const output = config[origin]?.output;\n const tsconfig = config[origin]?.tsconfig;\n\n if (!source) {\n throw new ThrowableDiagnostic({\n diagnostic: {\n origin,\n message: dedent`No \"@renr/parcel-reporter-docgen\" source found in package.json. \n NOTE: if you are using a monorepo, you need to run parcel from the package that contains your pages rather than the project root.\n See https://github.com/parcel-bundler/parcel/issues/7206 for a workaround.`,\n hints: [\n 'Add a \"@renr/parcel-reporter-docgen\" source to your package.json with a source e.g `../packages/ui/src/**/*.{ts,tsx}`.',\n ],\n\n codeFrames: [\n {\n codeHighlights: [\n {\n start: { line: 3, column: 2 },\n end: { line: 7, column: 44 },\n message:\n 'Add a \"@renr/parcel-reporter-docgen\" source to generate docs for your UI components.',\n },\n ],\n language: \"json\",\n filePath: projectPackageJSON,\n code: dedent`{\n \"@renr/parcel-reporter-docgen\": {\n \"source\": \"../packages/ui/src/**/*.{ts,tsx}\",\n \"output\": \"docs/components\"\n }\n } `,\n },\n ],\n },\n });\n }\n try {\n await generateProps(\n source,\n options.projectRoot,\n output || \"docgen\",\n (...args) => logger.info({ origin, message: args.join(\" \") }),\n tsconfig\n );\n } catch (error) {\n throwError(error as Error);\n }\n } catch (error) {\n throwError(error as Error);\n }\n return;\n }\n },\n});\n\nfunction throwError(error: Error) {\n throw new ThrowableDiagnostic({\n diagnostic: {\n origin,\n message: error.message,\n stack: error.stack,\n },\n });\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,SAASA;AAEf,IAAA,cAAe,IAAI,SAAS,EAC1B,MAAM,OAAO,EAAE,OAAO,SAAS,UAAU;CACvC,IAAI,MAAM,SAAS,cAAc;EAC/B,IAAI;;GACF,MAAM,qBAAqB,KAAK,KAC9B,QAAQ,aACR,cACF;GAIA,MAAM,SAAU,MAAM,OAFN,cAAc,kBAAkB,CAAC,CAAC,SAEf,GAAG,EACpC,MAAM,EACJ,MAAM,OACR,EACF,EAAE,CAAC,MAAM,QAAQ,IAAI,OAAO;GAQ5B,MAAM,UAAA,iBAAS,OAAO,aAAA,QAAA,mBAAA,KAAA,IAAA,KAAA,IAAA,eAAS;GAC/B,MAAM,UAAA,kBAAS,OAAO,aAAA,QAAA,oBAAA,KAAA,IAAA,KAAA,IAAA,gBAAS;GAC/B,MAAM,YAAA,kBAAW,OAAO,aAAA,QAAA,oBAAA,KAAA,IAAA,KAAA,IAAA,gBAAS;GAEjC,IAAI,CAAC,QACH,MAAM,IAAI,oBAAoB,EAC5B,YAAY;IACV;IACA,SAAS,MAAM;;;IAGf,OAAO,CACL,0HACF;IAEA,YAAY,CACV;KACE,gBAAgB,CACd;MACE,OAAO;OAAE,MAAM;OAAG,QAAQ;MAAE;MAC5B,KAAK;OAAE,MAAM;OAAG,QAAQ;MAAG;MAC3B,SACE;KACJ,CACF;KACA,UAAU;KACV,UAAU;KACV,MAAM,MAAM;;;;;;IAMd,CACF;GACF,EACF,CAAC;GAEH,IAAI;IACF,MAAM,cACJ,QACA,QAAQ,aACR,UAAU,WACT,GAAG,SAAS,OAAO,KAAK;KAAE;KAAQ,SAAS,KAAK,KAAK,GAAG;IAAE,CAAC,GAC5D,QACF;GACF,SAAS,OAAO;IACd,WAAW,KAAc;GAC3B;EACF,SAAS,OAAO;GACd,WAAW,KAAc;EAC3B;EACA;CACF;AACF,EACF,CAAC;AAED,SAAS,WAAW,OAAc;CAChC,MAAM,IAAI,oBAAoB,EAC5B,YAAY;EACV;EACA,SAAS,MAAM;EACf,OAAO,MAAM;CACf,EACF,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renr/parcel-reporter-docgen",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-beta.10",
4
4
  "author": "Ren Rizzolo",
5
5
  "license": "MIT",
6
6
  "description": "Parcel reporter that generates ui docs via react-docgen-typescript",
@@ -13,24 +13,26 @@
13
13
  "url": "https://github.com/renrizzolo/parcel-rsc-react.git"
14
14
  },
15
15
  "type": "module",
16
- "main": "src/index.ts",
16
+ "main": "./dist/esm/index.mjs",
17
+ "module": "./dist/esm/index.mjs",
18
+ "types": "./dist/esm/index.d.mts",
17
19
  "files": [
18
20
  "dist"
19
21
  ],
20
22
  "sideEffects": false,
21
23
  "exports": {
22
- "default": {
24
+ ".": {
23
25
  "types": "./dist/esm/index.d.mts",
26
+ "import": "./dist/esm/index.mjs",
24
27
  "default": "./dist/esm/index.mjs"
25
28
  }
26
29
  },
27
30
  "dependencies": {
28
- "react-docgen-typescript": "^2.4.0",
29
31
  "@parcel/diagnostic": "^2.16.4",
30
32
  "@parcel/plugin": "^2.16.4",
31
33
  "dedent": "^1.7.2",
34
+ "react-docgen-typescript": "^2.4.0",
32
35
  "tinyglobby": "^0.2.17",
33
- "prettier": "^3.9.9",
34
36
  "typescript": "npm:@typescript/typescript6@^6.0.2"
35
37
  },
36
38
  "devDependencies": {
package/src/index.ts DELETED
@@ -1,96 +0,0 @@
1
- import ThrowableDiagnostic from "@parcel/diagnostic";
2
- import { Reporter } from "@parcel/plugin";
3
- import path from "path";
4
- import { pathToFileURL } from "url";
5
- import { generateProps } from "./generate-props.js";
6
- import pacakgeJSON from "../package.json" with { type: "json" };
7
- import dedent from "dedent";
8
-
9
- const origin = pacakgeJSON.name;
10
-
11
- export default new Reporter({
12
- async report({ event, options, logger }) {
13
- if (event.type === "buildStart") {
14
- try {
15
- const packageJSON = path.join(options.projectRoot, "package.json");
16
-
17
- const fileURL = pathToFileURL(packageJSON).toString();
18
-
19
- const config = (await import(fileURL, {
20
- with: {
21
- type: "json",
22
- },
23
- }).then((mod) => mod.default)) as {
24
- [origin]?: {
25
- source: string;
26
- output?: string;
27
- };
28
- };
29
-
30
- const source = config[origin]?.source;
31
- const output = config[origin]?.output;
32
-
33
- if (!source) {
34
- // @ts-expect-error compiled verison needs to use default
35
- throw new ThrowableDiagnostic.default({
36
- diagnostic: {
37
- origin,
38
- message: dedent`No "@renr/parcel-reporter-docgen" source found in package.json.
39
- NOTE: if you are using a monorepo, you need to run parcel from the package that contains your pages rather than the project root.
40
- See https://github.com/parcel-bundler/parcel/issues/7206 for a workaround.`,
41
- // TODO why isn't the hint/documentation showing up in the terminal/error page?
42
- hints: [
43
- 'Add a "@renr/parcel-reporter-docgen" source to your package.json with a source e.g `../packages/ui/src/**/*.{ts,tsx}`.',
44
- ],
45
-
46
- codeFrames: [
47
- {
48
- codeHighlights: [
49
- {
50
- start: { line: 3, column: 2 },
51
- end: { line: 7, column: 44 },
52
- message:
53
- 'Add a "@renr/parcel-reporter-docgen" source to generate docs for your UI components.',
54
- },
55
- ],
56
- language: "json",
57
- filePath: packageJSON,
58
- code: dedent`{
59
- "@renr/parcel-reporter-docgen": {
60
- "source": "../packages/ui/src/**/*.{ts,tsx}",
61
- "output": "docs/components"
62
- }
63
- } `,
64
- },
65
- ],
66
- },
67
- });
68
- }
69
- try {
70
- await generateProps(
71
- source,
72
- options.projectRoot,
73
- output || "docgen",
74
- (...args) => logger.info({ origin, message: args.join(" ") })
75
- );
76
- } catch (error) {
77
- throwError(error as Error);
78
- }
79
- } catch (error) {
80
- throwError(error as Error);
81
- }
82
- return;
83
- }
84
- },
85
- });
86
-
87
- function throwError(error: Error) {
88
- // @ts-expect-error compiled verison needs to use default
89
- throw new ThrowableDiagnostic.default({
90
- diagnostic: {
91
- origin,
92
- message: error.message,
93
- stack: error.stack,
94
- },
95
- });
96
- }