@reicek/neataptic-ts 0.1.24 → 0.1.26

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.
Files changed (215) hide show
  1. package/.github/copilot-instructions.md +11 -0
  2. package/.github/skills/trace-analyzer-extension/SKILL.md +3 -3
  3. package/.github/skills/trace-analyzer-extension/assets/extension-checklist.md +1 -1
  4. package/.github/skills/trace-analyzer-extension/references/analyzer-extension-workflow.md +1 -1
  5. package/.github/skills/trace-audit-reporting/SKILL.md +3 -3
  6. package/.github/skills/trace-audit-reporting/references/trace-analysis-workflow.md +1 -1
  7. package/.github/workflows/ci.yml +3 -3
  8. package/.github/workflows/deploy-pages.yml +6 -6
  9. package/.github/workflows/manual_release_pipeline.yml +3 -3
  10. package/.github/workflows/publish.yml +18 -19
  11. package/.github/workflows/release_dispatch.yml +3 -3
  12. package/package.json +26 -20
  13. package/plans/Flappy_Bird_Folder_Documentation_Pass.md +4 -4
  14. package/plans/README.md +24 -0
  15. package/plans/Roadmap.md +62 -40
  16. package/plans/analyze-trace-solid-split.plans.md +66 -0
  17. package/plans/architecture-solid-split.plans.md +9 -15
  18. package/plans/asciiMaze-typescript-repair.plans.md +1 -1
  19. package/plans/generate-docs-solid-split.plans.md +87 -0
  20. package/plans/methods-docs.plans.md +25 -1
  21. package/plans/methods-solid-split.plans.md +14 -14
  22. package/plans/neat-docs.plans.md +9 -1
  23. package/plans/neat-test-surface-repair.plans.md +1 -1
  24. package/plans/render-docs-html-solid-split.plans.md +68 -0
  25. package/plans/src-no-explicit-any-cleanup.plans.md +1 -1
  26. package/plans/utils-docs.plans.md +6 -1
  27. package/scripts/analyze-trace/analyze-trace.analysis.ts +479 -0
  28. package/scripts/analyze-trace/analyze-trace.constants.ts +35 -0
  29. package/scripts/analyze-trace/analyze-trace.io.ts +69 -0
  30. package/scripts/analyze-trace/analyze-trace.report.ts +100 -0
  31. package/scripts/analyze-trace/analyze-trace.shared.ts +116 -0
  32. package/scripts/analyze-trace/analyze-trace.ts +45 -0
  33. package/scripts/analyze-trace/analyze-trace.types.ts +72 -0
  34. package/scripts/assets/theme.css +80 -23
  35. package/scripts/copy-examples.ts +239 -0
  36. package/scripts/export-onnx.ts +223 -0
  37. package/scripts/generate-bench-tables.ts +378 -37
  38. package/scripts/generate-docs/generate-docs.constants.ts +107 -0
  39. package/scripts/generate-docs/generate-docs.order.ts +355 -0
  40. package/scripts/generate-docs/generate-docs.state.ts +31 -0
  41. package/scripts/generate-docs/generate-docs.targets.ts +165 -0
  42. package/scripts/generate-docs/generate-docs.ts +63 -0
  43. package/scripts/generate-docs/generate-docs.types.ts +112 -0
  44. package/scripts/generate-docs/output/generate-docs.output.folder-index.utils.ts +167 -0
  45. package/scripts/generate-docs/output/generate-docs.output.ordering.utils.ts +353 -0
  46. package/scripts/generate-docs/output/generate-docs.output.readme.utils.ts +420 -0
  47. package/scripts/generate-docs/output/generate-docs.output.ts +123 -0
  48. package/scripts/generate-docs/output/generate-docs.output.warnings.utils.ts +219 -0
  49. package/scripts/generate-docs/symbols/generate-docs.symbols.collection.utils.ts +365 -0
  50. package/scripts/generate-docs/symbols/generate-docs.symbols.jsdoc.utils.ts +373 -0
  51. package/scripts/generate-docs/symbols/generate-docs.symbols.normalize.utils.ts +155 -0
  52. package/scripts/generate-docs/symbols/generate-docs.symbols.render.utils.ts +149 -0
  53. package/scripts/generate-docs/symbols/generate-docs.symbols.signature.utils.ts +289 -0
  54. package/scripts/generate-docs/symbols/generate-docs.symbols.ts +11 -0
  55. package/scripts/mermaid-cli.mjs +102 -22
  56. package/scripts/mermaid-cli.ts +736 -0
  57. package/scripts/render-docs-html/render-docs-html.assets.ts +54 -0
  58. package/scripts/render-docs-html/render-docs-html.mermaid.ts +245 -0
  59. package/scripts/{render-docs-html.sidebar.ts → render-docs-html/render-docs-html.navigation.ts} +141 -144
  60. package/scripts/render-docs-html/render-docs-html.pages.ts +333 -0
  61. package/scripts/render-docs-html/render-docs-html.shared.ts +333 -0
  62. package/scripts/render-docs-html/render-docs-html.types.ts +42 -0
  63. package/scripts/render-docs-html.ts +23 -587
  64. package/scripts/run-docs.ts +238 -0
  65. package/scripts/write-dist-docs-pkg.ts +40 -0
  66. package/src/README.md +75 -75
  67. package/src/architecture/connection/README.md +5 -5
  68. package/src/architecture/layer/README.md +508 -508
  69. package/src/architecture/network/README.md +1458 -1458
  70. package/src/architecture/network/activate/README.md +694 -694
  71. package/src/architecture/network/bootstrap/README.md +77 -77
  72. package/src/architecture/network/connect/README.md +74 -74
  73. package/src/architecture/network/deterministic/README.md +135 -135
  74. package/src/architecture/network/evolve/README.md +364 -364
  75. package/src/architecture/network/gating/README.md +130 -130
  76. package/src/architecture/network/genetic/README.md +399 -399
  77. package/src/architecture/network/mutate/README.md +897 -897
  78. package/src/architecture/network/onnx/README.md +720 -720
  79. package/src/architecture/network/onnx/export/README.md +728 -728
  80. package/src/architecture/network/onnx/export/layers/README.md +450 -450
  81. package/src/architecture/network/onnx/import/README.md +618 -618
  82. package/src/architecture/network/onnx/schema/README.md +32 -32
  83. package/src/architecture/network/prune/README.md +245 -245
  84. package/src/architecture/network/remove/README.md +135 -135
  85. package/src/architecture/network/runtime/README.md +106 -106
  86. package/src/architecture/network/serialize/README.md +542 -542
  87. package/src/architecture/network/slab/README.md +608 -608
  88. package/src/architecture/network/standalone/README.md +212 -212
  89. package/src/architecture/network/stats/README.md +84 -84
  90. package/src/architecture/network/topology/README.md +465 -465
  91. package/src/architecture/network/training/README.md +200 -200
  92. package/src/architecture/node/README.md +5 -5
  93. package/src/architecture/nodePool/README.md +14 -14
  94. package/src/methods/README.md +99 -99
  95. package/src/methods/activation/README.md +189 -189
  96. package/src/methods/cost/README.md +131 -131
  97. package/src/methods/rate/README.md +86 -86
  98. package/src/multithreading/README.md +77 -77
  99. package/src/multithreading/workers/browser/README.md +8 -8
  100. package/src/multithreading/workers/node/README.md +8 -8
  101. package/src/neat/README.md +148 -148
  102. package/src/neat/adaptive/README.md +120 -120
  103. package/src/neat/adaptive/acceptance/README.md +40 -40
  104. package/src/neat/adaptive/complexity/README.md +137 -137
  105. package/src/neat/adaptive/core/README.md +197 -197
  106. package/src/neat/adaptive/lineage/README.md +90 -90
  107. package/src/neat/adaptive/mutation/README.md +284 -284
  108. package/src/neat/compat/README.md +43 -43
  109. package/src/neat/compat/core/README.md +90 -90
  110. package/src/neat/diversity/README.md +35 -35
  111. package/src/neat/diversity/core/README.md +88 -88
  112. package/src/neat/evaluate/README.md +85 -85
  113. package/src/neat/evaluate/auto-distance/README.md +75 -75
  114. package/src/neat/evaluate/entropy-compat/README.md +37 -37
  115. package/src/neat/evaluate/entropy-sharing/README.md +43 -43
  116. package/src/neat/evaluate/fitness/README.md +23 -23
  117. package/src/neat/evaluate/novelty/README.md +120 -120
  118. package/src/neat/evaluate/objectives/README.md +17 -17
  119. package/src/neat/evaluate/shared/README.md +94 -94
  120. package/src/neat/evolve/README.md +96 -96
  121. package/src/neat/evolve/adaptive/README.md +60 -60
  122. package/src/neat/evolve/objectives/README.md +63 -63
  123. package/src/neat/evolve/offspring/README.md +56 -56
  124. package/src/neat/evolve/population/README.md +171 -171
  125. package/src/neat/evolve/runtime/README.md +79 -79
  126. package/src/neat/evolve/speciation/README.md +74 -74
  127. package/src/neat/evolve/warnings/README.md +10 -10
  128. package/src/neat/export/README.md +114 -114
  129. package/src/neat/helpers/README.md +50 -50
  130. package/src/neat/init/README.md +9 -9
  131. package/src/neat/lineage/core/README.md +101 -101
  132. package/src/neat/multiobjective/category/README.md +74 -74
  133. package/src/neat/multiobjective/crowding/README.md +272 -272
  134. package/src/neat/multiobjective/dominance/README.md +171 -171
  135. package/src/neat/multiobjective/fronts/README.md +68 -68
  136. package/src/neat/multiobjective/metrics/README.md +43 -43
  137. package/src/neat/multiobjective/objectives/README.md +31 -31
  138. package/src/neat/multiobjective/shared/README.md +27 -27
  139. package/src/neat/mutation/README.md +97 -97
  140. package/src/neat/mutation/add-conn/README.md +115 -115
  141. package/src/neat/mutation/add-node/README.md +126 -126
  142. package/src/neat/mutation/flow/README.md +149 -149
  143. package/src/neat/mutation/repair/README.md +185 -185
  144. package/src/neat/mutation/select/README.md +117 -117
  145. package/src/neat/mutation/shared/README.md +32 -32
  146. package/src/neat/objectives/README.md +25 -25
  147. package/src/neat/objectives/core/README.md +67 -67
  148. package/src/neat/pruning/README.md +40 -40
  149. package/src/neat/pruning/core/README.md +171 -171
  150. package/src/neat/pruning/facade/README.md +32 -32
  151. package/src/neat/rng/README.md +104 -104
  152. package/src/neat/rng/core/README.md +137 -137
  153. package/src/neat/rng/facade/README.md +50 -50
  154. package/src/neat/selection/README.md +111 -111
  155. package/src/neat/selection/core/README.md +227 -227
  156. package/src/neat/selection/facade/README.md +61 -61
  157. package/src/neat/shared/README.md +163 -163
  158. package/src/neat/speciation/README.md +31 -31
  159. package/src/neat/speciation/threshold/README.md +35 -35
  160. package/src/neat/species/README.md +25 -25
  161. package/src/neat/species/core/README.md +20 -20
  162. package/src/neat/species/core/shared/README.md +18 -18
  163. package/src/neat/species/history/context/README.md +22 -22
  164. package/src/neat/telemetry/accessors/README.md +58 -58
  165. package/src/neat/telemetry/exports/README.md +233 -233
  166. package/src/neat/telemetry/facade/README.md +252 -252
  167. package/src/neat/telemetry/facade/archive/README.md +57 -57
  168. package/src/neat/telemetry/facade/buffer/README.md +43 -43
  169. package/src/neat/telemetry/facade/lineage/README.md +12 -12
  170. package/src/neat/telemetry/facade/objectives/README.md +44 -44
  171. package/src/neat/telemetry/facade/runtime/README.md +26 -26
  172. package/src/neat/telemetry/facade/species/README.md +27 -27
  173. package/src/neat/telemetry/metrics/README.md +696 -696
  174. package/src/neat/telemetry/recorder/README.md +57 -57
  175. package/src/neat/telemetry/types/README.md +32 -32
  176. package/src/neat/topology-intent/README.md +75 -75
  177. package/src/utils/README.md +193 -193
  178. package/test/examples/asciiMaze/browser-entry/README.md +92 -92
  179. package/test/examples/asciiMaze/dashboardManager/README.md +109 -109
  180. package/test/examples/asciiMaze/dashboardManager/telemetry/README.md +28 -28
  181. package/test/examples/asciiMaze/evolutionEngine/README.md +1527 -1527
  182. package/test/examples/asciiMaze/mazeMovement/README.md +105 -105
  183. package/test/examples/asciiMaze/mazeMovement/finalization/README.md +16 -16
  184. package/test/examples/asciiMaze/mazeMovement/policy/README.md +57 -57
  185. package/test/examples/asciiMaze/mazeMovement/runtime/README.md +52 -52
  186. package/test/examples/asciiMaze/mazeMovement/shaping/README.md +46 -46
  187. package/test/examples/flappy_bird/browser-entry/README.md +508 -508
  188. package/test/examples/flappy_bird/browser-entry/host/README.md +101 -101
  189. package/test/examples/flappy_bird/browser-entry/host/resize/README.md +144 -144
  190. package/test/examples/flappy_bird/browser-entry/network-view/README.md +194 -194
  191. package/test/examples/flappy_bird/browser-entry/playback/README.md +278 -278
  192. package/test/examples/flappy_bird/browser-entry/playback/background/README.md +129 -129
  193. package/test/examples/flappy_bird/browser-entry/playback/background/ground-grid/README.md +502 -502
  194. package/test/examples/flappy_bird/browser-entry/playback/frame-render/README.md +139 -139
  195. package/test/examples/flappy_bird/browser-entry/playback/snapshot/README.md +10 -10
  196. package/test/examples/flappy_bird/browser-entry/playback/trail/README.md +43 -43
  197. package/test/examples/flappy_bird/browser-entry/playback/worker-channel/README.md +30 -30
  198. package/test/examples/flappy_bird/browser-entry/runtime/README.md +59 -59
  199. package/test/examples/flappy_bird/browser-entry/visualization/README.md +276 -276
  200. package/test/examples/flappy_bird/browser-entry/worker-channel/README.md +16 -16
  201. package/test/examples/flappy_bird/constants/README.md +1070 -1070
  202. package/test/examples/flappy_bird/environment/README.md +22 -22
  203. package/test/examples/flappy_bird/evaluation/README.md +32 -32
  204. package/test/examples/flappy_bird/evaluation/rollout/README.md +141 -141
  205. package/test/examples/flappy_bird/flappy-evolution-worker/README.md +425 -425
  206. package/test/examples/flappy_bird/simulation-shared/README.md +170 -170
  207. package/test/examples/flappy_bird/simulation-shared/observation/README.md +109 -109
  208. package/test/examples/flappy_bird/trainer/README.md +325 -325
  209. package/test/examples/flappy_bird/trainer/evaluation/README.md +74 -74
  210. package/scripts/analyze-trace.ts +0 -590
  211. package/scripts/copy-examples.mjs +0 -114
  212. package/scripts/export-onnx.mjs +0 -86
  213. package/scripts/generate-bench-tables.mjs +0 -182
  214. package/scripts/generate-docs.ts +0 -2900
  215. package/scripts/write-dist-docs-pkg.mjs +0 -16
