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

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
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ import { generateProps } from "./generate-props.mjs";
3
+ import path from "path";
4
+ import fs from "fs";
5
+ import { parseArgs } from "util";
6
+ //#region src/cli.ts
7
+ const origin = "@renr/parcel-reporter-docgen";
8
+ function loadParcelRcConfig(rootDir) {
9
+ const parcelRcPath = path.join(rootDir, ".parcelrc");
10
+ if (!fs.existsSync(parcelRcPath)) return;
11
+ try {
12
+ const raw = JSON.parse(fs.readFileSync(parcelRcPath, "utf-8"));
13
+ if (Array.isArray(raw.reporters)) {
14
+ for (const entry of raw.reporters) if (typeof entry === "object" && entry !== null && entry.plugin === origin && entry.config) return entry.config;
15
+ }
16
+ } catch (_unused) {}
17
+ }
18
+ function loadPackageConfig(rootDir) {
19
+ const pkgPath = path.join(rootDir, "package.json");
20
+ if (!fs.existsSync(pkgPath)) return;
21
+ try {
22
+ return JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
23
+ } catch (_unused2) {
24
+ return;
25
+ }
26
+ }
27
+ async function main() {
28
+ var _ref, _ref2, _pkgConfig$origin, _ref3, _ref4, _pkgConfig$origin2, _ref5, _ref6, _pkgConfig$origin3;
29
+ const { values } = parseArgs({
30
+ options: {
31
+ source: {
32
+ type: "string",
33
+ short: "s"
34
+ },
35
+ output: {
36
+ type: "string",
37
+ short: "o"
38
+ },
39
+ tsconfig: {
40
+ type: "string",
41
+ short: "t"
42
+ },
43
+ root: {
44
+ type: "string",
45
+ short: "r"
46
+ }
47
+ },
48
+ strict: false
49
+ });
50
+ const rootDir = typeof values.root === "string" ? path.resolve(process.cwd(), values.root) : process.cwd();
51
+ const rcConfig = loadParcelRcConfig(rootDir);
52
+ const pkgConfig = loadPackageConfig(rootDir);
53
+ const source = (_ref = (_ref2 = typeof values.source === "string" ? values.source : void 0) !== null && _ref2 !== void 0 ? _ref2 : rcConfig === null || rcConfig === void 0 ? void 0 : rcConfig.source) !== null && _ref !== void 0 ? _ref : pkgConfig === null || pkgConfig === void 0 || (_pkgConfig$origin = pkgConfig[origin]) === null || _pkgConfig$origin === void 0 ? void 0 : _pkgConfig$origin.source;
54
+ const output = (_ref3 = (_ref4 = typeof values.output === "string" ? values.output : void 0) !== null && _ref4 !== void 0 ? _ref4 : rcConfig === null || rcConfig === void 0 ? void 0 : rcConfig.output) !== null && _ref3 !== void 0 ? _ref3 : pkgConfig === null || pkgConfig === void 0 || (_pkgConfig$origin2 = pkgConfig[origin]) === null || _pkgConfig$origin2 === void 0 ? void 0 : _pkgConfig$origin2.output;
55
+ const tsconfig = (_ref5 = (_ref6 = typeof values.tsconfig === "string" ? values.tsconfig : void 0) !== null && _ref6 !== void 0 ? _ref6 : rcConfig === null || rcConfig === void 0 ? void 0 : rcConfig.tsconfig) !== null && _ref5 !== void 0 ? _ref5 : pkgConfig === null || pkgConfig === void 0 || (_pkgConfig$origin3 = pkgConfig[origin]) === null || _pkgConfig$origin3 === void 0 ? void 0 : _pkgConfig$origin3.tsconfig;
56
+ if (!source) throw new Error(`No "${origin}" source found in .parcelrc or package.json.`);
57
+ await generateProps(source, rootDir, output || "docgen", (...args) => console.info(args.join(" ")), tsconfig);
58
+ }
59
+ main().catch((error) => {
60
+ console.error(error instanceof Error ? error.message : String(error));
61
+ process.exit(1);
62
+ });
63
+ //#endregion
64
+ export {};
65
+
66
+ //# sourceMappingURL=cli.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.mjs","names":[],"sources":["../../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"fs\";\nimport path from \"path\";\nimport { parseArgs } from \"util\";\nimport { generateProps } from \"./generate-props.js\";\n\nconst origin = \"@renr/parcel-reporter-docgen\";\n\ninterface DocgenPluginConfig {\n source?: string;\n output?: string;\n tsconfig?: string;\n}\n\ninterface PackageConfig {\n [origin]?: DocgenPluginConfig;\n}\n\nfunction loadParcelRcConfig(rootDir: string): DocgenPluginConfig | undefined {\n const parcelRcPath = path.join(rootDir, \".parcelrc\");\n if (!fs.existsSync(parcelRcPath)) {\n return undefined;\n }\n try {\n const raw = JSON.parse(fs.readFileSync(parcelRcPath, \"utf-8\")) as {\n reporters?: Array<\n string | { plugin?: string; config?: DocgenPluginConfig }\n >;\n };\n if (Array.isArray(raw.reporters)) {\n for (const entry of raw.reporters) {\n if (\n typeof entry === \"object\" &&\n entry !== null &&\n entry.plugin === origin &&\n entry.config\n ) {\n return entry.config;\n }\n }\n }\n } catch {\n // ignore parse errors\n }\n return undefined;\n}\n\nfunction loadPackageConfig(rootDir: string): PackageConfig | undefined {\n const pkgPath = path.join(rootDir, \"package.json\");\n if (!fs.existsSync(pkgPath)) {\n return undefined;\n }\n try {\n return JSON.parse(fs.readFileSync(pkgPath, \"utf-8\")) as PackageConfig;\n } catch {\n return undefined;\n }\n}\n\nasync function main() {\n const { values } = parseArgs({\n options: {\n source: { type: \"string\", short: \"s\" },\n output: { type: \"string\", short: \"o\" },\n tsconfig: { type: \"string\", short: \"t\" },\n root: { type: \"string\", short: \"r\" },\n },\n strict: false,\n });\n\n const rootDir =\n typeof values.root === \"string\"\n ? path.resolve(process.cwd(), values.root)\n : process.cwd();\n\n const rcConfig = loadParcelRcConfig(rootDir);\n const pkgConfig = loadPackageConfig(rootDir);\n\n const source =\n (typeof values.source === \"string\" ? values.source : undefined) ??\n rcConfig?.source ??\n pkgConfig?.[origin]?.source;\n\n const output =\n (typeof values.output === \"string\" ? values.output : undefined) ??\n rcConfig?.output ??\n pkgConfig?.[origin]?.output;\n\n const tsconfig =\n (typeof values.tsconfig === \"string\" ? values.tsconfig : undefined) ??\n rcConfig?.tsconfig ??\n pkgConfig?.[origin]?.tsconfig;\n\n if (!source) {\n throw new Error(\n `No \"${origin}\" source found in .parcelrc or package.json.`\n );\n }\n\n await generateProps(\n source,\n rootDir,\n output || \"docgen\",\n (...args) => console.info(args.join(\" \")),\n tsconfig\n );\n}\n\nmain().catch((error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n});\n"],"mappings":";;;;;;AAMA,MAAM,SAAS;AAYf,SAAS,mBAAmB,SAAiD;CAC3E,MAAM,eAAe,KAAK,KAAK,SAAS,WAAW;CACnD,IAAI,CAAC,GAAG,WAAW,YAAY,GAC7B;CAEF,IAAI;EACF,MAAM,MAAM,KAAK,MAAM,GAAG,aAAa,cAAc,OAAO,CAAC;EAK7D,IAAI,MAAM,QAAQ,IAAI,SAAS,GACxB;QAAA,MAAM,SAAS,IAAI,WACtB,IACE,OAAO,UAAU,YACjB,UAAU,QACV,MAAM,WAAW,UACjB,MAAM,QAEN,OAAO,MAAM;EAAA;CAIrB,SAAA,SAAQ,CAER;AAEF;AAEA,SAAS,kBAAkB,SAA4C;CACrE,MAAM,UAAU,KAAK,KAAK,SAAS,cAAc;CACjD,IAAI,CAAC,GAAG,WAAW,OAAO,GACxB;CAEF,IAAI;EACF,OAAO,KAAK,MAAM,GAAG,aAAa,SAAS,OAAO,CAAC;CACrD,SAAA,UAAQ;EACN;CACF;AACF;AAEA,eAAe,OAAO;;CACpB,MAAM,EAAE,WAAW,UAAU;EAC3B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CAEvB,IAAI,CAAC,QACH,MAAM,IAAI,MACR,OAAO,OAAO,6CAChB;CAGF,MAAM,cACJ,QACA,SACA,UAAU,WACT,GAAG,SAAS,QAAQ,KAAK,KAAK,KAAK,GAAG,CAAC,GACxC,QACF;AACF;AAEA,KAAK,CAAC,CAAC,OAAO,UAAmB;CAC/B,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,KAAK,CAAC;AAChB,CAAC"}
@@ -0,0 +1,4 @@
1
+ //#region src/generate-props.d.ts
2
+ export declare function generateProps(pagesPattern: string, rootDir: string, outputPath?: string, log?: (...args: unknown[]) => void, customTsconfigPath?: string): Promise<void>;
3
+ //#endregion
4
+ //# sourceMappingURL=generate-props.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-props.d.mts","names":[],"sources":["../../src/generate-props.ts"],"mappings":";wBAasB,cACpB,sBACA,iBACA,qBACA,UAAS,0BACT,8BAA2B"}
@@ -1,15 +1,15 @@
1
- import path from "path";
2
- import { fileURLToPath } from "url";
3
1
  import fs from "fs/promises";
