@renr/parcel-reporter-docgen 0.0.1-alpha.4 → 0.1.0-beta.6

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
@@ -3,11 +3,12 @@ import { fileURLToPath } from "url";
3
3
  import fs from "fs/promises";
4
4
  import { withCustomConfig } from "react-docgen-typescript";
5
5
  import { glob } from "tinyglobby";
6
+ import ts from "typescript";
6
7
  //#region src/generate-props.ts
7
8
  const __filename = fileURLToPath(import.meta.url);
8
9
  path.dirname(__filename);
9
10
  const fileMtimeCache = /* @__PURE__ */ new Map();
10
- async function generateProps(pagesPattern, rootDir, outputPath, log = console.log) {
11
+ async function generateProps(pagesPattern, rootDir, outputPath = "docgen", log = console.log, customTsconfigPath) {
11
12
  const files = await glob(pagesPattern, { cwd: rootDir });
12
13
  if (files.length === 0) {
13
14
  log(`No files found for pattern: ${pagesPattern}`);
@@ -42,7 +43,8 @@ async function generateProps(pagesPattern, rootDir, outputPath, log = console.lo
42
43
  }
43
44
  if (filesToProcess.length === 0) return;
44
45
  log(`Found ${filesToProcess.length} changed file(s) for pattern: ${pagesPattern}`);
45
- const docgenParser = withCustomConfig(path.resolve(rootDir, "./tsconfig.json"), {
46
+ const resolvedTsconfigPath = customTsconfigPath ? path.resolve(rootDir, customTsconfigPath) : path.resolve(rootDir, "./tsconfig.json");
47
+ const docgenParser = withCustomConfig(resolvedTsconfigPath, {
46
48
  shouldExtractLiteralValuesFromEnum: true,
47
49
  savePropValueAsString: true,
48
50
  propFilter: (prop) => {
@@ -66,23 +68,47 @@ async function generateProps(pagesPattern, rootDir, outputPath, log = console.lo
66
68
  }
67
69
  await Promise.all(filesToProcess.map(async ({ relFile, absPath, componentName }) => {
68
70
  log(`parsing file: : ${relFile}`);
69
- const fileDocs = docsByFilePath.get(path.resolve(absPath));
70
- const props = fileDocs && fileDocs[0] ? fileDocs[0].props : {};
71
- for (const propName in props) {
72
- const prop = props[propName];
73
- if (!prop) throw new Error(`No prop found for ${propName} in ${componentName}`);
74
- if (prop.type && prop.type.name) {
75
- const { type: shortPropTypeName, detailedType } = getShortPropType(propName, prop.type.name);
76
- const hasExpandedType = Boolean(detailedType);
77
- prop.type.name = hasExpandedType && prop.type.name.split("|").length > 3 ? prop.type.name.split("|").map((line) => `| ${line}\n`).join("") : prop.type.name;
78
- prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;
71
+ const fileDocs = docsByFilePath.get(path.resolve(absPath)) || [];
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];
74
+ let primaryProps = primaryDoc ? primaryDoc.props : {};
75
+ if (assignedInfo.baseIdentifier && primaryDoc && primaryDoc.displayName === componentName) {
76
+ const baseDoc = fileDocs.find((d) => d.displayName === assignedInfo.baseIdentifier);
77
+ if (baseDoc && Object.keys(baseDoc.props).length > Object.keys(primaryProps).length) primaryProps = baseDoc.props;
78
+ }
79
+ const formattedPrimaryProps = formatProps(primaryProps);
80
+ const subcomponents = {};
81
+ 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
+ };
88
+ }
89
+ for (const doc of fileDocs) {
90
+ if (doc === primaryDoc) continue;
91
+ if (assignedInfo.baseIdentifier && doc.displayName === assignedInfo.baseIdentifier) continue;
92
+ let subName;
93
+ 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) {
96
+ const existing = subcomponents[subName];
97
+ if (existing && Object.keys(existing.props).length >= Object.keys(doc.props).length) continue;
98
+ subcomponents[subName] = {
99
+ name: `${componentName}.${subName}`,
100
+ description: doc.description || void 0,
101
+ props: formatProps(doc.props)
102
+ };
79
103
  }
80
104
  }
81
105
  const componentJSON = JSON.stringify({
82
106
  name: componentName,
83
- path: relFile,
84
- fileName: relFile.split("/").pop(),
85
- props
107
+ description: (primaryDoc === null || primaryDoc === void 0 ? void 0 : primaryDoc.description) || void 0,
108
+ path: relFile.replace(/\\/g, "/"),
109
+ fileName: path.basename(relFile),
110
+ props: formattedPrimaryProps,
111
+ subcomponents: Object.keys(subcomponents).length > 0 ? subcomponents : void 0
86
112
  }, null, 2);
87
113
  const outputFilePath = path.join(resolvedOutputPath, `${componentName}.json`);
88
114
  await fs.writeFile(outputFilePath, componentJSON + "\n", "utf-8");
@@ -118,6 +144,47 @@ function getShortPropType(name, type) {
118
144
  detailedType: true
119
145
  };
120
146
  }
147
+ function formatProps(rawProps) {
148
+ const props = {};
149
+ for (const propName in rawProps) {
150
+ const rawProp = rawProps[propName];
151
+ if (!rawProp) continue;
152
+ const prop = { ...rawProp };
153
+ if (prop.type && prop.type.name) {
154
+ const { type: shortPropTypeName, detailedType } = getShortPropType(propName, prop.type.name);
155
+ 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;
157
+ prop.shortPropTypeName = hasExpandedType ? shortPropTypeName : null;
158
+ }
159
+ props[propName] = prop;
160
+ }
161
+ return props;
162
+ }
163
+ function getAssignedInfo(sourceText, compName) {
164
+ const sourceFile = ts.createSourceFile("temp.tsx", sourceText, ts.ScriptTarget.Latest, true);
165
+ let baseIdentifier = null;
166
+ const subcomponentsMap = /* @__PURE__ */ new Map();
167
+ ts.forEachChild(sourceFile, (node) => {
168
+ if (ts.isVariableStatement(node)) {
169
+ for (const decl of node.declarationList.declarations) if (decl.name.getText(sourceFile) === compName && decl.initializer && ts.isCallExpression(decl.initializer)) {
170
+ const call = decl.initializer;
171
+ const exprText = call.expression.getText(sourceFile);
172
+ if ((exprText === "Object.assign" || exprText.endsWith(".assign")) && call.arguments.length > 0) {
173
+ const firstArg = call.arguments[0];
174
+ if (firstArg) baseIdentifier = firstArg.getText(sourceFile);
175
+ 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));
178
+ }
179
+ }
180
+ }
181
+ }
182
+ });
183
+ return {
184
+ baseIdentifier,
185
+ subcomponentsMap
186
+ };
187
+ }
121
188
  //#endregion
122
189
  export { generateProps };
123
190
 
@@ -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 { 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 const props = fileDocs && fileDocs[0] ? fileDocs[0].props : {};\n\n for (const propName in props) {\n const prop = props[propName] as\n | (PropItem & {\n shortPropTypeName: string | null;\n })\n | undefined;\n\n if (!prop) {\n throw new Error(\n `No prop found for ${propName} in ${componentName}`\n );\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\n const componentJSON = JSON.stringify(\n {\n name: componentName,\n path: relFile,\n fileName: relFile.split(\"/\").pop(),\n props,\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"],"mappings":";;;;;;AAMA,MAAM,aAAa,cAAc,OAAO,KAAK,IAAI;AAC/B,KAAK,QAAQ,WAAW;AAG1C,MAAM,iCAAiB,IAAI,KAAqB;AAEhD,eAAsB,cACpB,cACA,SACA,YACA,MAAM,QAAQ,KACd;CACA,MAAM,QAAQ,MAAM,KAAK,cAAc,EACrC,KAAK,SACN,CAAC;CAEF,IAAI,MAAM,WAAW,GAAG;EACtB,IAAI,+BAA+B,eAAe;EAClD;;CAGF,MAAM,qBAAqB,KAAK,QAAQ,SAAS,WAAW;CAC5D,MAAM,GAAG,MAAM,oBAAoB,EAAE,WAAW,MAAM,CAAC;CAEvD,MAAM,iBAIA,EAAE;CAER,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAW,KAAK,QAAQ,SAAS,KAAK;EAC5C,MAAM,gBAAgB,KAAK,SAAS,MAAM,KAAK,QAAQ,KAAK,CAAC;EAC7D,MAAM,iBAAiB,KAAK,KAC1B,oBACA,GAAG,cAAc,OAClB;EAED,IAAI;GACF,MAAM,aAAa,MAAM,GAAG,KAAK,SAAS;GAC1C,MAAM,cAAc,eAAe,IAAI,SAAS;GAEhD,IAAI,aAAa;GACjB,IAAI;IACF,MAAM,UAAU,MAAM,GAAG,KAAK,eAAe;IAC7C,IACG,gBAAgB,KAAA,KAAa,gBAAgB,WAAW,WACzD,QAAQ,WAAW,WAAW,SAC9B;KACA,aAAa;KACb,eAAe,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],"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(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.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 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,aAAqB,UACrB,MAAoC,QAAQ,KAC5C,oBACA;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,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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AAM,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,5 +1,4 @@
1
1
  import { Reporter } from "@parcel/plugin";
2
-
3
2
  //#region src/index.d.ts
4
3
  declare const _default: Reporter;
5
4
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/index.ts"],"mappings":";;;cAC0C,QAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/index.ts"],"mappings":""}
@@ -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,eAAe;GAIlE,MAAM,SAAU,MAAM,OAFN,cAAc,YAAY,CAAC,UAEP,EAAE,EACpC,MAAM,EACJ,MAAM,QACP,EACF,EAAE,MAAM,QAAQ,IAAI,QAAQ;GAO7B,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,2HACD;IAED,YAAY,CACV;KACE,gBAAgB,CACd;MACE,OAAO;OAAE,MAAM;OAAG,QAAQ;OAAG;MAC7B,KAAK;OAAE,MAAM;OAAG,QAAQ;OAAI;MAC5B,SACE;MACH,CACF;KACD,UAAU;KACV,UAAU;KACV,MAAM,MAAM;;;;;;KAMb,CACF;IACF,EACF,CAAC;GAEJ,IAAI;IACF,MAAM,cACJ,QACA,QAAQ,aACR,UAAU,WACT,GAAG,SAAS,OAAO,KAAK;KAAE;KAAQ,SAAS,KAAK,KAAK,IAAI;KAAE,CAAC,CAC9D;YACM,OAAO;IACd,WAAW,MAAe;;WAErB,OAAO;GACd,WAAW,MAAe;;EAE5B;;GAGL,CAAC;AAEF,SAAS,WAAW,OAAc;CAEhC,MAAM,IAAI,oBAAoB,QAAQ,EACpC,YAAY;EACV;EACA,SAAS,MAAM;EACf,OAAO,MAAM;EACd,EACF,CAAC"}
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,MA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+1,6 @@
1
1
  {
2
2
  "name": "@renr/parcel-reporter-docgen",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.1.0-beta.6",
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
  },
@@ -29,8 +32,9 @@
29
32
  "@parcel/diagnostic": "^2.16.4",
30
33
  "@parcel/plugin": "^2.16.4",
31
34
  "dedent": "^1.7.2",
32
- "tinyglobby": "^0.2.16",
33
- "prettier": "^3.8.3"
35
+ "tinyglobby": "^0.2.17",
36
+ "prettier": "^3.9.9",
37
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
34
38
  },
35
39
  "devDependencies": {
36
40
  "@types/node": "^25.6.2"
@@ -40,6 +44,6 @@
40
44
  },
41
45
  "scripts": {
42
46
  "build": "tsdown",
43
- "type-check": "tsgo --noEmit"
47
+ "type-check": "tsc --noEmit"
44
48
  }
45
49
  }
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
- }