@md-code/follow-architecture 0.3.0 → 0.3.3

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 (382) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +1341 -472
  3. package/dist/args.d.ts +4 -0
  4. package/dist/args.js +18 -1
  5. package/dist/bin/follow-architecture.js +3 -3
  6. package/dist/closure-project.d.ts +4 -0
  7. package/dist/closure-project.js +122 -0
  8. package/dist/code-entities/classify.d.ts +11 -0
  9. package/dist/code-entities/classify.js +45 -0
  10. package/dist/code-entities/connector.d.ts +8 -0
  11. package/dist/code-entities/connector.js +119 -0
  12. package/dist/code-entities/entities.d.ts +9 -0
  13. package/dist/{code-roles/roles.js → code-entities/entities.js} +81 -54
  14. package/dist/code-entities/project.d.ts +21 -0
  15. package/dist/code-entities/project.js +249 -0
  16. package/dist/code-entities/walk.d.ts +31 -0
  17. package/dist/code-entities/walk.js +95 -0
  18. package/dist/config-options.d.ts +23 -0
  19. package/dist/config-options.js +18 -1
  20. package/dist/config-project.js +10 -2
  21. package/dist/config-report.d.ts +1 -1
  22. package/dist/config-report.js +20 -3
  23. package/dist/config-rule.d.ts +25 -0
  24. package/dist/config-rule.js +89 -6
  25. package/dist/config-state.d.ts +14 -3
  26. package/dist/config-state.js +180 -17
  27. package/dist/config.d.ts +25 -0
  28. package/dist/css/index.d.ts +11 -7
  29. package/dist/css/index.js +124 -23
  30. package/dist/css/syntax/css/gate.js +5 -5
  31. package/dist/css/syntax/css/index.d.ts +1 -1
  32. package/dist/css/syntax/css/index.js +1 -1
  33. package/dist/css/syntax/css/reference.d.ts +1 -1
  34. package/dist/css/syntax/css/reference.js +15 -3
  35. package/dist/css/syntax/language.d.ts +1 -1
  36. package/dist/css/syntax/language.js +4 -2
  37. package/dist/css/syntax/scss/index.d.ts +2 -2
  38. package/dist/css/syntax/scss/index.js +1 -1
  39. package/dist/css/syntax/scss/reference.d.ts +1 -1
  40. package/dist/css/syntax/scss/reference.js +7 -1
  41. package/dist/css/syntax/styled/document.d.ts +3 -3
  42. package/dist/css/syntax/styled/document.js +17 -7
  43. package/dist/css/syntax/styled/markup.d.ts +1 -1
  44. package/dist/css/syntax/styled/markup.js +22 -14
  45. package/dist/css/syntax/styled/tags.d.ts +2 -0
  46. package/dist/css/syntax/styled/tags.js +22 -0
  47. package/dist/css/syntax/styled/template.js +10 -4
  48. package/dist/css/syntax/tailwind/tailwind.js +4 -4
  49. package/dist/css/value/check.d.ts +1 -1
  50. package/dist/css/value/check.js +1 -1
  51. package/dist/css/value/expression/arithmetic.d.ts +2 -2
  52. package/dist/css/value/expression/arithmetic.js +7 -3
  53. package/dist/css/value/expression/block.d.ts +2 -2
  54. package/dist/css/value/expression/block.js +4 -3
  55. package/dist/css/value/expression/conditional.d.ts +2 -2
  56. package/dist/css/value/expression/conditional.js +1 -1
  57. package/dist/css/value/expression/index.d.ts +2 -2
  58. package/dist/css/value/expression/index.js +10 -6
  59. package/dist/css/value/expression/map.d.ts +2 -2
  60. package/dist/css/value/expression/map.js +2 -2
  61. package/dist/css/value/object/index.d.ts +2 -2
  62. package/dist/css/value/object/index.js +14 -4
  63. package/dist/css/value/object/members.d.ts +2 -2
  64. package/dist/css/value/object/node.js +9 -4
  65. package/dist/css/value/object/path.d.ts +3 -3
  66. package/dist/css/value/object/path.js +10 -4
  67. package/dist/css/value/pieces.d.ts +3 -3
  68. package/dist/css/value/pieces.js +14 -4
  69. package/dist/css/value/resolve.js +15 -5
  70. package/dist/css/value/scope.d.ts +3 -2
  71. package/dist/css/value/scope.js +25 -7
  72. package/dist/css/value/substitute.js +43 -11
  73. package/dist/entities/architecture.d.ts +28 -25
  74. package/dist/entities/ast/assignments-raw.d.ts +1 -1
  75. package/dist/entities/ast/assignments-raw.js +61 -8
  76. package/dist/entities/ast/assignments-tagged.d.ts +1 -1
  77. package/dist/entities/ast/assignments-tagged.js +22 -7
  78. package/dist/entities/ast/assignments.d.ts +1 -1
  79. package/dist/entities/ast/assignments.js +6 -4
  80. package/dist/entities/ast/branches.d.ts +1 -1
  81. package/dist/entities/ast/calls.d.ts +1 -1
  82. package/dist/entities/ast/calls.js +19 -3
  83. package/dist/entities/ast/classes.d.ts +1 -1
  84. package/dist/entities/ast/classes.js +5 -1
  85. package/dist/entities/ast/comments.d.ts +3 -2
  86. package/dist/entities/ast/comments.js +47 -17
  87. package/dist/entities/ast/declaration.d.ts +1 -1
  88. package/dist/entities/ast/depth.d.ts +2 -2
  89. package/dist/entities/ast/depth.js +15 -8
  90. package/dist/entities/ast/enums.d.ts +1 -1
  91. package/dist/entities/ast/export-chain.d.ts +15 -0
  92. package/dist/entities/ast/export-chain.js +171 -0
  93. package/dist/entities/ast/file-exports.d.ts +1 -1
  94. package/dist/entities/ast/file-exports.js +26 -3
  95. package/dist/entities/ast/file-facts.d.ts +6 -3
  96. package/dist/entities/ast/file-facts.js +33 -4
  97. package/dist/entities/ast/file-imports.d.ts +1 -1
  98. package/dist/entities/ast/file-imports.js +26 -3
  99. package/dist/entities/ast/file.d.ts +2 -2
  100. package/dist/entities/ast/file.js +2 -1
  101. package/dist/entities/ast/functions.d.ts +1 -1
  102. package/dist/entities/ast/functions.js +13 -4
  103. package/dist/entities/ast/heritage.d.ts +1 -1
  104. package/dist/entities/ast/heritage.js +9 -1
  105. package/dist/entities/ast/index.d.ts +6 -3
  106. package/dist/entities/ast/index.js +82 -26
  107. package/dist/entities/ast/kind.d.ts +1 -1
  108. package/dist/entities/ast/kind.js +7 -1
  109. package/dist/entities/ast/modifiers.d.ts +1 -1
  110. package/dist/entities/ast/modifiers.js +4 -4
  111. package/dist/entities/ast/project.js +33 -2
  112. package/dist/entities/ast/properties.d.ts +1 -1
  113. package/dist/entities/ast/properties.js +10 -5
  114. package/dist/entities/ast/resolve.d.ts +1 -1
  115. package/dist/entities/ast/resolve.js +4 -4
  116. package/dist/entities/ast/tree.d.ts +4 -2
  117. package/dist/entities/ast/tree.js +184 -17
  118. package/dist/entities/ast/types.d.ts +1 -1
  119. package/dist/entities/ast/types.js +2 -1
  120. package/dist/entities/ast/usage.d.ts +1 -1
  121. package/dist/entities/ast/usage.js +1 -1
  122. package/dist/entities/ast/variables.d.ts +1 -1
  123. package/dist/entities/context.d.ts +4 -4
  124. package/dist/entities/facts.d.ts +36 -13
  125. package/dist/entities/findings.d.ts +3 -3
  126. package/dist/entities/kinds.d.ts +1 -1
  127. package/dist/entities/kinds.js +131 -30
  128. package/dist/entities/location/homes.d.ts +10 -10
  129. package/dist/entities/location/homes.js +74 -48
  130. package/dist/entities/location/place.d.ts +1 -1
  131. package/dist/entities/location/place.js +10 -3
  132. package/dist/entities/location/where.d.ts +8 -6
  133. package/dist/entities/location/where.js +79 -30
  134. package/dist/entities/location.d.ts +3 -3
  135. package/dist/entities/location.js +17 -17
  136. package/dist/entities/operators.js +1 -1
  137. package/dist/entities/overview/data.d.ts +6 -6
  138. package/dist/entities/overview/decision.d.ts +11 -11
  139. package/dist/entities/overview/finding.d.ts +10 -10
  140. package/dist/entities/overview/graph.d.ts +28 -11
  141. package/dist/entities/overview/input.d.ts +2 -2
  142. package/dist/entities/overview/summaries.d.ts +17 -15
  143. package/dist/entities/queries.d.ts +1 -1
  144. package/dist/entities/queries.js +72 -12
  145. package/dist/entities/repair.d.ts +1 -1
  146. package/dist/entities/repair.js +8 -2
  147. package/dist/entities/schema.d.ts +17 -3
  148. package/dist/entities/schema.js +74 -16
  149. package/dist/entities/story.d.ts +5 -5
  150. package/dist/entities/structure-facts.d.ts +1 -1
  151. package/dist/entities/token.d.ts +4 -4
  152. package/dist/entities/tree/build.d.ts +4 -3
  153. package/dist/entities/tree/build.js +95 -44
  154. package/dist/entities/tree/entries.d.ts +3 -3
  155. package/dist/entities/tree/entries.js +41 -16
  156. package/dist/entities/tree/index.d.ts +2 -2
  157. package/dist/entities/tree/index.js +1 -1
  158. package/dist/entities/tree/match.d.ts +2 -2
  159. package/dist/entities/tree/match.js +9 -5
  160. package/dist/fa-index.d.ts +16 -0
  161. package/dist/fa-index.js +165 -0
  162. package/dist/fa-open.d.ts +51 -0
  163. package/dist/fa-open.js +232 -0
  164. package/dist/fa-store.d.ts +22 -0
  165. package/dist/fa-store.js +222 -0
  166. package/dist/fa-values.d.ts +37 -0
  167. package/dist/fa-values.js +104 -0
  168. package/dist/facts-record.d.ts +45 -0
  169. package/dist/facts-record.js +287 -0
  170. package/dist/frameworks/angular/index.d.ts +2 -2
  171. package/dist/frameworks/angular/index.js +2 -1
  172. package/dist/frameworks/facet.d.ts +3 -1
  173. package/dist/frameworks/facet.js +13 -0
  174. package/dist/frameworks/index.d.ts +1 -1
  175. package/dist/frameworks/index.js +8 -4
  176. package/dist/frameworks/react/index.d.ts +2 -2
  177. package/dist/frameworks/react/index.js +33 -10
  178. package/dist/frameworks/test/index.d.ts +6 -0
  179. package/dist/frameworks/test/index.js +157 -0
  180. package/dist/frameworks/vue/index.d.ts +2 -2
  181. package/dist/frameworks/vue/index.js +2 -1
  182. package/dist/ignore.d.ts +3 -0
  183. package/dist/ignore.js +48 -0
  184. package/dist/index-file.d.ts +43 -0
  185. package/dist/index-file.js +218 -0
  186. package/dist/index-run.d.ts +39 -0
  187. package/dist/index-run.js +217 -0
  188. package/dist/index-zone.d.ts +25 -0
  189. package/dist/index-zone.js +209 -0
  190. package/dist/main.d.ts +5 -2
  191. package/dist/main.js +207 -34
  192. package/dist/nodes/child-entities.d.ts +3 -0
  193. package/dist/nodes/child-entities.js +12 -0
  194. package/dist/nodes/children.d.ts +4 -4
  195. package/dist/nodes/children.js +54 -11
  196. package/dist/nodes/finally/emit.d.ts +3 -3
  197. package/dist/nodes/finally/emit.js +26 -10
  198. package/dist/nodes/finally/entities.d.ts +13 -0
  199. package/dist/nodes/finally/entities.js +42 -0
  200. package/dist/nodes/finally/index.d.ts +6 -6
  201. package/dist/nodes/finally/index.js +8 -8
  202. package/dist/nodes/finally/queries.d.ts +2 -2
  203. package/dist/nodes/finally/queries.js +7 -4
  204. package/dist/nodes/finally/relations-access.d.ts +2 -2
  205. package/dist/nodes/finally/relations-access.js +22 -18
  206. package/dist/nodes/finally/relations-edge.d.ts +5 -5
  207. package/dist/nodes/finally/relations-edge.js +67 -44
  208. package/dist/nodes/finally/relations-group.d.ts +7 -7
  209. package/dist/nodes/finally/relations-group.js +28 -25
  210. package/dist/nodes/finally/relations.d.ts +2 -2
  211. package/dist/nodes/finally/relations.js +16 -12
  212. package/dist/nodes/finally/required.d.ts +3 -3
  213. package/dist/nodes/finally/required.js +9 -7
  214. package/dist/nodes/finally/violation.d.ts +2 -2
  215. package/dist/nodes/similar.d.ts +3 -3
  216. package/dist/nodes/similar.js +61 -49
  217. package/dist/piece-forms.d.ts +9 -0
  218. package/dist/piece-forms.js +68 -0
  219. package/dist/{pipeline-roles.d.ts → pipeline-entities.d.ts} +2 -2
  220. package/dist/{pipeline-roles.js → pipeline-entities.js} +32 -28
  221. package/dist/pipeline-facts.d.ts +4 -3
  222. package/dist/pipeline-facts.js +47 -55
  223. package/dist/{pipeline-unroled.d.ts → pipeline-unclassified.d.ts} +2 -2
  224. package/dist/{pipeline-unroled.js → pipeline-unclassified.js} +58 -63
  225. package/dist/pipeline.js +19 -64
  226. package/dist/release-file.d.ts +3 -0
  227. package/dist/release-file.js +13 -0
  228. package/dist/report/asks.d.ts +3 -3
  229. package/dist/report/asks.js +16 -6
  230. package/dist/report/configErrors.d.ts +55 -27
  231. package/dist/report/configErrors.js +81 -35
  232. package/dist/report/errorTypes/codes/structure.d.ts +1 -1
  233. package/dist/report/errorTypes/codes/structure.js +9 -9
  234. package/dist/report/errorTypes/decision-maker.d.ts +5 -5
  235. package/dist/report/errorTypes/decision-maker.js +4 -4
  236. package/dist/report/errorTypes/destinations.d.ts +5 -5
  237. package/dist/report/errorTypes/destinations.js +52 -34
  238. package/dist/report/errorTypes/finding-type.d.ts +3 -3
  239. package/dist/report/errorTypes/index.d.ts +1 -1
  240. package/dist/report/errorTypes/types/fileContents.d.ts +4 -4
  241. package/dist/report/errorTypes/types/fileContents.js +11 -5
  242. package/dist/report/errorTypes/types/unknownEntity.d.ts +9 -0
  243. package/dist/report/errorTypes/types/{unknownRole.js → unknownEntity.js} +12 -7
  244. package/dist/report/errorTypes/types/wrongAction.d.ts +5 -5
  245. package/dist/report/errorTypes/types/wrongAction.js +18 -13
  246. package/dist/report/errorTypes/types/wrongPlacement.d.ts +4 -4
  247. package/dist/report/errorTypes/types/wrongPlacement.js +19 -9
  248. package/dist/report/errorTypes/vocabulary/ids.d.ts +2 -2
  249. package/dist/report/errorTypes/vocabulary/ids.js +3 -3
  250. package/dist/report/errorTypes/vocabulary/phrases.d.ts +2 -2
  251. package/dist/report/errorTypes/vocabulary/phrases.js +39 -26
  252. package/dist/report/errorTypes/vocabulary/places.d.ts +3 -3
  253. package/dist/report/errorTypes/vocabulary/places.js +13 -13
  254. package/dist/report/finding-from.d.ts +3 -3
  255. package/dist/report/finding-from.js +14 -9
  256. package/dist/report/notices.d.ts +6 -1
  257. package/dist/report/notices.js +46 -20
  258. package/dist/report/observed.d.ts +19 -0
  259. package/dist/report/observed.js +87 -0
  260. package/dist/report/render-report.d.ts +1 -1
  261. package/dist/report/render-report.js +33 -30
  262. package/dist/report/user-report/build/bundle.js +9 -0
  263. package/dist/report/user-report/build/bundle.prebuilt.js +799 -297
  264. package/dist/report/user-report/data/collect.d.ts +2 -2
  265. package/dist/report/user-report/data/collect.js +15 -12
  266. package/dist/report/user-report/data/entities.d.ts +7 -0
  267. package/dist/report/user-report/data/{roles.js → entities.js} +27 -22
  268. package/dist/report/user-report/data/{role-examples.d.ts → entity-examples.d.ts} +3 -3
  269. package/dist/report/user-report/data/entity-examples.js +126 -0
  270. package/dist/report/user-report/data/{role-filters.d.ts → entity-filters.d.ts} +2 -2
  271. package/dist/report/user-report/data/{role-filters.js → entity-filters.js} +7 -7
  272. package/dist/report/user-report/data/entity-marks.d.ts +5 -0
  273. package/dist/report/user-report/data/{role-marks.js → entity-marks.js} +11 -11
  274. package/dist/report/user-report/data/file-tree.d.ts +3 -3
  275. package/dist/report/user-report/data/file-tree.js +13 -5
  276. package/dist/report/user-report/data/finding-boundary.d.ts +4 -4
  277. package/dist/report/user-report/data/finding-boundary.js +2 -2
  278. package/dist/report/user-report/data/finding-plan.d.ts +5 -5
  279. package/dist/report/user-report/data/finding-plan.js +10 -10
  280. package/dist/report/user-report/data/finding-title.d.ts +2 -2
  281. package/dist/report/user-report/data/finding-title.js +8 -8
  282. package/dist/report/user-report/data/findings.d.ts +4 -4
  283. package/dist/report/user-report/data/findings.js +30 -20
  284. package/dist/report/user-report/data/graph-edges.d.ts +4 -4
  285. package/dist/report/user-report/data/graph-edges.js +19 -19
  286. package/dist/report/user-report/data/graph-entities.d.ts +6 -0
  287. package/dist/report/user-report/data/graph-entities.js +158 -0
  288. package/dist/report/user-report/data/graph-helpers.d.ts +5 -5
  289. package/dist/report/user-report/data/graph-helpers.js +15 -15
  290. package/dist/report/user-report/data/graph.d.ts +5 -4
  291. package/dist/report/user-report/data/graph.js +28 -21
  292. package/dist/report/user-report/data/nodes.d.ts +2 -2
  293. package/dist/report/user-report/data/nodes.js +16 -16
  294. package/dist/report/user-report/data/rules.d.ts +7 -0
  295. package/dist/report/user-report/data/{invariants.js → rules.js} +13 -13
  296. package/dist/report/user-report/data/scan.d.ts +1 -1
  297. package/dist/report/user-report/data/scan.js +2 -2
  298. package/dist/report/user-report/html/shell.d.ts +1 -1
  299. package/dist/report/user-report/html/shell.js +1 -1
  300. package/dist/report/user-report/index.d.ts +1 -1
  301. package/dist/report/user-report/shared/describe.d.ts +1 -1
  302. package/dist/report/user-report/shared/describe.js +6 -6
  303. package/dist/rules/index.d.ts +7 -0
  304. package/dist/{invariants → rules}/index.js +85 -57
  305. package/dist/{invariants → rules}/list-vars.d.ts +2 -2
  306. package/dist/{invariants → rules}/list-vars.js +9 -3
  307. package/dist/{invariants → rules}/name.js +2 -2
  308. package/dist/rules/normalize.d.ts +5 -0
  309. package/dist/{invariants → rules}/normalize.js +35 -32
  310. package/dist/{invariants → rules}/vars.d.ts +9 -7
  311. package/dist/{invariants → rules}/vars.js +5 -5
  312. package/dist/scan-run.d.ts +20 -0
  313. package/dist/scan-run.js +130 -0
  314. package/dist/scripts/audit-report.js +2 -2
  315. package/dist/usage-index.d.ts +4 -0
  316. package/dist/usage-index.js +272 -0
  317. package/dist/usage-mode.d.ts +7 -0
  318. package/dist/usage-mode.js +16 -0
  319. package/dist/usage-pass.d.ts +19 -0
  320. package/dist/usage-pass.js +136 -0
  321. package/dist/usage-prepare.d.ts +2 -0
  322. package/dist/usage-prepare.js +22 -0
  323. package/dist/usage-sweep.d.ts +10 -0
  324. package/dist/usage-sweep.js +254 -0
  325. package/dist/utils/aliases.d.ts +22 -0
  326. package/dist/utils/aliases.js +163 -0
  327. package/dist/utils/classify.d.ts +2 -2
  328. package/dist/utils/classify.js +4 -4
  329. package/dist/utils/distinct.js +4 -2
  330. package/dist/utils/files.js +24 -30
  331. package/dist/utils/fixpoint.js +2 -2
  332. package/dist/utils/host.d.ts +1 -1
  333. package/dist/utils/host.js +4 -1
  334. package/dist/utils/imports.js +66 -12
  335. package/dist/utils/keyed.js +2 -2
  336. package/dist/utils/map-record.js +2 -2
  337. package/dist/utils/packages.d.ts +15 -0
  338. package/dist/utils/packages.js +197 -0
  339. package/dist/utils/path-label.js +3 -1
  340. package/dist/utils/pattern.d.ts +5 -4
  341. package/dist/utils/pattern.js +38 -8
  342. package/dist/utils/permission.d.ts +3 -3
  343. package/dist/utils/permission.js +4 -2
  344. package/dist/utils/plural.js +2 -2
  345. package/dist/utils/qualified.js +4 -4
  346. package/dist/utils/rank.js +2 -2
  347. package/dist/utils/record.js +1 -1
  348. package/dist/utils/search.js +7 -2
  349. package/dist/utils/speak.js +1 -1
  350. package/dist/utils/split.js +14 -1
  351. package/dist/utils/template.d.ts +1 -1
  352. package/dist/utils/template.js +1 -1
  353. package/dist/utils/tokenize.js +6 -1
  354. package/dist/utils/typed-field.js +2 -2
  355. package/dist/utils/verdicts.js +1 -1
  356. package/entities/operators.ts +1 -1
  357. package/package.json +101 -90
  358. package/report/errorTypes/vocabulary/ids.ts +7 -2
  359. package/report/errorTypes/vocabulary/phrases.ts +47 -27
  360. package/report/errorTypes/vocabulary/places.ts +21 -16
  361. package/report/user-report/shared/describe.ts +7 -7
  362. package/dist/code-roles/classify.d.ts +0 -11
  363. package/dist/code-roles/classify.js +0 -43
  364. package/dist/code-roles/connector.d.ts +0 -5
  365. package/dist/code-roles/connector.js +0 -114
  366. package/dist/code-roles/project.d.ts +0 -12
  367. package/dist/code-roles/project.js +0 -122
  368. package/dist/code-roles/roles.d.ts +0 -8
  369. package/dist/invariants/index.d.ts +0 -6
  370. package/dist/invariants/normalize.d.ts +0 -4
  371. package/dist/nodes/child-roles.d.ts +0 -3
  372. package/dist/nodes/child-roles.js +0 -12
  373. package/dist/nodes/finally/roles.d.ts +0 -13
  374. package/dist/nodes/finally/roles.js +0 -41
  375. package/dist/report/errorTypes/types/unknownRole.d.ts +0 -9
  376. package/dist/report/user-report/data/graph-roles.d.ts +0 -5
  377. package/dist/report/user-report/data/graph-roles.js +0 -71
  378. package/dist/report/user-report/data/invariants.d.ts +0 -7
  379. package/dist/report/user-report/data/role-examples.js +0 -94
  380. package/dist/report/user-report/data/role-marks.d.ts +0 -5
  381. package/dist/report/user-report/data/roles.d.ts +0 -7
  382. /package/dist/{invariants → rules}/name.d.ts +0 -0
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usageFor = exports.runUsagePass = void 0;
4
+ // THE PASS THAT ASKS THE CHECKER. `references` and `implementations` are the only
5
+ // facts a file's record cannot get from its own syntax: who calls a name is a
6
+ // statement about every other file. Asking them while a chunk of the zone is being
7
+ // read would answer "nobody" for a helper the rest of the repo calls — so they are
8
+ // asked once, here, on ONE project over the whole repository, and the answers are
9
+ // stored by position in the index (`fa-usage`). The checks then read a number
10
+ // instead of opening a project to ask a question the run has already answered.
11
+ //
12
+ // The project is the same one every other whole-repo question uses
13
+ // (`wholeRepoProject` → `openProject`): a second configuration would give the
14
+ // checker different answers than the reference path, and the reference path is
15
+ // what a run without an index answers with.
16
+ const notices_1 = require("./report/notices");
17
+ const pipeline_facts_1 = require("./pipeline-facts");
18
+ const usage_mode_1 = require("./usage-mode");
19
+ const fa_index_1 = require("./fa-index");
20
+ const tree_1 = require("./entities/ast/tree");
21
+ const file_1 = require("./entities/ast/file");
22
+ const release_file_1 = require("./release-file");
23
+ const usage_1 = require("./entities/ast/usage");
24
+ const usage_sweep_1 = require("./usage-sweep");
25
+ const scan_run_1 = require("./scan-run");
26
+ // One declaration's answer, or null when the checker had nothing to add: a name
27
+ // that is not published keeps the `null` the record already carries, and storing
28
+ // that would be a second copy of the same silence.
29
+ //
30
+ // The count comes from the one-pass sweep (`usage-sweep`), which answers for every
31
+ // name the same way the language service does; a shape the sweep cannot attribute
32
+ // (`null`) is asked exactly, as before. Both are asked through the same project,
33
+ // so an answer does not depend on which of the two produced it.
34
+ const answerOf = (candidate, sf, relOf, ask) => {
35
+ if (candidate.at === undefined || candidate.len === undefined)
36
+ return null;
37
+ const node = sf.getDescendantAtStartWithWidth(candidate.at, candidate.len);
38
+ if (node === null || node === undefined)
39
+ return null;
40
+ const exported = (0, tree_1.isExported)(node);
41
+ const swept = maySweep(node, exported, ask) ? sweptOf(node, sf, candidate, ask) : null;
42
+ if (swept !== null)
43
+ return swept;
44
+ const answer = (0, usage_1.usageFact)(node, sf, { exported, relOf });
45
+ if (answer.references === null && answer.implementations === null)
46
+ return null;
47
+ return { references: answer.references, implementations: answer.implementations };
48
+ };
49
+ // A name that is not published has no answer at all (`usageFact` says so), and a
50
+ // rule reads `null` as "unknown", not as "nobody": the sweep counts uses of every
51
+ // name, so it must not answer for one of those. An interface keeps the exact path
52
+ // because `implementations` is a question only it raises.
53
+ const maySweep = (node, exported, ask) => ask !== null && exported && node.getKindName() !== "InterfaceDeclaration";
54
+ // The sweep's answer for one declaration, as the record stores it. `implementations`
55
+ // is a separate question (`getImplementations`) that only an interface raises, and
56
+ // the caller sends an interface down the exact path.
57
+ const sweptOf = (node, sf, candidate, ask) => {
58
+ if (candidate.name === undefined || candidate.name === null)
59
+ return null;
60
+ // The declaration's own symbol: `getSymbolAtLocation` answers for a name token,
61
+ // not for the declaration that holds it.
62
+ const symbol = node.getSymbol()?.compilerSymbol;
63
+ if (symbol === undefined)
64
+ return null;
65
+ const rel = (0, file_1.repoRelative)(sf.getFilePath(), ask.root) ?? sf.getBaseName();
66
+ const references = ask.walk.references(symbol, rel, candidate.name);
67
+ if (references === null)
68
+ return null;
69
+ return { references, implementations: null };
70
+ };
71
+ // Every name of one file the checker can be asked about: the answers are keyed by
72
+ // the declaration's start, which is what the record keeps and what a later check
73
+ // looks a candidate up by.
74
+ const counted = (candidates, sf, repoRoot, ask = null) => {
75
+ const capture = (0, notices_1.beginNotices)();
76
+ const { answers, asked, answered } = answersOf(candidates, sf, repoRoot, ask);
77
+ return { answers, notices: capture.end(), asked, answered };
78
+ };
79
+ const answersOf = (candidates, sf, repoRoot, ask) => {
80
+ const relOf = (p) => (0, file_1.repoRelative)(p, repoRoot) ?? p;
81
+ const answers = {};
82
+ let asked = 0;
83
+ let answered = 0;
84
+ for (const candidate of candidates) {
85
+ const answer = answerOf(candidate, sf, relOf, ask);
86
+ asked += 1;
87
+ if (answer === null || candidate.at === undefined)
88
+ continue;
89
+ answers[String(candidate.at)] = answer;
90
+ answered += 1;
91
+ }
92
+ return { answers, asked, answered };
93
+ };
94
+ // The same answers for ONE file whose syntax the caller already holds: the plain
95
+ // path (`pipeline.checkFile`, and a file outside the scan scope) has the file open
96
+ // and asks the checker right there, exactly as before the pass existed.
97
+ const usageFor = (sf, candidates, repoRoot) => {
98
+ const capture = (0, notices_1.beginNotices)();
99
+ const { answers } = answersOf(candidates, sf, repoRoot, null);
100
+ return { answers, notices: capture.end() };
101
+ };
102
+ exports.usageFor = usageFor;
103
+ // The pass itself: one project, one open per file, one write per chunk. The
104
+ // file's syntax is given back as its answers are taken (`releaseFile`), so what
105
+ // the pass holds is the program, never the tree of every file it walked.
106
+ const runUsagePass = (args) => {
107
+ const { run, index, zone, absOf } = args;
108
+ const stats = { files: 0, asked: 0, answered: 0 };
109
+ if (zone.size === 0 || !(0, pipeline_facts_1.needsUsage)(run.arch))
110
+ return stats;
111
+ // `usage: index` answered at extraction (`usageFromIndex`), where no project was
112
+ // needed: opening one now would be the whole-repo parse this mode exists to skip.
113
+ if ((0, usage_mode_1.usageMode)() === "index")
114
+ return stats;
115
+ const repoRoot = run.arch.repoRoot ?? ".";
116
+ const project = (0, scan_run_1.wholeRepoProject)();
117
+ const program = project.getProgram().compilerObject;
118
+ const ask = { walk: (0, usage_sweep_1.sweep)(program, repoRoot), checker: program.getTypeChecker(), root: repoRoot };
119
+ for (const rel of zone) {
120
+ const abs = absOf.get(rel);
121
+ if (abs === undefined)
122
+ continue;
123
+ const record = (0, fa_index_1.recordAt)(index, abs);
124
+ const sf = project.getSourceFile(abs) ?? null;
125
+ if (record === null || sf === null)
126
+ continue;
127
+ const { answers, notices, asked, answered } = counted(record.candidates, sf, repoRoot, ask);
128
+ stats.files += 1;
129
+ stats.asked += asked;
130
+ stats.answered += answered;
131
+ (0, fa_index_1.keepUsage)(index, abs, { answers, notices });
132
+ (0, release_file_1.releaseFile)(sf);
133
+ }
134
+ return stats;
135
+ };
136
+ exports.runUsagePass = runUsagePass;
@@ -0,0 +1,2 @@
1
+ declare const prepareUsage: (raw: string | undefined, root: string, files: readonly string[]) => void;
2
+ export { prepareUsage };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareUsage = void 0;
4
+ // ONE PLACE THAT PICKS THE SOURCE OF `references` AND PREPARES IT. The mode is a
5
+ // run's (`--usage`, the rule's `usage`); the occurrence index has to be read from
6
+ // the repo's text before any answer is asked, and reading it twice for the same
7
+ // repo is wasted work — the CLI picks the mode and the scan asks again.
8
+ const usage_index_1 = require("./usage-index");
9
+ const usage_mode_1 = require("./usage-mode");
10
+ let primedFor = null;
11
+ let primedCount = 0;
12
+ const prepareUsage = (raw, root, files) => {
13
+ (0, usage_mode_1.setUsageMode)((0, usage_mode_1.usageModeOf)(raw));
14
+ if ((0, usage_mode_1.usageMode)() !== "index")
15
+ return;
16
+ if (primedFor === root && primedCount === files.length)
17
+ return;
18
+ (0, usage_index_1.primeUsageIndex)(root, files);
19
+ primedFor = root;
20
+ primedCount = files.length;
21
+ };
22
+ exports.prepareUsage = prepareUsage;
@@ -0,0 +1,10 @@
1
+ import { ts } from "ts-morph";
2
+ import type { ReferencesFact } from "@md-code/follow-architecture/entities/facts";
3
+ type Sweep = {
4
+ references: (symbol: ts.Symbol, ownRel: string, name: string) => ReferencesFact | null;
5
+ unsure: ReadonlySet<string>;
6
+ };
7
+ declare const nameSymbol: (checker: ts.TypeChecker, node: ts.Node) => ts.Symbol | undefined;
8
+ declare const sweep: (program: ts.Program, repoRoot: string) => Sweep;
9
+ export { sweep, nameSymbol };
10
+ export type { Sweep };
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.nameSymbol = exports.sweep = void 0;
27
+ // WHO USES A NAME, IN ONE WALK. `findReferencesAsNodes` asks the language service
28
+ // a question about the whole program once per candidate — 38 000 questions on this
29
+ // repo, ~1.5 ms each, and every answer re-derives what the checker already knows.
30
+ // The same facts are computable in a single pass: resolve every identifier to its
31
+ // symbol, group the occurrences by that symbol, and count.
32
+ //
33
+ // The answer keeps the shape and the meaning of `ReferencesFact`
34
+ // (`entities/facts.ts`): `total` = uses (the declaration's own name is not a use,
35
+ // a use in the declaring file is), `outside` = the ones in other files, `files` =
36
+ // the distinct files, `usedIn` = those where the name is USED and not merely
37
+ // republished by `export … from`.
38
+ const path = __importStar(require("node:path"));
39
+ const ts_morph_1 = require("ts-morph");
40
+ const emptyPart = () => ({ all: 0, used: 0, head: false });
41
+ const tallyOf = (into, symbol) => {
42
+ let tally = into.names.get(symbol);
43
+ if (tally === undefined) {
44
+ tally = new Map();
45
+ into.names.set(symbol, tally);
46
+ }
47
+ return tally;
48
+ };
49
+ const partOf = (name, file) => {
50
+ const found = name.get(file);
51
+ if (found !== undefined)
52
+ return found;
53
+ const part = emptyPart();
54
+ name.set(file, part);
55
+ return part;
56
+ };
57
+ // The file a node lives in, relative to the repo — the spelling a rule sees.
58
+ const relOf = (node, repoRoot) => {
59
+ const file = node.getSourceFile().fileName;
60
+ const rel = path.relative(repoRoot, file);
61
+ return rel.startsWith("..") ? null : rel.split(path.sep).join("/");
62
+ };
63
+ // Is the token part of an `export … from`? The same syntax rule the language
64
+ // service answer is filtered by: walk up to the statement that holds the name.
65
+ const inExportFrom = (node) => {
66
+ for (let current = node.parent; current !== undefined; current = current.parent) {
67
+ if (current.kind === ts_morph_1.ts.SyntaxKind.SourceFile)
68
+ return false;
69
+ if (current.kind === ts_morph_1.ts.SyntaxKind.ExportDeclaration)
70
+ return true;
71
+ }
72
+ return false;
73
+ };
74
+ // A declaration inside `declare global { … }` or `declare module "x" { … }` does
75
+ // not own its symbol: the checker merges those declarations into a symbol of
76
+ // another file's scope, and the walk sees a different one. The language service
77
+ // resolves the merge; the walk does not, so the name is answered exactly.
78
+ const inAmbientBlock = (node) => {
79
+ for (let current = node.parent; current !== undefined; current = current.parent) {
80
+ if (!ts_morph_1.ts.isModuleDeclaration(current))
81
+ continue;
82
+ const flags = ts_morph_1.ts.getCombinedModifierFlags(current);
83
+ if ((flags & ts_morph_1.ts.ModifierFlags.Ambient) !== 0)
84
+ return true;
85
+ if (current.name.kind === ts_morph_1.ts.SyntaxKind.StringLiteral)
86
+ return true;
87
+ }
88
+ return false;
89
+ };
90
+ // The token IS the name the TARGET symbol is declared under — the definition,
91
+ // which the language service does not count as a reference. Asked of the symbol
92
+ // rather than of the parent's shape: a declaration is whatever the checker says
93
+ // declares it. An alias (`import { x }`) declares the alias, not the target, and
94
+ // the language service counts it as a reference to the target — so it is a use.
95
+ const isDefinition = (node, target) => target.declarations !== undefined && target.declarations.some((declared) => declared === node.parent);
96
+ // An alias (`import { x as y }`, `export { x as y }`) names its target: the checker
97
+ // answers references against the TARGET's symbol, and so must the sweep, or the
98
+ // same name would be counted once per alias.
99
+ const targetOf = (checker, symbol) => {
100
+ if ((symbol.flags & ts_morph_1.ts.SymbolFlags.Alias) === 0)
101
+ return symbol;
102
+ try {
103
+ return checker.getAliasedSymbol(symbol);
104
+ }
105
+ catch {
106
+ return symbol;
107
+ }
108
+ };
109
+ // Do we count this token at all? Identifiers everywhere (declarations, uses,
110
+ // member names, shorthand properties, JSX names) and the string spelling of a
111
+ // module-specifier name (`import { "x" as y }`). Nothing else in a file names a binding.
112
+ const isNameToken = (node) => {
113
+ if (node.kind === ts_morph_1.ts.SyntaxKind.Identifier)
114
+ return true;
115
+ if (node.kind !== ts_morph_1.ts.SyntaxKind.StringLiteral)
116
+ return false;
117
+ const parent = node.parent;
118
+ return parent !== undefined && (ts_morph_1.ts.isImportSpecifier(parent) || ts_morph_1.ts.isExportSpecifier(parent));
119
+ };
120
+ // `namespaced` holds the files something imports as `import * as ns`: through a
121
+ // namespace any export may be reached, and the language service answers that
122
+ // shape its own way (it even counts the namespace token itself), so a name
123
+ // declared in such a file is not answered by the walk at all.
124
+ // A name re-exported under another name (`export { PairView as Diff }`) is counted
125
+ // by the language service once per spelling of the specifier, not once per token —
126
+ // three specifiers of `PairView` in one line give it six references where the walk
127
+ // sees three tokens. Not attributable here: such a symbol is asked exactly.
128
+ const isExportAlias = (node) => {
129
+ const parent = node.parent;
130
+ return parent !== undefined && ts_morph_1.ts.isExportSpecifier(parent) && parent.propertyName !== undefined;
131
+ };
132
+ // A class or interface member is answered across the type hierarchy: a use of the
133
+ // interface's `emit` is a reference to the class method that implements it, and
134
+ // the walk sees one symbol per declaration. Not attributable here — asked exactly.
135
+ const isMember = (symbol) => (symbol.flags & (ts_morph_1.ts.SymbolFlags.Property | ts_morph_1.ts.SymbolFlags.Method | ts_morph_1.ts.SymbolFlags.GetAccessor | ts_morph_1.ts.SymbolFlags.SetAccessor)) !== 0;
136
+ const isModuleSymbol = (symbol) => symbol.declarations !== undefined && symbol.declarations.some((each) => each.kind === ts_morph_1.ts.SyntaxKind.SourceFile);
137
+ const modulePath = (module, repoRoot) => {
138
+ for (const each of module.declarations ?? []) {
139
+ if (each.kind !== ts_morph_1.ts.SyntaxKind.SourceFile)
140
+ continue;
141
+ const rel = relOf(each, repoRoot);
142
+ if (rel !== null)
143
+ return rel;
144
+ }
145
+ return null;
146
+ };
147
+ const hasDeclarations = (symbol) => symbol.declarations !== undefined && symbol.declarations.length > 0;
148
+ // The symbol this token names: `{ Post }` declares a property, and the name is a
149
+ // USE of the variable that property reads — the shorthand answers for both.
150
+ const attribute = (node, checker) => {
151
+ const parent = node.parent;
152
+ const symbol = parent !== undefined && ts_morph_1.ts.isShorthandPropertyAssignment(parent)
153
+ ? checker.getShorthandAssignmentValueSymbol(parent)
154
+ : checker.getSymbolAtLocation(node);
155
+ return symbol === undefined ? undefined : targetOf(checker, symbol);
156
+ };
157
+ // One token → one count in its symbol's tally. A declaration in an ambient block,
158
+ // or a name whose symbol has no declaration at all (an augmentation's export), is
159
+ // not attributable by this walk: the name is answered exactly instead.
160
+ const countToken = (node, into, checker, repoRoot) => {
161
+ const target = attribute(node, checker);
162
+ if (target === undefined)
163
+ return;
164
+ const text = node.getText();
165
+ if (isExportAlias(node)) {
166
+ into.aliased.add(target);
167
+ return;
168
+ }
169
+ if (inAmbientBlock(node) || !hasDeclarations(target)) {
170
+ into.unsure.add(text);
171
+ return;
172
+ }
173
+ const rel = relOf(node, repoRoot);
174
+ if (rel === null)
175
+ return;
176
+ if (isModuleSymbol(target)) {
177
+ const file = modulePath(target, repoRoot);
178
+ if (file !== null)
179
+ into.namespaced.add(file);
180
+ return;
181
+ }
182
+ const part = partOf(tallyOf(into, target), rel);
183
+ if (part.all === 0)
184
+ part.head = isDefinition(node, target);
185
+ part.all += 1;
186
+ if (!inExportFrom(node))
187
+ part.used += 1;
188
+ };
189
+ // The whole program, one walk. Files outside the repo (the compiler's own libs, a
190
+ // dependency's `.d.ts`) are skipped: a use in them is not a use in this repo.
191
+ const collect = (program, repoRoot) => {
192
+ const checker = program.getTypeChecker();
193
+ const into = { names: new Map(), unsure: new Set(), namespaced: new Set(), aliased: new Set() };
194
+ for (const file of program.getSourceFiles()) {
195
+ if (relOf(file, repoRoot) === null)
196
+ continue;
197
+ const visit = (node) => {
198
+ if (isNameToken(node))
199
+ countToken(node, into, checker, repoRoot);
200
+ ts_morph_1.ts.forEachChild(node, visit);
201
+ };
202
+ ts_morph_1.ts.forEachChild(file, visit);
203
+ }
204
+ return into;
205
+ };
206
+ // The tally of one symbol as the fact a rule reads. The declaring file is the
207
+ // caller's business: the same name in two modules must answer for its own module.
208
+ // The declaration the caller asks about is not its own reference — the language
209
+ // service skips it, but only when nothing sortable comes before it in its file:
210
+ // a use above the declaration makes the declaration itself a counted reference.
211
+ const answerOf = (name, ownRel) => {
212
+ let total = name.get(ownRel)?.head === true ? -1 : 0;
213
+ const where = [];
214
+ const used = [];
215
+ for (const [file, part] of name) {
216
+ total += part.all;
217
+ if (file === ownRel)
218
+ continue;
219
+ if (part.all > 0)
220
+ where.push(file);
221
+ if (part.used > 0)
222
+ used.push(file);
223
+ }
224
+ return { total, outside: where.reduce((sum, file) => sum + (name.get(file)?.all ?? 0), 0), files: where, usedIn: used };
225
+ };
226
+ // The symbol a NAME TOKEN declares or uses, with aliases resolved: what the
227
+ // checker would answer references about.
228
+ const nameSymbol = (checker, node) => {
229
+ const symbol = checker.getSymbolAtLocation(node);
230
+ return symbol === undefined ? undefined : targetOf(checker, symbol);
231
+ };
232
+ exports.nameSymbol = nameSymbol;
233
+ const sweep = (program, repoRoot) => {
234
+ const { names, unsure, namespaced, aliased } = collect(program, repoRoot);
235
+ // A symbol with more than one declaration is answered per declaration by the
236
+ // language service, and the walk keeps one tally for all of them.
237
+ const merged = new Set();
238
+ for (const [symbol] of names)
239
+ if ((symbol.declarations?.length ?? 0) > 1)
240
+ merged.add(symbol);
241
+ return {
242
+ references: (symbol, ownRel, name) => {
243
+ if (unsure.has(name) || namespaced.has(ownRel) || merged.has(symbol) || isMember(symbol) || aliased.has(symbol))
244
+ return null;
245
+ const tally = names.get(symbol);
246
+ // A symbol the walk never met (a declaration outside the repository, a lib
247
+ // type) has no tally here, and "no uses" would be a claim, not an answer:
248
+ // the caller asks exactly instead.
249
+ return tally === undefined ? null : answerOf(tally, ownRel);
250
+ },
251
+ unsure,
252
+ };
253
+ };
254
+ exports.sweep = sweep;
@@ -0,0 +1,22 @@
1
+ import { type FieldValue } from "@md-code/follow-architecture/utils/field";
2
+ type Aliases = Record<string, string>;
3
+ type Alias = {
4
+ name: string;
5
+ rest: string;
6
+ };
7
+ declare const splitAlias: (aliases: Aliases | null | undefined, specifier: string) => Alias | null;
8
+ type Placement = {
9
+ dirs: string[];
10
+ files: string[];
11
+ };
12
+ type AliasScope = {
13
+ repoRoot?: string | null;
14
+ repoFiles?: readonly string[];
15
+ };
16
+ declare const locateAlias: (aliases: Aliases | null | undefined, name: string, rest: string, scope?: AliasScope) => Placement | null;
17
+ declare const placesOf: (aliases: Aliases | null | undefined, specifier: string, scope?: AliasScope) => string[] | null;
18
+ declare const primaryPlace: (aliases: Aliases | null | undefined, specifier: string, scope?: AliasScope) => string | null;
19
+ declare const expandPattern: (aliases: Aliases | null | undefined, pattern: string, scope?: AliasScope) => string;
20
+ declare const expandLocationFilters: (filter: FieldValue, aliases: Aliases | null | undefined) => FieldValue;
21
+ export { splitAlias, locateAlias, placesOf, primaryPlace, expandPattern, expandLocationFilters };
22
+ export type { Aliases, AliasScope, Placement };
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.expandLocationFilters = exports.expandPattern = exports.primaryPlace = exports.placesOf = exports.locateAlias = exports.splitAlias = void 0;
27
+ // ONE vocabulary for the architecture's aliases: what a specifier names, where it
28
+ // points, and how a config pattern that starts with `@` becomes a repo path. Its
29
+ // four consumers — the import resolver, node names/children, rule `where`/`ignore`
30
+ // and `location` filters — ask these functions and nothing else, so the alias map
31
+ // and the packages' `exports` are read in exactly one place.
32
+ //
33
+ // Without a scanned set (the config is built before the repo is scanned) only the
34
+ // plain reading is available: `@pkg` is the package folder, `@pkg/x` the folder
35
+ // under it. With `{ repoRoot, repoFiles }` a subpath also goes through the
36
+ // package's manifest and lands on the source its artifact was built from.
37
+ const notices_1 = require("@md-code/follow-architecture/report/notices");
38
+ const configError = __importStar(require("@md-code/follow-architecture/report/configErrors"));
39
+ const packages_1 = require("@md-code/follow-architecture/utils/packages");
40
+ const field_1 = require("@md-code/follow-architecture/utils/field");
41
+ const splitAlias = (aliases, specifier) => {
42
+ const s = String(specifier ?? "");
43
+ let name = null;
44
+ for (const candidate of Object.keys(aliases ?? {})) {
45
+ if (s !== candidate && !s.startsWith(`${candidate}/`))
46
+ continue;
47
+ if (name == null || candidate.length > name.length)
48
+ name = candidate;
49
+ }
50
+ if (name == null)
51
+ return null;
52
+ return { name, rest: s.slice(name.length).replace(/^\//, "") };
53
+ };
54
+ exports.splitAlias = splitAlias;
55
+ const isStars = (rest) => rest.length > 0 && /^\*(?:\/\*)*$/.test(rest);
56
+ // `@pkg/*` — every public source of the package, for a package that has no
57
+ // folders to walk. Only a scanned set can answer it.
58
+ const starredPlace = (folder, manifest, repoFiles) => {
59
+ const sources = (0, packages_1.publicSources)(folder, manifest, repoFiles);
60
+ return sources.length ? { dirs: [], files: sources } : null;
61
+ };
62
+ const artifactPlace = ({ name, folder, rest, manifest, repoFiles }) => {
63
+ const folderReading = { dirs: [`${folder}/${rest}`], files: [] };
64
+ const artifact = (0, packages_1.exportsPath)(manifest, rest) ?? (0, packages_1.typesVersionPath)(manifest, rest);
65
+ if (artifact == null || !repoFiles)
66
+ return folderReading;
67
+ const source = (0, packages_1.sourceOf)(folder, artifact, repoFiles);
68
+ if (source)
69
+ return { dirs: [], files: [source] };
70
+ (0, notices_1.notice)(`the alias ${name}/${rest} points at ${(0, packages_1.norm)(artifact)}, which no scanned file mirrors`, "the package's `exports` names that file but the package has no source for it — the import resolves to nothing the architecture can see");
71
+ return folderReading;
72
+ };
73
+ // Where an alias subpath points: the package's public entry when its manifest
74
+ // names one, otherwise the folder (or file) under the alias target.
75
+ const locateAlias = (aliases, name, rest, scope = {}) => {
76
+ const target = aliases?.[name];
77
+ if (target == null)
78
+ return null;
79
+ const folder = (0, packages_1.folderOf)(target);
80
+ if (!rest)
81
+ return { dirs: [folder], files: (0, packages_1.isFile)(target) ? [(0, packages_1.norm)(target)] : [] };
82
+ const manifest = (0, packages_1.manifestOf)(scope.repoRoot, folder);
83
+ const repoFiles = scope.repoFiles;
84
+ const starred = repoFiles && isStars(rest) ? starredPlace(folder, manifest, repoFiles) : null;
85
+ return starred ?? artifactPlace({ name, folder, rest, manifest, repoFiles });
86
+ };
87
+ exports.locateAlias = locateAlias;
88
+ // A CONFIG pattern (`@pkg/**`, `@pkg/chip`, `@pkg/themes`) → the repo place(s) it
89
+ // stands for, absolute. `null` when the specifier is not an alias at all.
90
+ const placesOf = (aliases, specifier, scope = {}) => {
91
+ const alias = splitAlias(aliases, specifier);
92
+ if (!alias)
93
+ return null;
94
+ const place = locateAlias(aliases, alias.name, alias.rest, scope);
95
+ const places = [...(place?.dirs ?? []), ...(place?.files ?? [])];
96
+ if (!places.length)
97
+ return [`${(0, packages_1.folderOf)(String(aliases?.[alias.name] ?? ""))}/${alias.rest}`];
98
+ return places;
99
+ };
100
+ exports.placesOf = placesOf;
101
+ // The ONE place a specifier names, when the caller needs a single string (a node's
102
+ // name, a child): the package folder when the alias has one, else the entry file.
103
+ const primaryPlace = (aliases, specifier, scope = {}) => {
104
+ const alias = splitAlias(aliases, specifier);
105
+ if (!alias)
106
+ return null;
107
+ const place = locateAlias(aliases, alias.name, alias.rest, scope);
108
+ if (place == null)
109
+ return null;
110
+ return place.dirs[0] ?? place.files[0] ?? null;
111
+ };
112
+ exports.primaryPlace = primaryPlace;
113
+ // A PREFIX pattern (`@md/utils/`) names a FOLDER and everything under it, so only
114
+ // folders answer it: the alias's entry file is not one.
115
+ const folderPlace = (aliases, specifier, scope) => {
116
+ const alias = splitAlias(aliases, specifier);
117
+ if (!alias) {
118
+ if (!specifier.startsWith("@"))
119
+ return specifier;
120
+ throw configError.unknownAlias({ specifier, known: Object.keys(aliases ?? {}) });
121
+ }
122
+ const place = locateAlias(aliases, alias.name, alias.rest, scope);
123
+ const folder = (0, packages_1.folderOf)(String(aliases?.[alias.name] ?? ""));
124
+ return place?.dirs[0] ?? (alias.rest ? `${folder}/${alias.rest}` : folder);
125
+ };
126
+ // A CONFIG pattern → the repo path it stands for: one path when the alias names
127
+ // one place, a brace alternation when it names several. A `@`-specifier that is
128
+ // NOT an alias is a config error — it would silently match nothing. A trailing
129
+ // `/` is a PREFIX (`startsWith: "@md/utils/"`), not a glob: it must survive, or
130
+ // the filter would widen from `utils/*` to `utils*` and swallow `utils-uniqueness`.
131
+ const expandPattern = (aliases, pattern, scope = {}) => {
132
+ const s = String(pattern ?? "");
133
+ if (s.endsWith("/"))
134
+ return `${folderPlace(aliases, s.slice(0, -1), scope)}/`;
135
+ const places = placesOf(aliases, s, scope);
136
+ if (!places) {
137
+ if (!s.startsWith("@"))
138
+ return s;
139
+ throw configError.unknownAlias({ specifier: s, known: Object.keys(aliases ?? {}) });
140
+ }
141
+ return places.length === 1 ? places[0] : `{${places.join(",")}}`;
142
+ };
143
+ exports.expandPattern = expandPattern;
144
+ // Only a `location` subtree names PLACES. A filter's other strings are values
145
+ // (`equals: "@angular/core"` names a package, not a file), so they stay as written.
146
+ const LOCATION_KEY = "location";
147
+ const rewritePatterns = (value, aliases, inside) => {
148
+ if (typeof value === "string")
149
+ return inside ? expandPattern(aliases, value) : value;
150
+ if ((0, field_1.isList)(value))
151
+ return value.map((item) => rewritePatterns(item, aliases, inside));
152
+ if (!(0, field_1.isObj)(value))
153
+ return value;
154
+ const out = {};
155
+ for (const [key, item] of Object.entries(value)) {
156
+ out[key] = rewritePatterns(item, aliases, inside || key === LOCATION_KEY);
157
+ }
158
+ return out;
159
+ };
160
+ // A filter with every `location` pattern expanded. A filter is plain data, so the
161
+ // rewrite is a copy — the raw config stays as written.
162
+ const expandLocationFilters = (filter, aliases) => rewritePatterns(filter, aliases, false);
163
+ exports.expandLocationFilters = expandLocationFilters;
@@ -1,5 +1,5 @@
1
- import type { QueryFilter, QueryScope } from "../entities/architecture";
2
- import type { FieldValue } from "../utils/field";
1
+ import type { QueryFilter, QueryScope } from "@md-code/follow-architecture/entities/architecture";
2
+ import type { FieldValue } from "@md-code/follow-architecture/utils/field";
3
3
  type Definition = {
4
4
  name: string;
5
5
  infer: QueryFilter;
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.firstMatch = exports.definitionsOf = void 0;
4
4
  // A CLASSIFICATION is one mechanism: definitions are tried in DECLARED ORDER
5
5
  // against a subject, and the FIRST whose `infer` filter matches names it. A
6
- // code role classifies a piece of code (`code-roles/connector`), a file's own
7
- // facts (`code-roles/classify`), and the roles a folder's files hold
6
+ // code entity classifies a piece of code (`code-entities/connector`), a file's own
7
+ // facts (`code-entities/classify`), and the entities a folder's files hold
8
8
  // (`nodes/similar`) — all three ask the same question of the same filter
9
9
  // engine, so the walk lives here once. What the definitions ARE and what a
10
- // match MEANS is the caller's own; nothing here knows roles.
11
- const queries_1 = require("../entities/queries");
10
+ // match MEANS is the caller's own; nothing here knows entities.
11
+ const queries_1 = require("@md-code/follow-architecture/entities/queries");
12
12
  // The definitions a record of `{ infer }` specs declares, in the record's own
13
13
  // (YAML) order. A spec without an infer filter can never match.
14
14
  const definitionsOf = (defs) => Object.entries(defs ?? {}).map(([name, def]) => ({ name, infer: def?.infer ?? null }));
@@ -4,9 +4,11 @@ exports.distinctFlat = void 0;
4
4
  // A DISTINCT COLLECT is one mechanism: every item of a list contributes names
5
5
  // (zero, one, or many), and the answer is the names in first-seen order, each
6
6
  // once. A component's props are the distinct names its parameters contribute
7
- // (`frameworks/react`); an entity's shape is the distinct roles its children
7
+ // (`frameworks/react`); an entity's shape is the distinct entities its children
8
8
  // declare (`nodes/similar`). The walk is the same — flatMap the contributions,
9
9
  // keep the first of each — so it lives here once. What a name IS and where it
10
10
  // comes from is the caller's own.
11
- const distinctFlat = (items, namesOf) => [...new Set(items.flatMap(namesOf))];
11
+ const distinctFlat = (items, namesOf) => [
12
+ ...new Set(items.flatMap(namesOf)),
13
+ ];
12
14
  exports.distinctFlat = distinctFlat;