2
+ import path from "path";
4
3
  import { withCustomConfig } from "react-docgen-typescript";
5
4
  import { glob } from "tinyglobby";
6
5
  import ts from "typescript";
6
+ import { fileURLToPath } from "url";
7
7
  //#region src/generate-props.ts
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,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;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 = (\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,IAA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KACnD,MAAM,aAAa,IAAI,MAAM,QAAQ,UAAU;KAC/C,iBAAiB,IAAI,UAAU,UAAU;IAC3C;GACF;EACF;CACF,CAAC;CAED,OAAO;EAAE;EAAgB;CAAiB;AAC5C"}
@@ -1,6 +1,2 @@
1
- import { Reporter } from "@parcel/plugin";
2
- //#region src/index.d.ts
3
- declare const _default: Reporter;
4
- //#endregion
5
- export { _default as default };
6
- //# sourceMappingURL=index.d.mts.map
1
+ import { generateProps } from "./generate-props.mjs";
2
+ export { generateProps };
@@ -1,70 +1,2 @@
1
1
  import { generateProps } from "./generate-props.mjs";
2
- import { name } from "./package.mjs";
3
- import ThrowableDiagnostic from "@parcel/diagnostic";
4
- import { Reporter } from "@parcel/plugin";
5
- import path from "path";
6
- import { pathToFileURL } from "url";
7
- import dedent from "dedent";
8
- //#region src/index.ts
9
- const origin = name;
10
- var src_default = new Reporter({ async report({ event, options, logger }) {
11
- if (event.type === "buildStart") {
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);
16
- const source = (_config$origin = config[origin]) === null || _config$origin === void 0 ? void 0 : _config$origin.source;
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: {
19
- origin,
20
- message: dedent`No "@renr/parcel-reporter-docgen" source found in package.json.
21
- NOTE: if you are using a monorepo, you need to run parcel from the package that contains your pages rather than the project root.
22
- See https://github.com/parcel-bundler/parcel/issues/7206 for a workaround.`,
23
- hints: ["Add a \"@renr/parcel-reporter-docgen\" source to your package.json with a source e.g `../packages/ui/src/**/*.{ts,tsx}`."],
24
- codeFrames: [{
25
- codeHighlights: [{
26
- start: {
27
- line: 3,
28
- column: 2
29
- },
30
- end: {
31
- line: 7,
32
- column: 44
33
- },
34
- message: "Add a \"@renr/parcel-reporter-docgen\" source to generate docs for your UI components."
35
- }],
36
- language: "json",
37
- filePath: packageJSON,
38
- code: dedent`{
39
- "@renr/parcel-reporter-docgen": {
40
- "source": "../packages/ui/src/**/*.{ts,tsx}",
41
- "output": "docs/components"
42
- }
43
- } `
44
- }]
45
- } });
46
- try {
47
- await generateProps(source, options.projectRoot, output || "docgen", (...args) => logger.info({
48
- origin,
49
- message: args.join(" ")
50
- }));
51
- } catch (error) {
52
- throwError(error);
53
- }
54
- } catch (error) {
55
- throwError(error);
56
- }
57
- return;
58
- }
59
- } });
60
- function throwError(error) {
61
- throw new ThrowableDiagnostic.default({ diagnostic: {
62
- origin,
63
- message: error.message,
64
- stack: error.stack
65
- } });
66
- }
67
- //#endregion
68
- export { src_default as default };
69
-
70
- //# sourceMappingURL=index.mjs.map
2
+ export { generateProps };
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.11",
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,52 @@
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",
19
+ "bin": {
20
+ "parcel-docgen": "./dist/esm/cli.mjs"
21
+ },
17
22
  "files": [
18
- "dist"
23
+ "dist",
24
+ "target/release/libparcel_reporter_docgen.so",
25
+ "target/release/libparcel_reporter_docgen.dylib",
26
+ "target/release/parcel_reporter_docgen.dll"
19
27
  ],
