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

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,7 +8,7 @@ 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) {
11
+ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log = console.log, customTsconfigPath) {
12
12
  const files = await glob(pagesPattern, { cwd: rootDir });
13
13
  if (files.length === 0) {
14
14
  log(`No files found for pattern: ${pagesPattern}`);
@@ -43,8 +43,8 @@ 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
49
  savePropValueAsString: true,
50
50
  propFilter: (prop) => {
@@ -70,7 +70,9 @@ async function generateProps(pagesPattern, rootDir, outputPath, log = console.lo
70
70
  log(`parsing file: : ${relFile}`);
71
71
  const fileDocs = docsByFilePath.get(path.resolve(absPath)) || [];
72
72
  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];
73
+ const hasRoot = assignedInfo.subcomponentsMap.has("Root") || fileDocs.some((d) => d.displayName === "Root" || d.displayName === `${componentName}Root` || d.displayName === `${componentName}.Root`);
74
+ const rootTarget = assignedInfo.subcomponentsMap.get("Root");
75
+ const primaryDoc = hasRoot ? (rootTarget ? fileDocs.find((d) => d.displayName === rootTarget) : void 0) || (assignedInfo.baseIdentifier ? fileDocs.find((d) => d.displayName === assignedInfo.baseIdentifier) : void 0) || fileDocs.find((d) => d.displayName === `${componentName}.Root` || d.displayName === `${componentName}Root` || d.displayName === "Root") || fileDocs.find((d) => d.displayName === componentName) || fileDocs.find((d) => Object.keys(d.props).length > 0) || fileDocs[0] : 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
76
  let primaryProps = primaryDoc ? primaryDoc.props : {};
75
77
  if (assignedInfo.baseIdentifier && primaryDoc && primaryDoc.displayName === componentName) {
76
78
  const baseDoc = fileDocs.find((d) => d.displayName === assignedInfo.baseIdentifier);
@@ -79,7 +81,8 @@ async function generateProps(pagesPattern, rootDir, outputPath, log = console.lo
79
81
  const formattedPrimaryProps = formatProps(primaryProps);
80
82
  const subcomponents = {};
81
83
  for (const [subName, targetName] of assignedInfo.subcomponentsMap) {
82
- const subDoc = fileDocs.find((d) => d.displayName === targetName || d.displayName === `${componentName}.${subName}`);
84
+ if (hasRoot && subName === "Root") continue;
85
+ const subDoc = fileDocs.find((d) => d.displayName === targetName || d.displayName === `${componentName}.${subName}` || d.displayName === `${componentName}${subName}` || d.displayName === subName);
83
86
  if (subDoc) subcomponents[subName] = {
84
87
  name: `${componentName}.${subName}`,
85
88
  description: subDoc.description || void 0,
@@ -93,6 +96,7 @@ async function generateProps(pagesPattern, rootDir, outputPath, log = console.lo
93
96
  if (doc.displayName.startsWith(`${componentName}.`)) subName = doc.displayName.slice(componentName.length + 1);
94
97
  else if (doc.displayName.startsWith(componentName)) subName = doc.displayName.slice(componentName.length);
95
98
  if (subName) {
99
+ if (hasRoot && subName === "Root") continue;
96
100
  const existing = subcomponents[subName];
97
101
  if (existing && Object.keys(existing.props).length >= Object.keys(doc.props).length) continue;
98
102
  subcomponents[subName] = {
@@ -103,10 +107,10 @@ async function generateProps(pagesPattern, rootDir, outputPath, log = console.lo
103
107
  }
104
108
  }
105
109
  const componentJSON = JSON.stringify({
106
- name: componentName,
110
+ name: hasRoot ? `${componentName}.Root` : componentName,
107
111
  description: (primaryDoc === null || primaryDoc === void 0 ? void 0 : primaryDoc.description) || void 0,
108
- path: relFile,
109
- fileName: relFile.split("/").pop(),
112
+ path: relFile.replace(/\\/g, "/"),
113
+ fileName: path.basename(relFile),
110
114
  props: formattedPrimaryProps,
111
115
  subcomponents: Object.keys(subcomponents).length > 0 ? subcomponents : void 0
112
116
  }, null, 2);
@@ -165,6 +169,18 @@ function getAssignedInfo(sourceText, compName) {
165
169
  let baseIdentifier = null;
166
170
  const subcomponentsMap = /* @__PURE__ */ new Map();
167
171
  ts.forEachChild(sourceFile, (node) => {
172
+ if (ts.isExportDeclaration(node)) {
173
+ if (!node.isTypeOnly && node.exportClause && ts.isNamedExports(node.exportClause)) {
174
+ for (const element of node.exportClause.elements) if (!element.isTypeOnly) {
175
+ const exportName = element.name.getText(sourceFile);
176
+ const localName = element.propertyName ? element.propertyName.getText(sourceFile) : exportName;
177
+ if (/^[A-Z]/.test(exportName)) {
178
+ subcomponentsMap.set(exportName, localName);
179
+ if (exportName === "Root") baseIdentifier = localName;
180
+ }
181
+ }
182
+ }
183
+ }
168
184
  if (ts.isVariableStatement(node)) {
169
185
  for (const decl of node.declarationList.declarations) if (decl.name.getText(sourceFile) === compName && decl.initializer && ts.isCallExpression(decl.initializer)) {
170
186
  const call = decl.initializer;
@@ -173,12 +189,52 @@ function getAssignedInfo(sourceText, compName) {
173
189
  const firstArg = call.arguments[0];
174
190
  if (firstArg) baseIdentifier = firstArg.getText(sourceFile);
175
191
  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));
192
+ for (const prop of call.arguments[1].properties) if (ts.isPropertyAssignment(prop)) {
193
+ const propName = prop.name.getText(sourceFile);
194
+ const initName = prop.initializer.getText(sourceFile);
195
+ subcomponentsMap.set(propName, initName);
196
+ if (propName === "Root") baseIdentifier = initName;
197
+ } else if (ts.isShorthandPropertyAssignment(prop)) {
198
+ const propName = prop.name.getText(sourceFile);
199
+ subcomponentsMap.set(propName, propName);
200
+ if (propName === "Root") baseIdentifier = propName;
201
+ }
178
202
  }
179
203
  }
180
204
  }
181
205
  }
206
+ if (ts.isExpressionStatement(node) && ts.isBinaryExpression(node.expression)) {
207
+ const bin = node.expression;
208
+ if (bin.operatorToken.kind === ts.SyntaxKind.EqualsToken && ts.isPropertyAccessExpression(bin.left)) {
209
+ const objText = bin.left.expression.getText(sourceFile);
210
+ const propText = bin.left.name.getText(sourceFile);
211
+ if (objText === compName && /^[A-Z]/.test(propText)) {
212
+ const targetName = bin.right.getText(sourceFile);
213
+ subcomponentsMap.set(propText, targetName);
214
+ if (propText === "Root") baseIdentifier = targetName;
215
+ }
216
+ }
217
+ }
218
+ if (ts.isFunctionDeclaration(node) && node.name) {
219
+ var _node$modifiers;
220
+ if ((_node$modifiers = node.modifiers) === null || _node$modifiers === void 0 ? void 0 : _node$modifiers.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {
221
+ const fnName = node.name.getText(sourceFile);
222
+ if (/^[A-Z]/.test(fnName)) {
223
+ subcomponentsMap.set(fnName, fnName);
224
+ if (fnName === "Root") baseIdentifier = fnName;
225
+ }
226
+ }
227
+ }
228
+ if (ts.isVariableStatement(node)) {
229
+ var _node$modifiers2;
230
+ if ((_node$modifiers2 = node.modifiers) === null || _node$modifiers2 === void 0 ? void 0 : _node$modifiers2.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) for (const decl of node.declarationList.declarations) {
231
+ const varName = decl.name.getText(sourceFile);
232
+ if (varName !== compName && /^[A-Z]/.test(varName)) {
233
+ subcomponentsMap.set(varName, varName);
234
+ if (varName === "Root") baseIdentifier = varName;
235
+ }
236
+ }
237
+ }
182
238
  });
183
239
  return {
184
240
  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,aA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K,KAAK,GAAG,CAAC,CAC5B,KAAK,EAAE,IACV,KAAK,KAAK;GAEhB,KAAK,oBAAoB,kBAAkB,oBAAoB;EACjE;EAEA,MAAM,YAAY;CACpB;CAEA,OAAO;AACT;AAEA,SAAS,gBAAgB,YAAoB,UAAkB;CAC7D,MAAM,aAAa,GAAG,iBACpB,YACA,YACA,GAAG,aAAa,QAChB,IACF;CACA,IAAI,iBAAgC;CACpC,MAAM,mCAAmB,IAAI,IAAoB;CAEjD,GAAG,aAAa,aAAa,SAAS;EACpC,IAAI,GAAG,oBAAoB,IAAI,GACxB;QAAA,MAAM,QAAQ,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 = 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 const resolvedTsconfigPath = customTsconfigPath\n ? path.resolve(rootDir, customTsconfigPath)\n : path.resolve(rootDir, \"./tsconfig.json\");\n\n const docgenParser = withCustomConfig(resolvedTsconfigPath, {\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 or exports compound parts\n const sourceText = await fs.readFile(absPath, \"utf-8\");\n const assignedInfo = getAssignedInfo(sourceText, componentName);\n\n // Determine if this component has a .Root part\n const hasRoot =\n assignedInfo.subcomponentsMap.has(\"Root\") ||\n fileDocs.some(\n (d) =>\n d.displayName === \"Root\" ||\n d.displayName === `${componentName}Root` ||\n d.displayName === `${componentName}.Root`\n );\n\n // 1. Identify primary component doc matching componentName or assigned base / Root\n const rootTarget = assignedInfo.subcomponentsMap.get(\"Root\");\n const primaryDoc = hasRoot\n ? (rootTarget\n ? fileDocs.find((d) => d.displayName === rootTarget)\n : undefined) ||\n (assignedInfo.baseIdentifier\n ? fileDocs.find(\n (d) => d.displayName === assignedInfo.baseIdentifier\n )\n : undefined) ||\n fileDocs.find(\n (d) =>\n d.displayName === `${componentName}.Root` ||\n d.displayName === `${componentName}Root` ||\n d.displayName === \"Root\"\n ) ||\n fileDocs.find((d) => d.displayName === componentName) ||\n fileDocs.find((d) => Object.keys(d.props).length > 0) ||\n fileDocs[0]\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 or exported\n for (const [subName, targetName] of assignedInfo.subcomponentsMap) {\n if (hasRoot && subName === \"Root\") {\n continue;\n }\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 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 if (hasRoot && subName === \"Root\") continue;\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: hasRoot ? `${componentName}.Root` : componentName,\n description: 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 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 // 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) {\n const exportName = element.name.getText(sourceFile);\n const localName = element.propertyName\n ? element.propertyName.getText(sourceFile)\n : exportName;\n if (/^[A-Z]/.test(exportName)) {\n subcomponentsMap.set(exportName, localName);\n if (exportName === \"Root\") {\n baseIdentifier = localName;\n }\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 if (propName === \"Root\") {\n baseIdentifier = initName;\n }\n } else if (ts.isShorthandPropertyAssignment(prop)) {\n const propName = prop.name.getText(sourceFile);\n subcomponentsMap.set(propName, propName);\n if (propName === \"Root\") {\n baseIdentifier = propName;\n }\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 if (propText === \"Root\") {\n baseIdentifier = targetName;\n }\n }\n }\n }\n\n // 4. export function Root(...) or export const Root = (...)\n if (ts.isFunctionDeclaration(node) && node.name) {\n const isExported = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.ExportKeyword\n );\n if (isExported) {\n const fnName = node.name.getText(sourceFile);\n if (/^[A-Z]/.test(fnName)) {\n subcomponentsMap.set(fnName, fnName);\n if (fnName === \"Root\") {\n baseIdentifier = fnName;\n }\n }\n }\n }\n\n if (ts.isVariableStatement(node)) {\n const isExported = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.ExportKeyword\n );\n if (isExported) {\n for (const decl of node.declarationList.declarations) {\n const varName = decl.name.getText(sourceFile);\n if (varName !== compName && /^[A-Z]/.test(varName)) {\n subcomponentsMap.set(varName, varName);\n if (varName === \"Root\") {\n baseIdentifier = varName;\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,aA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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;KACzC,IAAI,aAAa,QACf,iBAAiB;IAErB;GACF;EACF;EAGA,IAAI,GAAG,sBAAsB,IAAI,KAAK,KAAK,MAAM;;GAI/C,KAAA,kBAHmB,KAAK,eAAA,QAAA,oBAAA,KAAA,IAAA,KAAA,IAAA,gBAAW,MAChC,MAAM,EAAE,SAAS,GAAG,WAAW,aAClC,GACgB;IACd,MAAM,SAAS,KAAK,KAAK,QAAQ,UAAU;IAC3C,IAAI,SAAS,KAAK,MAAM,GAAG;KACzB,iBAAiB,IAAI,QAAQ,MAAM;KACnC,IAAI,WAAW,QACb,iBAAiB;IAErB;GACF;EACF;EAEA,IAAI,GAAG,oBAAoB,IAAI,GAAG;;GAIhC,KAAA,mBAHmB,KAAK,eAAA,QAAA,qBAAA,KAAA,IAAA,KAAA,IAAA,iBAAW,MAChC,MAAM,EAAE,SAAS,GAAG,WAAW,aAClC,GAEE,KAAK,MAAM,QAAQ,KAAK,gBAAgB,cAAc;IACpD,MAAM,UAAU,KAAK,KAAK,QAAQ,UAAU;IAC5C,IAAI,YAAY,YAAY,SAAS,KAAK,OAAO,GAAG;KAClD,iBAAiB,IAAI,SAAS,OAAO;KACrC,IAAI,YAAY,QACd,iBAAiB;IAErB;GACF;EAEJ;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.7",
4
4
  "author": "Ren Rizzolo",
5
5
  "license": "MIT",
6
6
  "description": "Parcel reporter that generates ui docs via react-docgen-typescript",
@@ -13,14 +13,17 @@
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
  },
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
- }