@md-code/follow-architecture 0.3.0 → 0.3.2

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 (387) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +1310 -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 +132 -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} +98 -61
  14. package/dist/code-entities/project.d.ts +21 -0
  15. package/dist/code-entities/project.js +259 -0
  16. package/dist/code-entities/walk.d.ts +31 -0
  17. package/dist/code-entities/walk.js +105 -0
  18. package/dist/config-options.d.ts +23 -0
  19. package/dist/config-options.js +18 -1
  20. package/dist/config-project.js +27 -9
  21. package/dist/config-report.d.ts +1 -1
  22. package/dist/config-report.js +37 -10
  23. package/dist/config-rule.d.ts +25 -0
  24. package/dist/config-rule.js +106 -13
  25. package/dist/config-state.d.ts +14 -3
  26. package/dist/config-state.js +197 -24
  27. package/dist/config.d.ts +25 -0
  28. package/dist/css/index.d.ts +11 -7
  29. package/dist/css/index.js +141 -30
  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 +18 -8
  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 +21 -9
  37. package/dist/css/syntax/scss/index.d.ts +2 -2
  38. package/dist/css/syntax/scss/index.js +18 -8
  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 +34 -14
  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 +32 -15
  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 +21 -11
  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 +148 -37
  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 +10 -8
  133. package/dist/entities/location/where.js +89 -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 +89 -19
  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 +112 -51
  154. package/dist/entities/tree/entries.d.ts +4 -4
  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 +26 -12
  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 +242 -0
  164. package/dist/fa-store.d.ts +22 -0
  165. package/dist/fa-store.js +232 -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 +297 -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 +25 -11
  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 +62 -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 +219 -0
  190. package/dist/main.d.ts +5 -2
  191. package/dist/main.js +223 -41
  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 +64 -11
  196. package/dist/nodes/finally/emit.d.ts +4 -4
  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 +78 -56
  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 +64 -62
  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.d.ts +1 -1
  226. package/dist/pipeline.js +19 -64
  227. package/dist/release-file.d.ts +3 -0
  228. package/dist/release-file.js +13 -0
  229. package/dist/report/asks.d.ts +3 -3
  230. package/dist/report/asks.js +16 -6
  231. package/dist/report/configErrors.d.ts +55 -27
  232. package/dist/report/configErrors.js +81 -35
  233. package/dist/report/errorTypes/codes/structure.d.ts +1 -1
  234. package/dist/report/errorTypes/codes/structure.js +9 -9
  235. package/dist/report/errorTypes/decision-maker.d.ts +5 -5
  236. package/dist/report/errorTypes/decision-maker.js +21 -11
  237. package/dist/report/errorTypes/destinations.d.ts +5 -5
  238. package/dist/report/errorTypes/destinations.js +52 -34
  239. package/dist/report/errorTypes/finding-type.d.ts +3 -3
  240. package/dist/report/errorTypes/index.d.ts +1 -1
  241. package/dist/report/errorTypes/index.js +17 -7
  242. package/dist/report/errorTypes/types/fileContents.d.ts +4 -4
  243. package/dist/report/errorTypes/types/fileContents.js +11 -5
  244. package/dist/report/errorTypes/types/unknownEntity.d.ts +9 -0
  245. package/dist/report/errorTypes/types/{unknownRole.js → unknownEntity.js} +12 -7
  246. package/dist/report/errorTypes/types/wrongAction.d.ts +5 -5
  247. package/dist/report/errorTypes/types/wrongAction.js +18 -13
  248. package/dist/report/errorTypes/types/wrongPlacement.d.ts +4 -4
  249. package/dist/report/errorTypes/types/wrongPlacement.js +19 -9
  250. package/dist/report/errorTypes/vocabulary/ids.d.ts +2 -2
  251. package/dist/report/errorTypes/vocabulary/ids.js +3 -3
  252. package/dist/report/errorTypes/vocabulary/phrases.d.ts +2 -2
  253. package/dist/report/errorTypes/vocabulary/phrases.js +39 -26
  254. package/dist/report/errorTypes/vocabulary/places.d.ts +3 -3
  255. package/dist/report/errorTypes/vocabulary/places.js +13 -13
  256. package/dist/report/finding-from.d.ts +3 -3
  257. package/dist/report/finding-from.js +14 -9
  258. package/dist/report/notices.d.ts +6 -1
  259. package/dist/report/notices.js +46 -20
  260. package/dist/report/observed.d.ts +19 -0
  261. package/dist/report/observed.js +87 -0
  262. package/dist/report/render-report.d.ts +1 -1
  263. package/dist/report/render-report.js +33 -30
  264. package/dist/report/user-report/build/bundle.js +26 -7
  265. package/dist/report/user-report/build/bundle.prebuilt.js +799 -297
  266. package/dist/report/user-report/data/collect.d.ts +2 -2
  267. package/dist/report/user-report/data/collect.js +32 -19
  268. package/dist/report/user-report/data/entities.d.ts +7 -0
  269. package/dist/report/user-report/data/{roles.js → entities.js} +27 -22
  270. package/dist/report/user-report/data/{role-examples.d.ts → entity-examples.d.ts} +3 -3
  271. package/dist/report/user-report/data/entity-examples.js +136 -0
  272. package/dist/report/user-report/data/{role-filters.d.ts → entity-filters.d.ts} +2 -2
  273. package/dist/report/user-report/data/{role-filters.js → entity-filters.js} +7 -7
  274. package/dist/report/user-report/data/entity-marks.d.ts +5 -0
  275. package/dist/report/user-report/data/{role-marks.js → entity-marks.js} +11 -11
  276. package/dist/report/user-report/data/file-tree.d.ts +3 -3
  277. package/dist/report/user-report/data/file-tree.js +13 -5
  278. package/dist/report/user-report/data/finding-boundary.d.ts +4 -4
  279. package/dist/report/user-report/data/finding-boundary.js +2 -2
  280. package/dist/report/user-report/data/finding-plan.d.ts +5 -5
  281. package/dist/report/user-report/data/finding-plan.js +10 -10
  282. package/dist/report/user-report/data/finding-title.d.ts +2 -2
  283. package/dist/report/user-report/data/finding-title.js +8 -8
  284. package/dist/report/user-report/data/findings.d.ts +4 -4
  285. package/dist/report/user-report/data/findings.js +30 -20
  286. package/dist/report/user-report/data/graph-edges.d.ts +4 -4
  287. package/dist/report/user-report/data/graph-edges.js +19 -19
  288. package/dist/report/user-report/data/graph-entities.d.ts +6 -0
  289. package/dist/report/user-report/data/graph-entities.js +158 -0
  290. package/dist/report/user-report/data/graph-helpers.d.ts +5 -5
  291. package/dist/report/user-report/data/graph-helpers.js +15 -15
  292. package/dist/report/user-report/data/graph.d.ts +5 -4
  293. package/dist/report/user-report/data/graph.js +28 -21
  294. package/dist/report/user-report/data/nodes.d.ts +2 -2
  295. package/dist/report/user-report/data/nodes.js +33 -23
  296. package/dist/report/user-report/data/rules.d.ts +7 -0
  297. package/dist/report/user-report/data/{invariants.js → rules.js} +13 -13
  298. package/dist/report/user-report/data/scan.d.ts +1 -1
  299. package/dist/report/user-report/data/scan.js +19 -9
  300. package/dist/report/user-report/html/shell.d.ts +1 -1
  301. package/dist/report/user-report/html/shell.js +1 -1
  302. package/dist/report/user-report/index.d.ts +1 -1
  303. package/dist/report/user-report/index.js +17 -7
  304. package/dist/report/user-report/shared/describe.d.ts +1 -1
  305. package/dist/report/user-report/shared/describe.js +6 -6
  306. package/dist/rules/index.d.ts +7 -0
  307. package/dist/{invariants → rules}/index.js +85 -57
  308. package/dist/{invariants → rules}/list-vars.d.ts +2 -2
  309. package/dist/{invariants → rules}/list-vars.js +9 -3
  310. package/dist/{invariants → rules}/name.js +2 -2
  311. package/dist/rules/normalize.d.ts +5 -0
  312. package/dist/rules/normalize.js +108 -0
  313. package/dist/{invariants → rules}/vars.d.ts +9 -7
  314. package/dist/{invariants → rules}/vars.js +5 -5
  315. package/dist/scan-run.d.ts +20 -0
  316. package/dist/scan-run.js +130 -0
  317. package/dist/scripts/audit-report.js +19 -9
  318. package/dist/usage-index.d.ts +4 -0
  319. package/dist/usage-index.js +282 -0
  320. package/dist/usage-mode.d.ts +7 -0
  321. package/dist/usage-mode.js +16 -0
  322. package/dist/usage-pass.d.ts +19 -0
  323. package/dist/usage-pass.js +136 -0
  324. package/dist/usage-prepare.d.ts +2 -0
  325. package/dist/usage-prepare.js +22 -0
  326. package/dist/usage-sweep.d.ts +10 -0
  327. package/dist/usage-sweep.js +264 -0
  328. package/dist/utils/aliases.d.ts +22 -0
  329. package/dist/utils/aliases.js +173 -0
  330. package/dist/utils/classify.d.ts +2 -2
  331. package/dist/utils/classify.js +4 -4
  332. package/dist/utils/configs.js +17 -7
  333. package/dist/utils/distinct.js +4 -2
  334. package/dist/utils/files.js +41 -37
  335. package/dist/utils/fixpoint.js +2 -2
  336. package/dist/utils/host.d.ts +1 -1
  337. package/dist/utils/host.js +4 -1
  338. package/dist/utils/imports.js +83 -19
  339. package/dist/utils/keyed.js +2 -2
  340. package/dist/utils/map-record.js +2 -2
  341. package/dist/utils/packages.d.ts +15 -0
  342. package/dist/utils/packages.js +207 -0
  343. package/dist/utils/path-label.js +3 -1
  344. package/dist/utils/pattern.d.ts +5 -4
  345. package/dist/utils/pattern.js +55 -15
  346. package/dist/utils/permission.d.ts +3 -3
  347. package/dist/utils/permission.js +4 -2
  348. package/dist/utils/plural.js +2 -2
  349. package/dist/utils/qualified.js +4 -4
  350. package/dist/utils/rank.js +2 -2
  351. package/dist/utils/record.js +1 -1
  352. package/dist/utils/search.js +7 -2
  353. package/dist/utils/speak.js +1 -1
  354. package/dist/utils/split.js +14 -1
  355. package/dist/utils/template.d.ts +1 -1
  356. package/dist/utils/template.js +1 -1
  357. package/dist/utils/tokenize.js +6 -1
  358. package/dist/utils/typed-field.js +2 -2
  359. package/dist/utils/verdicts.js +1 -1
  360. package/entities/operators.ts +1 -1
  361. package/package.json +101 -90
  362. package/report/errorTypes/vocabulary/ids.ts +7 -2
  363. package/report/errorTypes/vocabulary/phrases.ts +47 -27
  364. package/report/errorTypes/vocabulary/places.ts +21 -16
  365. package/report/user-report/shared/describe.ts +7 -7
  366. package/dist/code-roles/classify.d.ts +0 -11
  367. package/dist/code-roles/classify.js +0 -43
  368. package/dist/code-roles/connector.d.ts +0 -5
  369. package/dist/code-roles/connector.js +0 -114
  370. package/dist/code-roles/project.d.ts +0 -12
  371. package/dist/code-roles/project.js +0 -122
  372. package/dist/code-roles/roles.d.ts +0 -8
  373. package/dist/invariants/index.d.ts +0 -6
  374. package/dist/invariants/normalize.d.ts +0 -4
  375. package/dist/invariants/normalize.js +0 -95
  376. package/dist/nodes/child-roles.d.ts +0 -3
  377. package/dist/nodes/child-roles.js +0 -12
  378. package/dist/nodes/finally/roles.d.ts +0 -13
  379. package/dist/nodes/finally/roles.js +0 -41
  380. package/dist/report/errorTypes/types/unknownRole.d.ts +0 -9
  381. package/dist/report/user-report/data/graph-roles.d.ts +0 -5
  382. package/dist/report/user-report/data/graph-roles.js +0 -71
  383. package/dist/report/user-report/data/invariants.d.ts +0 -7
  384. package/dist/report/user-report/data/role-examples.js +0 -94
  385. package/dist/report/user-report/data/role-marks.d.ts +0 -5
  386. package/dist/report/user-report/data/roles.d.ts +0 -7
  387. /package/dist/{invariants → rules}/name.d.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.commentsOf = void 0;