@@ -0,0 +1,289 @@
1
+ /*
2
+ * Formats and parses callable signature text for generated README output.
3
+ *
4
+ * ts-morph returns rich type text that is useful but often noisy for docs.
5
+ * This chapter normalizes those signatures into stable stored strings and
6
+ * re-expands them into readable fenced blocks when rendering markdown.
7
+ */
8
+
9
+ import * as path from 'path';
10
+
11
+ import { WORKSPACE_ROOT_DIR } from '../generate-docs.constants.js';
12
+
13
+ /**
14
+ * Formats a stored call signature into a human-friendly TypeScript block.
15
+ *
16
+ * @param symbolName - Symbol name shown in the heading.
17
+ * @param signature - Stored canonical call signature.
18
+ * @returns Fenced TypeScript block lines.
19
+ */
20
+ export function renderSignatureBlock(
21
+ symbolName: string,
22
+ signature: string,
23
+ ): string[] {
24
+ const parsedSignature = parseCallSignature(signature);
25
+ if (!parsedSignature) {
26
+ return ['```ts', `${symbolName}${signature}`, '```'];
27
+ }
28
+
29
+ if (parsedSignature.parameters.length === 0) {
30
+ return ['```ts', `${symbolName}(): ${parsedSignature.returnType}`, '```'];
31
+ }
32
+
33
+ return [
34
+ '```ts',
35
+ `${symbolName}(`,
36
+ ...parsedSignature.parameters.map((parameter) => ` ${parameter},`),
37
+ `): ${parsedSignature.returnType}`,
38
+ '```',
39
+ ];
40
+ }
41
+
42
+ /**
43
+ * Resolves a call signature string from a declaration-like node.
44
+ *
45
+ * The stored format is the canonical round-trip shape used by this boundary:
46
+ * `(param: Type, other: Type) => ReturnType`. `renderSignatureBlock` later
47
+ * parses that value back into a fenced TypeScript block for generated README
48
+ * sections.
49
+ *
50
+ * Non-callable declarations intentionally return `undefined` so symbol
51
+ * collection can stay best-effort instead of treating missing signatures as a
52
+ * hard failure.
53
+ *
54
+ * @param declaration - Declaration-like node.
55
+ * @returns Signature string when the declaration is callable.
56
+ * @example
57
+ * const signature = resolveCallSignature(declaration);
58
+ * // => "(value: number) => string"
59
+ */
60
+ export function resolveCallSignature(declaration: any): string | undefined {
61
+ try {
62
+ const declarationType =
63
+ declaration.getType?.() || declaration.getSymbol?.()?.getType?.();
64
+ const callSignature = declarationType?.getCallSignatures?.()[0];
65
+ if (!callSignature) {
66
+ return undefined;
67
+ }
68
+
69
+ const renderedParameters = callSignature
70
+ .getParameters()
71
+ .map((parameter: any) => {
72
+ const parameterDeclarations = parameter.getDeclarations();
73
+ const parameterType = normalizeRenderedTypeText(
74
+ parameter
75
+ .getTypeAtLocation(parameterDeclarations[0] || declaration)
76
+ .getText(),
77
+ );
78
+ return `${parameter.getName()}: ${parameterType}`;
79
+ })
80
+ .join(', ');
81
+
82
+ const returnType = normalizeRenderedTypeText(
83
+ callSignature.getReturnType().getText(),
84
+ );
85
+ return `(${renderedParameters}) => ${returnType}`;
86
+ } catch {
87
+ return undefined;
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Extracts the balanced parameter-list portion of a stored call signature.
93
+ *
94
+ * @param signature - Stored canonical call signature.
95
+ * @returns Parameter-list text including the outer parentheses when recognized.
96
+ * @example
97
+ * extractCallSignatureParameterList('(value: number, cb: (x: number) => void) => string');
98
+ * // => '(value: number, cb: (x: number) => void)'
99
+ */
100
+ export function extractCallSignatureParameterList(
101
+ signature: string,
102
+ ): string | undefined {
103
+ if (!signature.startsWith('(')) {
104
+ return undefined;
105
+ }
106
+
107
+ const closingParenthesisIndex = findMatchingDelimiter(signature, 0, '(', ')');
108
+ if (closingParenthesisIndex === -1) {
109
+ return undefined;
110
+ }
111
+
112
+ return signature.slice(0, closingParenthesisIndex + 1);
113
+ }
114
+
115
+ /**
116
+ * Parses a canonical stored call signature.
117
+ *
118
+ * @param signature - Stored canonical call signature.
119
+ * @returns Parsed parameters and return type when recognized.
120
+ */
121
+ function parseCallSignature(
122
+ signature: string,
123
+ ): { parameters: string[]; returnType: string } | undefined {
124
+ const parameterList = extractCallSignatureParameterList(signature);
125
+ if (!parameterList) {
126
+ return undefined;
127
+ }
128
+
129
+ const parameterListText = parameterList.slice(1, -1);
130
+ const returnTypePrefix = signature.slice(parameterList.length).trimStart();
131
+ if (!returnTypePrefix.startsWith('=>')) {
132
+ return undefined;
133
+ }
134
+
135
+ return {
136
+ parameters: splitTopLevelCommaSeparated(parameterListText),
137
+ returnType: returnTypePrefix.slice(2).trim(),
138
+ };
139
+ }
140
+
141
+ /**
142
+ * Splits a comma-separated type list while respecting nested delimiters.
143
+ *
144
+ * @param value - Comma-separated text.
145
+ * @returns Top-level list entries.
146
+ */
147
+ function splitTopLevelCommaSeparated(value: string): string[] {
148
+ if (!value.trim()) {
149
+ return [];
150
+ }
151
+
152
+ const segments: string[] = [];
153
+ let segmentStartIndex = 0;
154
+ let parenthesisDepth = 0;
155
+ let bracketDepth = 0;
156
+ let braceDepth = 0;
157
+ let angleDepth = 0;
158
+
159
+ for (let index = 0; index < value.length; index += 1) {
160
+ const character = value[index];
161
+ if (character === '(') {
162
+ parenthesisDepth += 1;
163
+ continue;
164
+ }
165
+
166
+ if (character === ')') {
167
+ parenthesisDepth -= 1;
168
+ continue;
169
+ }
170
+
171
+ if (character === '[') {
172
+ bracketDepth += 1;
173
+ continue;
174
+ }
175
+
176
+ if (character === ']') {
177
+ bracketDepth -= 1;
178
+ continue;
179
+ }
180
+
181
+ if (character === '{') {
182
+ braceDepth += 1;
183
+ continue;
184
+ }
185
+
186
+ if (character === '}') {
187
+ braceDepth -= 1;
188
+ continue;
189
+ }
190
+
191
+ if (character === '<') {
192
+ angleDepth += 1;
193
+ continue;
194
+ }
195
+
196
+ if (character === '>') {
197
+ angleDepth = Math.max(0, angleDepth - 1);
198
+ continue;
199
+ }
200
+
201
+ const isTopLevelComma =
202
+ character === ',' &&
203
+ parenthesisDepth === 0 &&
204
+ bracketDepth === 0 &&
205
+ braceDepth === 0 &&
206
+ angleDepth === 0;
207
+ if (!isTopLevelComma) {
208
+ continue;
209
+ }
210
+
211
+ segments.push(value.slice(segmentStartIndex, index).trim());
212
+ segmentStartIndex = index + 1;
213
+ }
214
+
215
+ segments.push(value.slice(segmentStartIndex).trim());
216
+ return segments.filter(Boolean);
217
+ }
218
+
219
+ /**
220
+ * Finds the matching closing delimiter for a starting delimiter.
221
+ *
222
+ * @param value - Text to inspect.
223
+ * @param startIndex - Opening delimiter index.
224
+ * @param openingDelimiter - Opening delimiter character.
225
+ * @param closingDelimiter - Closing delimiter character.
226
+ * @returns Closing delimiter index when found.
227
+ */
228
+ function findMatchingDelimiter(
229
+ value: string,
230
+ startIndex: number,
231
+ openingDelimiter: string,
232
+ closingDelimiter: string,
233
+ ): number {
234
+ let delimiterDepth = 0;
235
+
236
+ for (let index = startIndex; index < value.length; index += 1) {
237
+ const character = value[index];
238
+ if (character === openingDelimiter) {
239
+ delimiterDepth += 1;
240
+ continue;
241
+ }
242
+
243
+ if (character !== closingDelimiter) {
244
+ continue;
245
+ }
246
+
247
+ delimiterDepth -= 1;
248
+ if (delimiterDepth === 0) {
249
+ return index;
250
+ }
251
+ }
252
+
253
+ return -1;
254
+ }
255
+
256
+ /**
257
+ * Rewrites absolute import paths from ts-morph type text into repo-relative paths.
258
+ *
259
+ * @param typeText - Raw type text returned by ts-morph.
260
+ * @returns Normalized type text safe for generated docs.
261
+ */
262
+ function normalizeRenderedTypeText(typeText: string): string {
263
+ const normalizedImportPaths = typeText.replace(
264
+ /import\((['"])([^'"]+)\1\)/g,
265
+ (_match, quote: string, importPath: string) => {
266
+ const normalizedImportPath = path.normalize(importPath);
267
+ if (!path.isAbsolute(normalizedImportPath)) {
268
+ return `import(${quote}${importPath}${quote})`;
269
+ }
270
+
271
+ const relativeImportPath = path
272
+ .relative(WORKSPACE_ROOT_DIR, normalizedImportPath)
273
+ .replace(/\\/g, '/');
274
+
275
+ const portableImportPath = relativeImportPath.startsWith('..')
276
+ ? importPath.replace(/\\/g, '/')
277
+ : relativeImportPath;
278
+
279
+ return `import(${quote}${portableImportPath}${quote})`;
280
+ },
281
+ );
282
+
283
+ return normalizedImportPaths
284
+ .replace(
285
+ /\btypeof\s+import\((['"])([^'"]+)\1\)\.([A-Za-z_$][\w$]*)/g,
286
+ 'typeof $3',
287
+ )
288
+ .replace(/import\((['"])([^'"]+)\1\)\.([A-Za-z_$][\w$]*)/g, '$3');
289
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Public symbols boundary for the folderized docs generator.
3
+ *
4
+ * This root exposes the stable symbol-facing surface while the detailed
5
+ * collection, normalization, JSDoc parsing, and signature work live in
6
+ * narrower helper chapters inside this folder.
7
+ */
8
+
9
+ export { collectDirectorySymbols } from './generate-docs.symbols.collection.utils.js';
10
+ export { dedupeDirectorySymbols } from './generate-docs.symbols.normalize.utils.js';
11
+ export { renderSignatureBlock } from './generate-docs.symbols.signature.utils.js';
@@ -1,7 +1,8 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { mkdtemp, mkdir, rm } from 'node:fs/promises';
2
+ import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises';
3
3
  import os from 'node:os';
4
4
  import path from 'node:path';
5
+
5
6
  const EXPORT_COMMAND = 'export';
6
7
  const VALIDATE_COMMAND = 'validate';
7
8
  const SUPPORTED_COMMANDS = new Set([EXPORT_COMMAND, VALIDATE_COMMAND]);
@@ -38,7 +39,11 @@ function parseArguments(rawArgs) {
38
39
  const named = {};
39
40
  const passthrough = [];
40
41
 
41
- for (let argumentIndex = 0; argumentIndex < rawArgs.length; argumentIndex += 1) {
42
+ for (
43
+ let argumentIndex = 0;
44
+ argumentIndex < rawArgs.length;
45
+ argumentIndex += 1
46
+ ) {
42
47
  const argument = rawArgs[argumentIndex];
43
48
  if (!argument.startsWith('--')) {
44
49
  passthrough.push(argument);
@@ -81,10 +86,9 @@ async function runValidateCommand(cliPath, inputPath, parsedArguments) {
81
86
  path.join(os.tmpdir(), 'neatapticts-mermaid-'),
82
87
  );
83
88
  const tempOutputPath = path.join(tempDirectoryPath, 'diagram.svg');
84
-
85
- try {
86
- await mkdir(path.dirname(tempOutputPath), { recursive: true });
87
- await runMermaidCli(cliPath, [
89
+ const mermaidCliInvocation = await buildMermaidCliInvocation(
90
+ parsedArguments,
91
+ [
88
92
  '--input',
89
93
  inputPath,
90
94
  '--output',
@@ -92,25 +96,45 @@ async function runValidateCommand(cliPath, inputPath, parsedArguments) {
92
96
  ...buildPassthroughArguments(parsedArguments, {
93
97
  excludedNames: new Set(['input', 'i', 'output', 'o']),
94
98
  }),
95
- ]);
99
+ ],
100
+ );
101
+
102
+ try {
103
+ await mkdir(path.dirname(tempOutputPath), { recursive: true });
104
+ await runMermaidCli(cliPath, mermaidCliInvocation.argumentsToPass);
96
105
  console.log(`[mermaid] Valid diagram: ${inputPath}`);
97
106
  } finally {
107
+ await mermaidCliInvocation.cleanup();
98
108
  await rm(tempDirectoryPath, { recursive: true, force: true });
99
109
  }
100
110
  }
101
111
 
102
- async function runExportCommand(cliPath, inputPath, outputPath, parsedArguments) {
112
+ async function runExportCommand(
113
+ cliPath,
114
+ inputPath,
115
+ outputPath,
116
+ parsedArguments,
117
+ ) {
103
118
  await mkdir(path.dirname(path.resolve(outputPath)), { recursive: true });
104
- await runMermaidCli(cliPath, [
105
- '--input',
106
- inputPath,
107
- '--output',
108
- outputPath,
109
- ...buildPassthroughArguments(parsedArguments, {
110
- excludedNames: new Set(['input', 'i', 'output', 'o']),
111
- }),
112
- ]);
113
- console.log(`[mermaid] Exported diagram to ${outputPath}`);
119
+ const mermaidCliInvocation = await buildMermaidCliInvocation(
120
+ parsedArguments,
121
+ [
122
+ '--input',
123
+ inputPath,
124
+ '--output',
125
+ outputPath,
126
+ ...buildPassthroughArguments(parsedArguments, {
127
+ excludedNames: new Set(['input', 'i', 'output', 'o']),
128
+ }),
129
+ ],
130
+ );
131
+
132
+ try {
133
+ await runMermaidCli(cliPath, mermaidCliInvocation.argumentsToPass);
134
+ console.log(`[mermaid] Exported diagram to ${outputPath}`);
135
+ } finally {
136
+ await mermaidCliInvocation.cleanup();
137
+ }
114
138
  }
115
139
 
116
140
  function buildPassthroughArguments(parsedArguments, options) {
@@ -129,9 +153,13 @@ function buildPassthroughArguments(parsedArguments, options) {
129
153
 
130
154
  async function runMermaidCli(cliPath, argumentsToPass) {
131
155
  await new Promise((resolve, reject) => {
132
- const childProcess = spawn(process.execPath, [cliPath, ...argumentsToPass], {
133
- stdio: 'inherit',
134
- });
156
+ const childProcess = spawn(
157
+ process.execPath,
158
+ [cliPath, ...argumentsToPass],
159
+ {
160
+ stdio: 'inherit',
161
+ },
162
+ );
135
163
 
136
164
  childProcess.once('exit', (exitCode) => {
137
165
  if (exitCode === 0) {
@@ -145,6 +173,58 @@ async function runMermaidCli(cliPath, argumentsToPass) {
145
173
  });
146
174
  }
147
175
 
176
+ async function buildMermaidCliInvocation(parsedArguments, baseArguments) {
177
+ if (!shouldInjectCiLinuxNoSandbox(parsedArguments)) {
178
+ return {
179
+ argumentsToPass: baseArguments,
180
+ cleanup: async () => {},
181
+ };
182
+ }
183
+
184
+ const tempDirectoryPath = await mkdtemp(
185
+ path.join(os.tmpdir(), 'neatapticts-mermaid-puppeteer-'),
186
+ );
187
+ const puppeteerConfigFilePath = path.join(
188
+ tempDirectoryPath,
189
+ 'puppeteer-config.json',
190
+ );
191
+
192
+ await writeFile(
193
+ puppeteerConfigFilePath,
194
+ JSON.stringify({
195
+ args: ['--no-sandbox', '--disable-setuid-sandbox'],
196
+ }),
197
+ );
198
+
199
+ return {
200
+ argumentsToPass: [
201
+ '--puppeteerConfigFile',
202
+ puppeteerConfigFilePath,
203
+ ...baseArguments,
204
+ ],
205
+ cleanup: async () => {
206
+ await rm(tempDirectoryPath, { recursive: true, force: true });
207
+ },
208
+ };
209
+ }
210
+
211
+ function shouldInjectCiLinuxNoSandbox(parsedArguments) {
212
+ return (
213
+ process.platform === 'linux' &&
214
+ (process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true') &&
215
+ !hasExplicitPuppeteerConfig(parsedArguments)
216
+ );
217
+ }
218
+
219
+ function hasExplicitPuppeteerConfig(parsedArguments) {
220
+ return (
221
+ parsedArguments.named.puppeteerConfigFile !== undefined ||
222
+ parsedArguments.named.p !== undefined ||
223
+ parsedArguments.passthrough.includes('--puppeteerConfigFile') ||
224
+ parsedArguments.passthrough.includes('-p')
225
+ );
226
+ }
227
+
148
228
  function printUsageAndExit(message) {
149
229
  console.error(`[mermaid] ${message}`);
150
230
  console.error(
@@ -155,4 +235,4 @@ function printUsageAndExit(message) {
155
235
  ].join('\n'),
156
236
  );
157
237
  process.exit(1);
158
- }
238
+ }