20
28
  "sideEffects": false,
21
29
  "exports": {
22
- "default": {
30
+ ".": {
23
31
  "types": "./dist/esm/index.d.mts",
32
+ "import": "./dist/esm/index.mjs",
24
33
  "default": "./dist/esm/index.mjs"
25
34
  }
26
35
  },
36
+ "engines": {
37
+ "parcel": "^3.0.0-alpha.3"
38
+ },
39
+ "parcel": {
40
+ "abi": 1,
41
+ "artifacts": {
42
+ "aarch64-apple-darwin": "@renr/parcel-reporter-docgen-darwin-arm64",
43
+ "x86_64-apple-darwin": "@renr/parcel-reporter-docgen-darwin-x64",
44
+ "x86_64-pc-windows-msvc": "@renr/parcel-reporter-docgen-win32-x64-msvc",
45
+ "aarch64-pc-windows-msvc": "@renr/parcel-reporter-docgen-win32-arm64-msvc",
46
+ "x86_64-unknown-linux-gnu": "@renr/parcel-reporter-docgen-linux-x64-gnu",
47
+ "aarch64-unknown-linux-gnu": "@renr/parcel-reporter-docgen-linux-arm64-gnu",
48
+ "x86_64-unknown-linux-musl": "@renr/parcel-reporter-docgen-linux-x64-musl",
49
+ "aarch64-unknown-linux-musl": "@renr/parcel-reporter-docgen-linux-arm64-musl"
50
+ }
51
+ },
52
+ "scripts": {
53
+ "build": "node ../../scripts/build-rust.mjs && tsdown",
54
+ "build:rust": "node ../../scripts/build-rust.mjs",
55
+ "test:rust": "node ../../scripts/build-rust.mjs --test",
56
+ "prepack": "node ../../scripts/prepack-plugin.mjs",
57
+ "type-check": "tsc --noEmit"
58
+ },
27
59
  "dependencies": {
28
60
  "react-docgen-typescript": "^2.4.0",
29
- "@parcel/diagnostic": "^2.16.4",
30
- "@parcel/plugin": "^2.16.4",
31
- "dedent": "^1.7.2",
32
61
  "tinyglobby": "^0.2.17",
33
- "prettier": "^3.9.9",
34
62
  "typescript": "npm:@typescript/typescript6@^6.0.2"
35
63
  },
36
64
  "devDependencies": {
@@ -39,8 +67,14 @@
39
67
  "publishConfig": {
40
68
  "access": "public"
41
69
  },
42
- "scripts": {
43
- "build": "tsdown",
44
- "type-check": "tsc --noEmit"
70
+ "optionalDependencies": {
71
+ "@renr/parcel-reporter-docgen-darwin-arm64": "0.1.0-beta.11",
72
+ "@renr/parcel-reporter-docgen-darwin-x64": "0.1.0-beta.11",
73
+ "@renr/parcel-reporter-docgen-win32-x64-msvc": "0.1.0-beta.11",
74
+ "@renr/parcel-reporter-docgen-win32-arm64-msvc": "0.1.0-beta.11",
75
+ "@renr/parcel-reporter-docgen-linux-x64-gnu": "0.1.0-beta.11",
76
+ "@renr/parcel-reporter-docgen-linux-arm64-gnu": "0.1.0-beta.11",
77
+ "@renr/parcel-reporter-docgen-linux-x64-musl": "0.1.0-beta.11",
78
+ "@renr/parcel-reporter-docgen-linux-arm64-musl": "0.1.0-beta.11"
45
79
  }
46
- }
80
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Ren
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/index.ts"],"mappings":""}
@@ -1 +0,0 @@
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,6 +0,0 @@
1
- //#region package.json
2
- var name = "@renr/parcel-reporter-docgen";
3
- //#endregion
4
- export { name };
5
-
6
- //# sourceMappingURL=package.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package.mjs","names":[],"sources":["../../package.json"],"sourcesContent":[""],"mappings":""}
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
- }