3
+ exports.releaseComments = exports.commentsOf = void 0;
4
4
  const tree_1 = require("./tree");
5
5
  const kind_1 = require("./kind");
6
6
  const functions_1 = require("./functions");
@@ -17,16 +17,22 @@ const kindOf = (range, text) => {
17
17
  // of the token that follows it, so the walk asks every node for the comments
18
18
  // around it and keeps them by position — the file itself carries the ones above
19
19
  // the first token.
20
- const rangesOf = (sf) => {
20
+ const rangesOf = (sf, descendants) => {
21
21
  const text = sf.getFullText();
22
22
  const byPos = new Map();
23
- for (const node of [sf, ...sf.getDescendants()]) {
23
+ for (const node of [sf, ...descendants]) {
24
24
  const ranges = [...(node.getLeadingCommentRanges?.() ?? []), ...(node.getTrailingCommentRanges?.() ?? [])];
25
25
  for (const range of ranges)
26
26
  if (!byPos.has(range.getPos()))
27
27
  byPos.set(range.getPos(), range);
28
28
  }
29
- return [...byPos.values()].sort((a, b) => a.getPos() - b.getPos()).map((range) => ({ pos: range.getPos(), end: range.getEnd(), kind: kindOf(range, text.slice(range.getPos(), range.getEnd())) }));
29
+ return [...byPos.values()]
30
+ .sort((a, b) => a.getPos() - b.getPos())
31
+ .map((range) => ({
32
+ pos: range.getPos(),
33
+ end: range.getEnd(),
34
+ kind: kindOf(range, text.slice(range.getPos(), range.getEnd())),
35
+ }));
30
36
  };
31
37
  // A comment is TRIVIA — text between tokens — but the parser still builds a node
32
38
  // for a doc block, and that node has a subtree of its own: `JSDocParameterTag`
@@ -34,9 +40,9 @@ const rangesOf = (sf) => {
34
40
  // inside of a doc block is described by the SAME machinery as any other node —
35
41
  // no `tags` field, no list of known tag names, nothing to keep in sync with the
36
42
  // language. Any comment that has no node of its own simply has no subtree.
37
- const nodesByPos = (sf) => {
43
+ const nodesByPos = (descendants) => {
38
44
  const byPos = new Map();
39
- for (const node of sf.getDescendants())
45
+ for (const node of descendants)
40
46
  if (!byPos.has(node.getStart()))
41
47
  byPos.set(node.getStart(), node);
42
48
  return byPos;
@@ -51,12 +57,11 @@ const linesOfRange = (sf, pos, end) => {
51
57
  };
52
58
  // The deepest function or class a comment sits inside. A doc block above a
53
59
  // declaration is NOT inside it (it starts before the declaration does), which is
54
- // the distinction a rule needs to say "no comments outside the action".
55
- const pieceAt = (sf, pos) => {
60
+ // the distinction a rule needs to say "no comments outside the action". The
61
+ // candidates are the file's function/class nodes, gathered once.
62
+ const pieceAt = (pos, pieces) => {
56
63
  let best = null;
57
- for (const node of sf.getDescendants()) {
58
- if (!(0, tree_1.isFunctionNode)(node) && !(0, tree_1.isClassNode)(node))
59
- continue;
64
+ for (const node of pieces) {
60
65
  if (node.getStart() > pos || node.getEnd() < pos)
61
66
  continue;
62
67
  if (!best || node.getStart() > best.getStart())
@@ -67,18 +72,18 @@ const pieceAt = (sf, pos) => {
67
72
  // The comment's `kind`: its own syntactic form, and — when the parser has a
68
73
  // node for it — the node's whole neighbourhood and subtree, read through `is`
69
74
  // like any other code.
70
- const commentKind = (node, kind) => (node ? { ...(0, tree_1.kindFact)(node), ...(0, kind_1.spelled)(kind), own: { is: kind } } : (0, kind_1.spelled)(kind));
75
+ const commentKind = (node, kind) => node ? { ...(0, tree_1.kindFact)(node), ...(0, kind_1.spelled)(kind), own: { is: kind } } : (0, kind_1.spelled)(kind);
71
76
  // The candidates. Each one carries the same facts every other candidate carries
72
77
  // (where it is, the lines it spans, what kind it is) plus what only a comment
73
78
  // has: its text, markers included — the markers are what tells a doc block from
74
79
  // a plain block, and stripping them would throw that away.
75
- const commentCandidate = (sf, rel, nodes, span) => {
76
- const piece = pieceAt(sf, span.pos);
80
+ const commentCandidate = (sf, rel, view, span) => {
81
+ const piece = pieceAt(span.pos, view.pieces);
77
82
  return {
78
83
  name: null,
79
84
  location: { path: rel ?? null, piece: piece ? ((0, functions_1.nameOf)(piece) ?? null) : null, nested: Boolean(piece) },
80
85
  lines: linesOfRange(sf, span.pos, span.end),
81
- kind: commentKind(nodes.get(span.pos), span.kind),
86
+ kind: commentKind(view.nodes.get(span.pos), span.kind),
82
87
  text: sf.getFullText().slice(span.pos, span.end),
83
88
  // A comment has no actions: it runs nothing, writes nothing, yields
84
89
  // nothing. Stated, because every candidate answers every question.
@@ -93,8 +98,33 @@ const commentCandidate = (sf, rel, nodes, span) => {
93
98
  implementations: null,
94
99
  };
95
100
  };
101
+ // A file's comments are the same every time it is walked in a run, and candidate
102
+ // collection walks the same file in several places (the linted file's pipeline and
103
+ // the project-wide index). So the comments are built once per SourceFile and handed
104
+ // out as shallow copies — the facets attach fields to the candidate they were
105
+ // handed. Guarded by the file's current text: overwriting a SourceFile in place
106
+ // yields a new comment set.
107
+ const COMMENTS = new WeakMap();
96
108
  const commentsOf = (sf, rel) => {
97
- const nodes = nodesByPos(sf);
98
- return rangesOf(sf).map((span) => commentCandidate(sf, rel, nodes, span));
109
+ const text = sf.getFullText();
110
+ const cached = COMMENTS.get(sf);
111
+ if (cached && cached.text === text)
112
+ return cached.list.map((c) => ({ ...c }));
113
+ const descendants = (0, tree_1.fileDescendants)(sf);
114
+ const view = {
115
+ nodes: nodesByPos(descendants),
116
+ pieces: descendants.filter((n) => (0, tree_1.isFunctionNode)(n) || (0, tree_1.isClassNode)(n)),
117
+ };
118
+ const list = rangesOf(sf, descendants).map((span) => commentCandidate(sf, rel, view, span));
119
+ COMMENTS.set(sf, { text, list });
120
+ return list.map((c) => ({ ...c }));
99
121
  };
100
122
  exports.commentsOf = commentsOf;
123
+ // Drop this file's cached comment candidates. A run that is done with a file's
124
+ // syntax releases them with the rest of the file (see `entities/ast/tree.ts`):
125
+ // the list is plain data, but it is derived from the file and must not outlive
126
+ // the walk that needed it.
127
+ const releaseComments = (sf) => {
128
+ COMMENTS.delete(sf);
129
+ };
130
+ exports.releaseComments = releaseComments;
@@ -1,4 +1,4 @@
1
1
  import type { LooseNode } from "./loose";
2
- import type { Candidate, AnyMember } from "../facts";
2
+ import type { Candidate, AnyMember } from "@md-code/follow-architecture/entities/facts";
3
3
  declare const declarationFact: (node: LooseNode, rel: string, members: AnyMember[]) => Candidate;
4
4
  export { declarationFact };
@@ -1,5 +1,5 @@
1
- import type { Candidate } from "../facts";
2
- import type { ScanContext } from "../context";
1
+ import type { Candidate } from "@md-code/follow-architecture/entities/facts";
2
+ import type { ScanContext } from "@md-code/follow-architecture/entities/context";
3
3
  type Chain = {
4
4
  depth: number;
5
5
  chain: string[];
@@ -15,20 +15,30 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.attachCallDepth = void 0;
27
37
  // How many calls deep a piece of code goes before somebody else does the work.
28
38
  //
29
39
  // A piece that calls an imported function which calls another which calls
30
40
  // another is not readable at the call site: nobody can see where the state is
31
- // finally changed, and no role rule can point at the place that changed it.
41
+ // finally changed, and no entity rule can point at the place that changed it.
32
42
  // The chain is what this fact measures — `toggleLineAction → applyDecorations →
33
43
  // applyActiveEditorDecorations → …` is a depth of 5, and a rule may refuse it.
34
44
  //
@@ -40,10 +50,15 @@ exports.attachCallDepth = void 0;
40
50
  const fs = __importStar(require("node:fs"));
41
51
  const path = __importStar(require("node:path"));
42
52
  const index_1 = require("./index");
43
- const frameworks_1 = require("../../frameworks");
44
- const notices_1 = require("../../report/notices");
45
- const try_read_1 = require("../../utils/try-read");
46
- const reason_1 = require("../../utils/reason");
53
+ const index_2 = require("@md-code/follow-architecture/frameworks/index");
54
+ const notices_1 = require("@md-code/follow-architecture/report/notices");
55
+ const try_read_1 = require("@md-code/follow-architecture/utils/try-read");
56
+ const reason_1 = require("@md-code/follow-architecture/utils/reason");
57
+ // How many files' candidate lists the cache keeps. A chain is answered from the
58
+ // file's TEXT and never changes inside a run, so a file that falls out of the
59
+ // cache is read again — the bound trades a re-read for the memory a whole repo's
60
+ // candidates would take, and the answers do not depend on it.
61
+ const MAX_CACHED_FILES = 64;
47
62
  // A link's target: an imported name names its module (followed only when the
48
63
  // module is a repo file); a local name is walked in this file. A link back to
49
64
  // the piece itself is not a step.
@@ -114,14 +129,16 @@ const candidatesIn = (rel, ctx) => {
114
129
  const text = fs.readFileSync(abs, "utf8");
115
130
  const sf = (0, index_1.loadSourceFile)(ctx.project, abs, text);
116
131
  const importMap = (0, index_1.importNameModules)(sf, ctx.repoRoot, ctx.aliases ?? {}, ctx.repoFiles);
117
- const candidates = (0, index_1.collectCandidates)(sf, importMap, rel, ctx.repoRoot);
132
+ const candidates = (0, index_1.collectCandidates)(sf, importMap, rel, ctx.repoRoot, { usage: false });
118
133
  // The facets read the same file the walk does, so a rendered component is a
119
- // link here exactly as it is in the invariants. The import map is handed over
134
+ // link here exactly as it is in the rules. The import map is handed over
120
135
  // so a tag imported from another module names that module.
121
- (0, frameworks_1.enrich)(candidates, { rel, sf, text, repoRoot: ctx.repoRoot, importMap });
136
+ (0, index_2.enrich)(candidates, { rel, sf, text, repoRoot: ctx.repoRoot, importMap });
122
137
  return candidates;
123
138
  };
124
139
  const out = (0, try_read_1.readOrFallback)(rel, read, [], (e) => (0, notices_1.notice)(`the import chain of ${rel} could not be read`, (0, reason_1.reasonOf)(e)));
140
+ if (ctx.cache && ctx.cache.files.size >= MAX_CACHED_FILES)
141
+ ctx.cache.files.clear();
125
142
  ctx.cache?.files.set(rel, out);
126
143
  return out;
127
144
  };
@@ -1,6 +1,6 @@
1
1
  import type { Node } from "ts-morph";
2
2
  import type { LooseNode } from "./loose";
3
- import type { Candidate } from "../facts";
3
+ import type { Candidate } from "@md-code/follow-architecture/entities/facts";
4
4
  declare const isEnumNode: (n: Node) => boolean;
5
5
  declare const enumFact: (node: LooseNode, rel: string) => Candidate;
6
6
  export { enumFact, isEnumNode };
@@ -0,0 +1,15 @@
1
+ import { type Project } from "ts-morph";
2
+ import { type AliasMap } from "./project";
3
+ declare const DEFAULT_BARREL_DEPTH = 8;
4
+ type ChainCtx = {
5
+ rel: string;
6
+ repoRoot: string;
7
+ repoFiles?: string[];
8
+ aliases?: AliasMap;
9
+ barrelDepth?: number;
10
+ project?: Project;
11
+ };
12
+ declare const declaringFiles: (ctx: ChainCtx, module: string, names: readonly string[]) => (string | null)[];
13
+ declare const declaringExportFiles: (ctx: ChainCtx, from: string, names: readonly string[]) => (string | null)[];
14
+ export { declaringFiles, declaringExportFiles, DEFAULT_BARREL_DEPTH };
15
+ export type { ChainCtx };
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DEFAULT_BARREL_DEPTH = exports.declaringExportFiles = exports.declaringFiles = void 0;
7
+ // Follows a NAME through a barrel to the file that DECLARES it.
8
+ //
9
+ // `import { codeEditor } from "@md/styles"` resolves to `packages/styles/index.ts`
10
+ // — the barrel, which only passes the name on. The law is about the code that
11
+ // declares a theme, so the relation has to be judged where the name is BORN:
12
+ // `export { default as codeEditor } from "./editor"` → `themes/index` →
13
+ // `themes/editor.ts`. One step per re-export, `DEFAULT_BARREL_DEPTH` steps at most, and a
14
+ // name already visited is a cycle: both stop the walk and leave the relation at
15
+ // the module file, exactly as before this walk existed.
16
+ //
17
+ // The walk reads a module's export facts, not its syntax tree, so a barrel that
18
+ // the pipeline has already released is re-read on demand and kept only as facts.
19
+ const node_fs_1 = __importDefault(require("node:fs"));
20
+ const node_path_1 = __importDefault(require("node:path"));
21
+ const ts_morph_1 = require("ts-morph");
22
+ const file_exports_1 = require("./file-exports");
23
+ const resolve_1 = require("./resolve");
24
+ const project_1 = require("./project");
25
+ // The default depth of a barrel chain: a name that travels through more re-exports
26
+ // than this is not followed. Eight re-exports is deeper than any barrel in the repo;
27
+ // a tenth is a mistake, not a chain. The rule option `barrelDepth` and the CLI's
28
+ // `--barrel-depth` move it; the architecture never states it.
29
+ const DEFAULT_BARREL_DEPTH = 8;
30
+ exports.DEFAULT_BARREL_DEPTH = DEFAULT_BARREL_DEPTH;
31
+ const CACHE = new WeakMap();
32
+ const cacheOf = (project) => {
33
+ const cached = CACHE.get(project) ?? new Map();
34
+ CACHE.set(project, cached);
35
+ return cached;
36
+ };
37
+ // What a declaration statement publishes, when it is exported at all: `export
38
+ // const a` names every binding, `export function f` one, and `export default f`
39
+ // publishes `default` — the name a chain looks for.
40
+ const declaredOf = (st) => {
41
+ if (ts_morph_1.Node.isVariableStatement(st)) {
42
+ return st.isExported()
43
+ ? { isDefault: st.isDefaultExport(), names: st.getDeclarations().map((d) => d.getName()) }
44
+ : null;
45
+ }
46
+ if (ts_morph_1.Node.isFunctionDeclaration(st) ||
47
+ ts_morph_1.Node.isClassDeclaration(st) ||
48
+ ts_morph_1.Node.isInterfaceDeclaration(st) ||
49
+ ts_morph_1.Node.isTypeAliasDeclaration(st) ||
50
+ ts_morph_1.Node.isEnumDeclaration(st)) {
51
+ if (!st.isExported())
52
+ return null;
53
+ const name = st.getName();
54
+ return { isDefault: st.isDefaultExport(), names: name ? [name] : [] };
55
+ }
56
+ return null;
57
+ };
58
+ const localExported = (sf) => {
59
+ const exported = new Set();
60
+ for (const st of sf.getStatements()) {
61
+ const declared = declaredOf(st);
62
+ if (!declared)
63
+ continue;
64
+ if (declared.isDefault)
65
+ exported.add("default");
66
+ else
67
+ for (const name of declared.names)
68
+ exported.add(name);
69
+ }
70
+ return exported;
71
+ };
72
+ // The parsed file, loaded only when the walk actually needs it.
73
+ const sourceAt = (ctx, rel) => {
74
+ const project = ctx.project;
75
+ if (!project)
76
+ return null;
77
+ const abs = node_path_1.default.resolve(ctx.repoRoot, rel);
78
+ const known = project.getSourceFile(abs);
79
+ if (known)
80
+ return known;
81
+ try {
82
+ return (0, project_1.loadSourceFile)(project, abs, node_fs_1.default.readFileSync(abs, "utf8"));
83
+ }
84
+ catch {
85
+ return null;
86
+ }
87
+ };
88
+ const factsOf = (ctx, rel) => {
89
+ const project = ctx.project;
90
+ if (!project)
91
+ return null;
92
+ const sf = sourceAt(ctx, rel);
93
+ if (!sf)
94
+ return null;
95
+ const cache = cacheOf(project);
96
+ const text = sf.getFullText();
97
+ const cached = cache.get(rel);
98
+ if (cached && cached.text === text)
99
+ return cached;
100
+ const importMap = (0, resolve_1.importNameModules)(sf, ctx.repoRoot, ctx.aliases, ctx.repoFiles);
101
+ const facts = { text, exports: (0, file_exports_1.exportsOf)(sf, importMap, { ...ctx, rel }), local: localExported(sf) };
102
+ cache.set(rel, facts);
103
+ return facts;
104
+ };
105
+ // What this module says about `name`, in the order TypeScript reads it: an
106
+ // explicit export first (named, then `default`), then the module's own
107
+ // declarations, then the star re-exports — a name is "found in the star" only
108
+ // when nothing above it names it.
109
+ const whereOf = (facts, name) => {
110
+ const namespace = facts.exports.find((exp) => exp.form === "namespace" && (exp.named ?? []).includes(name));
111
+ if (namespace)
112
+ return { kind: "module", file: namespace.from ?? "" };
113
+ const named = facts.exports.find((exp) => exp.form === "named" && (exp.named ?? []).includes(name));
114
+ if (named) {
115
+ if (!named.from)
116
+ return { kind: "here" };
117
+ const at = (named.named ?? []).indexOf(name);
118
+ // The name AFTER `as` is the caller's; the one BEFORE it is what the
119
+ // declaring module knows (`export { default as codeEditor }`).
120
+ return { kind: "re-export", file: named.from, name: named.original?.[at] ?? name };
121
+ }
122
+ if (name === "default") {
123
+ const def = facts.exports.find((exp) => exp.form === "default" || exp.form === "equals");
124
+ if (def)
125
+ return def.from ? { kind: "re-export", file: def.from, name: "default" } : { kind: "here" };
126
+ }
127
+ if (facts.local.has(name))
128
+ return { kind: "here" };
129
+ const star = facts.exports.find((exp) => exp.form === "star" && exp.from);
130
+ if (star?.from)
131
+ return { kind: "star", file: star.from };
132
+ return { kind: "none" };
133
+ };
134
+ const inside = (ctx, file) => Boolean(file) && !node_path_1.default.isAbsolute(file ?? "") && (ctx.repoFiles ?? []).includes(file ?? "");
135
+ const walk = (ctx, step) => {
136
+ const { rel, name, seen, steps } = step;
137
+ if (steps > (ctx.barrelDepth ?? DEFAULT_BARREL_DEPTH))
138
+ return null;
139
+ const key = `${rel}#${name}`;
140
+ if (seen.has(key))
141
+ return null;
142
+ seen.add(key);
143
+ const facts = factsOf(ctx, rel);
144
+ if (!facts)
145
+ return null;
146
+ const where = whereOf(facts, name);
147
+ if (where.kind === "here")
148
+ return rel;
149
+ if (where.kind === "module")
150
+ return inside(ctx, where.file) ? where.file : null;
151
+ if (where.kind === "re-export" || where.kind === "star") {
152
+ if (!inside(ctx, where.file))
153
+ return null;
154
+ return walk(ctx, { rel: where.file, name: where.kind === "star" ? name : where.name, seen, steps: steps + 1 });
155
+ }
156
+ return null;
157
+ };
158
+ // The declaring file of each name, in the names' own order (`null` = unknown).
159
+ const declaringFiles = (ctx, module, names) => names.map((name) => {
160
+ try {
161
+ return walk(ctx, { rel: module, name, seen: new Set(), steps: 0 });
162
+ }
163
+ catch {
164
+ return null;
165
+ }
166
+ });
167
+ exports.declaringFiles = declaringFiles;
168
+ // The declaring file of an exported name a module re-exports (`export { a } from
169
+ // "./barrel"`): the same walk, started at the module the statement names.
170
+ const declaringExportFiles = (ctx, from, names) => declaringFiles(ctx, from, names);
171
+ exports.declaringExportFiles = declaringExportFiles;
@@ -1,6 +1,6 @@
1
1
  import { type SourceFile } from "ts-morph";
2
2
  import type { CollectOptions } from "./file-facts";
3
- import type { ExportFact } from "../facts";
3
+ import type { ExportFact } from "@md-code/follow-architecture/entities/facts";
4
4
  type ResolveCtx = Omit<CollectOptions, "candidates">;
5
5
  declare const exportsOf: (sf: SourceFile, importMap: ReadonlyMap<string, string>, ctx: ResolveCtx) => ExportFact[];
6
6
  export { exportsOf };
@@ -11,7 +11,8 @@ exports.exportsOf = void 0;
11
11
  const ts_morph_1 = require("ts-morph");
12
12
  const tree_1 = require("./tree");
13
13
  const properties_1 = require("./properties");
14
- const imports_1 = require("../../utils/imports");
14
+ const imports_1 = require("@md-code/follow-architecture/utils/imports");
15
+ const export_chain_1 = require("./export-chain");
15
16
  // The form of one `export …` statement: a namespace re-export, a star
16
17
  // re-export, or named exports.
17
18
  const formOf = (exp) => {
@@ -23,9 +24,11 @@ const formOf = (exp) => {
23
24
  };
24
25
  const statementExport = (exp, importMap, ctx) => {
25
26
  const named = exp.getNamedExports().map((el) => el.getAliasNode()?.getText() ?? el.getName());
27
+ const original = exp.getNamedExports().map((el) => el.getName());
26
28
  const entry = {
27
29
  form: formOf(exp),
28
30
  named,
31
+ original,
29
32
  from: null,
30
33
  source: null,
31
34
  name: null,
@@ -49,6 +52,10 @@ const statementExport = (exp, importMap, ctx) => {
49
52
  // re-export like any other — the code being published is not this file's.
50
53
  if (!entry.from && entry.named?.length === 1 && importMap.has(entry.named[0]))
51
54
  entry.from = importMap.get(entry.named[0]) ?? null;
55
+ // A re-exported name is judged where it is declared: `export { a } from
56
+ // "./barrel"` hides the same declaring file as the import it stands for.
57
+ if (entry.from && entry.named?.length)
58
+ entry.declaring = (0, export_chain_1.declaringExportFiles)(ctx, entry.from, entry.named);
52
59
  return entry;
53
60
  };
54
61
  // `export default <expr>` / `export = <expr>`: no declaration modifier to find,
@@ -56,14 +63,30 @@ const statementExport = (exp, importMap, ctx) => {
56
63
  // binding, the export is a pass-through of that module.
57
64
  const assignmentExport = (ea, importMap) => {
58
65
  const text = ea.getExpression()?.getText() ?? "";
59
- return { form: ea.isExportEquals() ? "equals" : "default", named: [], source: null, from: text ? (importMap.get(text) ?? null) : null, name: null, line: (0, tree_1.startLine)(ea), piece: (0, properties_1.enclosingPiece)(ea) };
66
+ return {
67
+ form: ea.isExportEquals() ? "equals" : "default",
68
+ named: [],
69
+ source: null,
70
+ from: text ? (importMap.get(text) ?? null) : null,
71
+ name: null,
72
+ line: (0, tree_1.startLine)(ea),
73
+ piece: (0, properties_1.enclosingPiece)(ea),
74
+ };
60
75
  };
61
76
  // CommonJS, in every form it is still written in.
62
77
  const commonJsExport = (d) => {
63
78
  const m = /^(?:module\.)?exports(?:\.([A-Za-z0-9_$]+))?$/.exec(d.getLeft().getText());
64
79
  if (!m)
65
80
  return null;
66
- return { form: "commonjs", named: [], source: null, from: null, name: m[1] ?? null, line: d.getStartLineNumber(), piece: (0, properties_1.enclosingPiece)(d) };
81
+ return {
82
+ form: "commonjs",
83
+ named: [],
84
+ source: null,
85
+ from: null,
86
+ name: m[1] ?? null,
87
+ line: d.getStartLineNumber(),
88
+ piece: (0, properties_1.enclosingPiece)(d),
89
+ };
67
90
  };
68
91
  const exportsOf = (sf, importMap, ctx) => {
69
92
  const statementExports = sf.getExportDeclarations().map((exp) => statementExport(exp, importMap, ctx));
@@ -1,13 +1,16 @@
1
- import { type SourceFile } from "ts-morph";
1
+ import { type Project, type SourceFile } from "ts-morph";
2
2
  import type { AliasMap } from "./project";
3
- import type { FileFacts, Candidate } from "../facts";
3
+ import type { FileFacts, Candidate } from "@md-code/follow-architecture/entities/facts";
4
4
  interface CollectOptions {
5
5
  rel: string;
6
6
  repoFiles?: string[];
7
7
  aliases?: AliasMap;
8
8
  repoRoot: string;
9
9
  candidates?: Candidate[];
10
+ barrelDepth?: number;
11
+ project?: Project;
10
12
  }
11
13
  declare const collectFileFacts: (sf: SourceFile, options: CollectOptions) => FileFacts;
12
- export { collectFileFacts };
14
+ declare const releaseFileFacts: (sf: SourceFile) => void;
15
+ export { collectFileFacts, releaseFileFacts };
13
16
  export type { CollectOptions };
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectFileFacts = void 0;
3
+ exports.releaseFileFacts = exports.collectFileFacts = void 0;
4
4
  const tree_1 = require("./tree");
5
5
  const properties_1 = require("./properties");
6
6
  const resolve_1 = require("./resolve");
7
7
  const file_imports_1 = require("./file-imports");
8
8
  const file_exports_1 = require("./file-exports");
9
- const location_1 = require("../location");
10
- const collectFileFacts = (sf, options) => {
9
+ const location_1 = require("@md-code/follow-architecture/entities/location");
10
+ const buildFileFacts = (sf, options) => {
11
11
  const { rel, repoFiles, aliases, repoRoot, candidates } = options;
12
12
  // The import map is rebuilt here because reads are a FILE fact, not a
13
13
  // per-candidate one: a read is a property of the file's surface.
@@ -29,7 +29,36 @@ const collectFileFacts = (sf, options) => {
29
29
  // What is in the file: its own node, and every node below it.
30
30
  kind: { own: (0, tree_1.descriptor)(sf), descendants: (0, tree_1.descendantsOf)(sf) },
31
31
  candidates: candidates ?? [],
32
- roles: [...new Set((candidates ?? []).map((c) => c.role).filter((r) => Boolean(r)))],
32
+ entities: [...new Set((candidates ?? []).map((c) => c.entity).filter((r) => Boolean(r)))],
33
33
  };
34
34
  };
35
+ // The facts of a file are the same every time it is read in a run: the source is
36
+ // parsed once, `repoFiles`/`aliases`/`repoRoot` describe the SAME repo. A run
37
+ // reads a file's facts in several places (the linted file's pipeline and the
38
+ // project-wide index, for instance), so they are computed once per SourceFile
39
+ // and handed out as a shallow copy — a consumer may attach `entities` to the
40
+ // file's fact object without touching the cached one. Guarded by the file's
41
+ // current text: an overwritten SourceFile has different facts. The barrel budget is
42
+ // part of the key too — the same file walked with a different `barrelDepth`
43
+ // answers a different declaring file.
44
+ const FILE_FACTS = new WeakMap();
45
+ const collectFileFacts = (sf, options) => {
46
+ // A caller that hands real `candidates` derives `entities` from them, so that
47
+ // result is its own and is not cached.
48
+ if (options.candidates?.length)
49
+ return buildFileFacts(sf, options);
50
+ const text = sf.getFullText();
51
+ const cached = FILE_FACTS.get(sf);
52
+ if (cached && cached.text === text && cached.depth === options.barrelDepth)
53
+ return { ...cached.facts };
54
+ const facts = buildFileFacts(sf, options);
55
+ FILE_FACTS.set(sf, { text, depth: options.barrelDepth, facts });
56
+ return { ...facts };
57
+ };
35
58
  exports.collectFileFacts = collectFileFacts;
59
+ // Drop this file's cached facts, for the same reason as the comment cache: they
60
+ // are derived from a syntax tree the run has finished with.
61
+ const releaseFileFacts = (sf) => {
62
+ FILE_FACTS.delete(sf);
63
+ };
64
+ exports.releaseFileFacts = releaseFileFacts;
@@ -1,5 +1,5 @@
1
1
  import { type SourceFile } from "ts-morph";
2
2
  import type { ResolveCtx } from "./file-exports";
3
- import type { ImportFact } from "../facts";
3
+ import type { ImportFact } from "@md-code/follow-architecture/entities/facts";
4
4
  declare const importsOf: (sf: SourceFile, ctx: ResolveCtx) => ImportFact[];
5
5
  export { importsOf };
@@ -13,18 +13,34 @@ const ts_morph_1 = require("ts-morph");
13
13
  const tree_1 = require("./tree");
14
14
  const properties_1 = require("./properties");
15
15
  const heritage_1 = require("./heritage");
16
- const imports_1 = require("../../utils/imports");
16
+ const imports_1 = require("@md-code/follow-architecture/utils/imports");
17
+ const export_chain_1 = require("./export-chain");
17
18
  const statementImport = (imp, ctx) => {
18
19
  const source = imp.getModuleSpecifierValue();
19
20
  // Named imports carry the LOCAL binding name (`b as c` → "c").
20
- const entry = { form: "statement", source, typeOnly: imp.isTypeOnly(), named: imp.getNamedImports().map((el) => el.getAliasNode()?.getText() ?? el.getName()), line: (0, tree_1.startLine)(imp), piece: null };
21
+ const entry = {
22
+ form: "statement",
23
+ source,
24
+ typeOnly: imp.isTypeOnly(),
25
+ named: imp.getNamedImports().map((el) => el.getAliasNode()?.getText() ?? el.getName()),
26
+ line: (0, tree_1.startLine)(imp),
27
+ piece: null,
28
+ };
21
29
  const def = imp.getDefaultImport();
22
30
  if (def)
23
31
  entry.defaultName = def.getText();
24
32
  const ns = imp.getNamespaceImport();
25
33
  if (ns)
26
34
  entry.namespaceName = ns.getText();
35
+ entry.imported = imp.getNamedImports().map((el) => el.getName());
27
36
  entry.resolved = (0, imports_1.resolveImport)(imp.getSourceFile(), source, ctx);
37
+ // A named import is judged where the NAME is declared, not where the module
38
+ // that passes it on lives. No names (or no resolution) leaves the edge on the
39
+ // module file, as every relation did before.
40
+ // The DECLARED name is the one inside the braces; an alias (`X as Y`) renames the
41
+ // binding, never the symbol the target file declares.
42
+ if (entry.imported?.length && entry.resolved)
43
+ entry.declaring = (0, export_chain_1.declaringFiles)(ctx, entry.resolved, entry.imported);
28
44
  return entry;
29
45
  };
30
46
  // `require("x")` / `import("x")` — the call forms, only when the first argument
@@ -38,7 +54,14 @@ const callImport = (call, ctx) => {
38
54
  const arg = call.getArguments()[0];
39
55
  if (!arg || arg.getKind() !== tree_1.SK.StringLiteral)
40
56
  return null;
41
- const entry = { form: isDynamic ? "dynamic" : "require", source: (0, tree_1.nodeText)(arg) || null, typeOnly: false, named: [], line: call.getStartLineNumber(), piece: (0, properties_1.enclosingPiece)(call) };
57
+ const entry = {
58
+ form: isDynamic ? "dynamic" : "require",
59
+ source: (0, tree_1.nodeText)(arg) || null,
60
+ typeOnly: false,
61
+ named: [],
62
+ line: call.getStartLineNumber(),
63
+ piece: (0, properties_1.enclosingPiece)(call),
64
+ };
42
65
  entry.resolved = (0, imports_1.resolveImport)(call.getSourceFile(), entry.source ?? "", ctx);
43
66
  return entry;
44
67
  };
@@ -1,5 +1,5 @@
1
1
  export { createTsProject, loadSourceFile } from "./project";
2
- export { importNameModules, declaredFileOfNode, declaredFileOf, declaredFileOfType, declaredFileOfExpr, repoRelative, inRepo } from "./resolve";
3
- export { collectFileFacts } from "./file-facts";
2
+ export { importNameModules, declaredFileOfNode, declaredFileOf, declaredFileOfType, declaredFileOfExpr, repoRelative, inRepo, } from "./resolve";
3
+ export { collectFileFacts, releaseFileFacts } from "./file-facts";
4
4
  export type { DeclInfo } from "./resolve";
5
5
  export type { AliasMap } from "./project";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectFileFacts = exports.inRepo = exports.repoRelative = exports.declaredFileOfExpr = exports.declaredFileOfType = exports.declaredFileOf = exports.declaredFileOfNode = exports.importNameModules = exports.loadSourceFile = exports.createTsProject = void 0;
3
+ exports.releaseFileFacts = exports.collectFileFacts = exports.inRepo = exports.repoRelative = exports.declaredFileOfExpr = exports.declaredFileOfType = exports.declaredFileOf = exports.declaredFileOfNode = exports.importNameModules = exports.loadSourceFile = exports.createTsProject = void 0;
4
4
  // A source file: how it is loaded, and everything that is true about it. The
5
5
  // entity is split by question, each half in its own module, re-exported here so
6
6
  // every consumer keeps importing `entities/ast/file`:
@@ -20,3 +20,4 @@ Object.defineProperty(exports, "repoRelative", { enumerable: true, get: function
20
20
  Object.defineProperty(exports, "inRepo", { enumerable: true, get: function () { return resolve_1.inRepo; } });
21
21
  var file_facts_1 = require("./file-facts");
22
22
  Object.defineProperty(exports, "collectFileFacts", { enumerable: true, get: function () { return file_facts_1.collectFileFacts; } });
23
+ Object.defineProperty(exports, "releaseFileFacts", { enumerable: true, get: function () { return file_facts_1.releaseFileFacts; } });