@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
@@ -23,39 +23,40 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.normalizeInvariant = void 0;
27
- // Normalize an invariant from the YAML into the runtime shape the gates and
26
+ exports.normalizeRule = void 0;
27
+ // Normalize a rule from the YAML into the runtime shape the gates and
28
28
  // checkers consume.
29
29
  //
30
- // An invariant is: WHERE it applies (`where`), where it does NOT (`ignore`),
30
+ // A rule is: WHERE it applies (`where`), where it does NOT (`ignore`),
31
31
  // and what it forbids (`infer`). Both `where` and `ignore` are the same
32
- // mechanism the code roles use (utils/where.js).
32
+ // mechanism the code entities use (utils/where.js).
33
33
  //
34
- // `infer` is the SAME key as in a codeRole, because it is the SAME filter
35
- // language: the difference is only what a match means. In a role a match says
36
- // "this code IS that role"; in an invariant it says "this file breaks the
34
+ // `infer` is the SAME key as in an entity, because it is the SAME filter
35
+ // language: the difference is only what a match means. In an entity a match says
36
+ // "this code IS that entity"; in a rule it says "this file breaks the
37
37
  // rule". There is one check: a finding when the filter matches. "This must be
38
38
  // true" is the same filter under `not:` — the language already has it, so a
39
39
  // second key would be a second way to say one thing.
40
- const location_1 = require("../entities/location");
41
- const schema_1 = require("../entities/schema");
42
- const field_1 = require("../utils/field");
43
- const configError = __importStar(require("../report/configErrors"));
44
- // Every key an invariant may carry — anything else is a declaration the config
40
+ const location_1 = require("@md-code/follow-architecture/entities/location");
41
+ const aliases_1 = require("@md-code/follow-architecture/utils/aliases");
42
+ const schema_1 = require("@md-code/follow-architecture/entities/schema");
43
+ const field_1 = require("@md-code/follow-architecture/utils/field");
44
+ const configError = __importStar(require("@md-code/follow-architecture/report/configErrors"));
45
+ // Every key a rule may carry — anything else is a declaration the config
45
46
  // believes it made, so it fails loudly instead of doing nothing.
46
- const INVARIANT_KEYS = new Set(schema_1.SCHEMA.invariant);
47
+ const RULE_KEYS = new Set(schema_1.SCHEMA.rule);
47
48
  const checkKeys = (raw) => {
48
49
  for (const key of Object.keys(raw)) {
49
- if (INVARIANT_KEYS.has(key))
50
+ if (RULE_KEYS.has(key))
50
51
  continue;
51
- throw configError.unknownInvariantKey({ id: raw.id, key, allowed: schema_1.SCHEMA.invariant });
52
+ throw configError.unknownRuleKey({ id: raw.id, key });
52
53
  }
53
54
  };
54
55
  // `dedupeBy` is `where` vocabulary, not a fact name. A bare string that is not
55
- // a declared role and not a path is a mistake worth failing on: `path.dir`
56
+ // a declared entity and not a path is a mistake worth failing on: `path.dir`
56
57
  // used to be a fact name and would now silently match no path at all.
57
- const parseDedupe = (raw, roles) => {
58
- const entries = (0, location_1.parseWhere)(raw, roles);
58
+ const parseDedupe = (raw, entities, aliases) => {
59
+ const entries = (0, location_1.parseWhere)(raw, entities, aliases);
59
60
  for (const entry of entries) {
60
61
  if (entry.type !== "glob")
61
62
  continue;
@@ -65,31 +66,33 @@ const parseDedupe = (raw, roles) => {
65
66
  }
66
67
  return entries;
67
68
  };
68
- // `roles` (a Set of declared slugs) is only needed so a bare string naming a
69
- // role is read as a role reference instead of a glob — the same rule the
70
- // code-role actions follow.
71
- const normalizeInvariant = (raw, roles = null) => {
69
+ // `entities` (a Set of declared slugs) is only needed so a bare string naming a
70
+ // entity is read as an entity reference instead of a glob — the same rule the
71
+ // code-entity actions follow.
72
+ const normalizeRule = (raw, entities = null, aliases = null) => {
72
73
  if (!(0, field_1.isObj)(raw))
73
- throw configError.invariantNotAnObject();
74
+ throw configError.ruleNotAnObject();
74
75
  if (!raw.id)
75
- throw configError.invariantWithoutId();
76
+ throw configError.ruleWithoutId();
76
77
  checkKeys(raw);
77
78
  return {
78
79
  id: String(raw.id),
79
- // The SAME `where` mechanism the code-role actions use.
80
- where: (0, location_1.parseWhere)(raw.where, roles),
81
- ignore: (0, location_1.parseWhere)(raw.ignore, roles),
80
+ // The SAME `where` mechanism the code-entity actions use.
81
+ where: (0, location_1.parseWhere)(raw.where, entities, aliases),
82
+ ignore: (0, location_1.parseWhere)(raw.ignore, entities, aliases),
82
83
  when: raw.when ?? null,
83
84
  // A finding when a filter MATCHES. "Must be true" is the same filter
84
85
  // under `not:` — one check, one direction, negation in the filter.
85
- infer: (0, location_1.toList)(raw.infer),
86
+ // `infer` is the filter language too, so a `location` filter in it reads
87
+ // `@`-patterns as aliases — the same rewrite `where` gets.
88
+ infer: (0, location_1.toList)(raw.infer).map((entry) => (0, aliases_1.expandLocationFilters)(entry, aliases)),
86
89
  report: typeof raw.report === "string" || (0, field_1.isObj)(raw.report) ? raw.report : null,
87
90
  // WHERE the findings are counted: a `where` entry, the same vocabulary
88
- // the roles use. `{ node: feature }` = one finding per feature folder,
91
+ // the entities use. `{ node: feature }` = one finding per feature folder,
89
92
  // a glob = one per matched folder, a filter = one per file's folder.
90
93
  // The engine only counts — the entry says which place.
91
- dedupeBy: parseDedupe(raw.dedupeBy, roles),
92
- children: (0, location_1.toList)(raw.children).map((c) => normalizeInvariant(c, roles)),
94
+ dedupeBy: parseDedupe(raw.dedupeBy, entities, aliases),
95
+ children: (0, location_1.toList)(raw.children).map((c) => normalizeRule(c, entities, aliases)),
93
96
  };
94
97
  };
95
- exports.normalizeInvariant = normalizeInvariant;
98
+ exports.normalizeRule = normalizeRule;
@@ -1,6 +1,6 @@
1
- import { type FieldValue } from "../utils/field";
2
- import type { QueryScope } from "../entities/architecture";
3
- import type { FileContext } from "../entities/context";
1
+ import { type FieldValue } from "@md-code/follow-architecture/utils/field";
2
+ import type { QueryScope } from "@md-code/follow-architecture/entities/architecture";
3
+ import type { FileContext } from "@md-code/follow-architecture/entities/context";
4
4
  type ReportVars = Record<string, string | number>;
5
5
  declare const filterOf: (entry: FieldValue) => FieldValue;
6
6
  declare const enrichedVars: (ctx: FileContext) => ReportVars;
@@ -10,10 +10,12 @@ declare const QUANTIFIERS: Set<string>;
10
10
  declare const branchOf: (sub: FieldValue) => FieldValue;
11
11
  declare const describePiece: (c: {
12
12
  lines?: number[];
13
- css?: {
14
- templates?: {
15
- tag?: string;
16
- }[];
13
+ framework?: {
14
+ css?: {
15
+ templates?: {
16
+ tag?: string;
17
+ }[];
18
+ };
17
19
  };
18
20
  }) => string;
19
21
  export { filterOf, enrichedVars, listHit, collectScalars, branchOf, describePiece, QUANTIFIERS };
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QUANTIFIERS = exports.describePiece = exports.branchOf = exports.collectScalars = exports.listHit = exports.enrichedVars = exports.filterOf = void 0;
4
- // Report VARIABLES for the invariant runtime: the placeholders a finding's
4
+ // Report VARIABLES for the rule runtime: the placeholders a finding's
5
5
  // sentence may name. Every variable is read off the facts themselves — the
6
6
  // path vars, the scalars a fact carries, the items a filter matched — so no
7
7
  // list of known names can fall behind the fact model.
8
- const queries_1 = require("../entities/queries");
9
- const field_1 = require("../utils/field");
10
- const record_1 = require("../utils/record");
8
+ const queries_1 = require("@md-code/follow-architecture/entities/queries");
9
+ const field_1 = require("@md-code/follow-architecture/utils/field");
10
+ const record_1 = require("@md-code/follow-architecture/utils/record");
11
11
  const name_1 = require("./name");
12
12
  // A check's `report` is the message template for its findings, not a filter
13
13
  // key — strip it before matching so it is not treated as a fact field. The
@@ -111,7 +111,7 @@ exports.branchOf = branchOf;
111
111
  // so the sentence can still be followed to a line.
112
112
  const describePiece = (c) => {
113
113
  const line = c.lines?.[0] ?? 1;
114
- const tag = c.css?.templates?.[0]?.tag ?? null;
114
+ const tag = c.framework?.css?.templates?.[0]?.tag ?? null;
115
115
  return tag ? `the ${tag} block at line ${line}` : `the code at line ${line}`;
116
116
  };
117
117
  exports.describePiece = describePiece;
@@ -0,0 +1,20 @@
1
+ import type { Project } from "ts-morph";
2
+ import type { Arch } from "./entities/architecture";
3
+ import type { ProjectEntityIndex } from "./code-entities/project";
4
+ declare const openRun: (next: {
5
+ repoRoot: string;
6
+ arch: Pick<Arch, "aliases">;
7
+ absFiles: readonly string[];
8
+ whole?: Project | null;
9
+ }) => void;
10
+ declare const endRun: () => void;
11
+ declare const runIsOpen: () => boolean;
12
+ declare const adoptEntityIndex: (index: ProjectEntityIndex | null) => void;
13
+ declare const useRegistrySource: (source: (() => ProjectEntityIndex | null) | null) => void;
14
+ declare const sourcedRegistry: () => ProjectEntityIndex | null;
15
+ declare const adoptedEntityIndex: () => ProjectEntityIndex | null;
16
+ declare const scannedFiles: () => readonly string[];
17
+ declare const wholeRepoProject: () => Project;
18
+ declare const projectsOpened: () => number;
19
+ declare const openWholeRepoProject: () => Project | null;
20
+ export { openRun, endRun, runIsOpen, scannedFiles, wholeRepoProject, projectsOpened, openWholeRepoProject, adoptEntityIndex, adoptedEntityIndex, useRegistrySource, sourcedRegistry, };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sourcedRegistry = exports.useRegistrySource = exports.adoptedEntityIndex = exports.adoptEntityIndex = exports.openWholeRepoProject = exports.projectsOpened = exports.wholeRepoProject = exports.scannedFiles = exports.runIsOpen = exports.endRun = exports.openRun = void 0;
4
+ // WHICH PROJECT A RUN OPENS, AND HOW LONG IT LIVES.
5
+ //
6
+ // A scan asks two kinds of question, and they differ in what they need in
7
+ // memory:
8
+ //
9
+ // - about ONE file: which pieces it declares, which entity each piece carries,
10
+ // what its syntax does. One file's syntax would be enough.
11
+ // - about the WHOLE repo: who uses a name (`references`, `implementations`),
12
+ // which custom properties every stylesheet declares, where the lookalikes of
13
+ // a folder are. A project holding one file answers "nobody" for a helper the
14
+ // rest of the repo calls, so these questions force a project over EVERY
15
+ // scanned file.
16
+ //
17
+ // Sharding was tried and measured: a batch project for the per-file work does not
18
+ // help. The whole-repo project has to exist anyway (the questions above are
19
+ // always asked), so the second project only parses every file twice — same
20
+ // memory, more time. What is left here is therefore ONE project over every
21
+ // scanned file, created on the first question that needs it, so a run that asks
22
+ // nothing (an all-unchanged warm run) pays nothing for it.
23
+ //
24
+ // The ESLint rule already owns such a project, and linting interleaves repos in
25
+ // one process: a run is a NAMED entry (one per repo root), and the rule hands its
26
+ // project in instead of letting this module open a second copy.
27
+ const config_project_1 = require("./config-project");
28
+ const runs = new Map();
29
+ let current = null;
30
+ // The project-wide entity index, when the run got it from the file index instead
31
+ // of reading every file: the pass that builds it is the run's most expensive one,
32
+ // and a run whose records are all fresh would otherwise repeat it for nothing.
33
+ let adopted = null;
34
+ // Make `repoRoot`'s run current, creating it on first sight. `whole` is a project
35
+ // the caller already built over the same file list — reusing it is the point, as
36
+ // a second copy would double the largest structure in the run.
37
+ const openRun = (next) => {
38
+ openedProjects = 0;
39
+ const known = runs.get(next.repoRoot);
40
+ if (known && known.absFiles === next.absFiles) {
41
+ current = known;
42
+ if (next.whole)
43
+ known.whole = next.whole;
44
+ return;
45
+ }
46
+ adopted = null;
47
+ const created = {
48
+ repoRoot: next.repoRoot,
49
+ arch: next.arch,
50
+ absFiles: next.absFiles,
51
+ whole: next.whole ?? null,
52
+ };
53
+ runs.set(next.repoRoot, created);
54
+ current = created;
55
+ };
56
+ exports.openRun = openRun;
57
+ // A CLI run's end: the run's project goes away with it. (The ESLint rule never
58
+ // ends its run — its state lives as long as the lint session.)
59
+ const endRun = () => {
60
+ if (current)
61
+ runs.delete(current.repoRoot);
62
+ current = null;
63
+ };
64
+ exports.endRun = endRun;
65
+ const runIsOpen = () => current != null;
66
+ exports.runIsOpen = runIsOpen;
67
+ // Hand the run an index it did not have to build (`code-entities/project` reads it
68
+ // before its own pass), or clear it with null.
69
+ const adoptEntityIndex = (index) => {
70
+ adopted = index;
71
+ };
72
+ exports.adoptEntityIndex = adoptEntityIndex;
73
+ // Where a run that never enumerated the tree can get the project-wide index from:
74
+ // the index file's own summaries and pieces. The rule path asks about one file at
75
+ // a time and never walks the repo, so without this its first check would read every
76
+ // file's syntax to answer a question the index already answered. The source is
77
+ // consulted ONCE per run (the run caches what it returns by its file list).
78
+ let registrySource = null;
79
+ const useRegistrySource = (source) => {
80
+ registrySource = source;
81
+ };
82
+ exports.useRegistrySource = useRegistrySource;
83
+ const sourcedRegistry = () => (registrySource === null ? null : registrySource());
84
+ exports.sourcedRegistry = sourcedRegistry;
85
+ const adoptedEntityIndex = () => adopted;
86
+ exports.adoptedEntityIndex = adoptedEntityIndex;
87
+ // The files the run scans, in scan order. The array's identity is the run's
88
+ // identity: a cache keyed by it belongs to one run only.
89
+ const scannedFiles = () => current?.absFiles ?? [];
90
+ exports.scannedFiles = scannedFiles;
91
+ // The project over every scanned file — created on first use, which is where the
92
+ // run's largest structure comes from.
93
+ //
94
+ // Asked before any run was opened, nothing is scanned: an empty project sees no
95
+ // files, so a whole-repo question reads "no evidence" instead of taking a lint
96
+ // session down. That answer is WRONG for a real scan, so the state is made loud
97
+ // where it can be seen — a process warning on stderr (a technical note about the
98
+ // run, not a sentence about the config a reader has to act on) — while the run
99
+ // itself keeps going. Both entry points (the CLI and the rule) open a run before
100
+ // the first question, so this is a wiring bug, not a state a scan reaches.
101
+ const NO_FILES = [];
102
+ const EMPTY = { repoRoot: "", arch: { aliases: {} }, files: NO_FILES };
103
+ let warnedNoRun = false;
104
+ const warnNoRun = () => {
105
+ if (warnedNoRun)
106
+ return;
107
+ warnedNoRun = true;
108
+ process.emitWarning("follow-architecture: a whole-repo question was asked with no scan run open (empty project)");
109
+ };
110
+ // How many whole-repo projects this run has BUILT (not merely asked for): the
111
+ // number a run must keep at one — the extraction's answer pass builds it, the
112
+ // checks reuse it, and a second one would be a second parse of the repo.
113
+ let openedProjects = 0;
114
+ const wholeRepoProject = () => {
115
+ if (current == null) {
116
+ warnNoRun();
117
+ return (0, config_project_1.openProject)(EMPTY.repoRoot, EMPTY.files, EMPTY.arch);
118
+ }
119
+ if (current.whole == null) {
120
+ current.whole = (0, config_project_1.openProject)(current.repoRoot, current.absFiles, current.arch);
121
+ openedProjects += 1;
122
+ }
123
+ return current.whole;
124
+ };
125
+ exports.wholeRepoProject = wholeRepoProject;
126
+ const projectsOpened = () => openedProjects;
127
+ exports.projectsOpened = projectsOpened;
128
+ // That project when something already opened it.
129
+ const openWholeRepoProject = () => current?.whole ?? null;
130
+ exports.openWholeRepoProject = openWholeRepoProject;
@@ -103,9 +103,9 @@ for (const f of data.findings) {
103
103
  // divergence this file exists to catch.
104
104
  for (const o of f.fixOptions ?? []) {
105
105
  // Repairs with no geometry: the rule's own words (`rules`), "give this code
106
- // a role" (`role`), "create what is missing" (`add`). They name no place,
106
+ // an entity" (`entity`), "create what is missing" (`add`). They name no place,
107
107
  // and the card says so — that is not a divergence.
108
- if (o.code === "rules" || o.code === "role" || o.code === "add")
108
+ if (o.code === "rules" || o.code === "entity" || o.code === "add")
109
109
  continue;
110
110
  // A deletion has no geometry either — and it is NOT the same as "nothing":
111
111
  // the card must say "removed", which `plan.remove` carries.
@@ -0,0 +1,4 @@
1
+ import type { ReferencesFact } from "@md-code/follow-architecture/entities/facts";
2
+ declare const primeUsageIndex: (repoRoot: string, repoFiles: readonly string[]) => void;
3
+ declare const usageFromIndex: (name: string | null, rel: string, exported: boolean, kindName: string | null | undefined) => ReferencesFact | null;
4
+ export { primeUsageIndex, usageFromIndex };
@@ -0,0 +1,272 @@
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.usageFromIndex = exports.primeUsageIndex = void 0;
27
+ // THE OPTIONAL, CHEAPER SOURCE OF `references` (option `usage: index`, CLI
28
+ // `--usage index`): an answer computed from an index of IDENTIFIER OCCURRENCES
29
+ // instead of from a program that holds the whole repository. The default stays
30
+ // the checker (`entities/ast/usage.ts`), whose answer is what this mode
31
+ // approximates: it is faster and costs less memory, and it is wrong wherever two
32
+ // modules use one name for different things.
33
+ //
34
+ // The index is one pass over the text of every scanned file with `ts.createScanner`
35
+ // — tokens, no AST, no project, no checker. Per name it keeps, per file: how many
36
+ // standalone occurrences, how many after a dot (`?.` included — a member, not the
37
+ // value), how many import specifiers (a binding, but the checker counts it as a
38
+ // reference too), how many `export … from` specifiers (a republish, which
39
+ // `usedIn` excludes), and whether the file declares the name at top level (then
40
+ // every occurrence in it belongs to that declaration, not to the name).
41
+ //
42
+ // The answer keeps the shape and the meaning of `ReferencesFact`
43
+ // (`entities/facts.ts:138`): `total`, `outside`, `files`, `usedIn`.
44
+ const fs = __importStar(require("node:fs"));
45
+ const path = __importStar(require("node:path"));
46
+ const ts_morph_1 = require("ts-morph");
47
+ const empty = () => ({ declares: false, plain: 0, member: 0, imported: 0, exported: 0, declared: 0 });
48
+ const emptySums = () => ({ total: 0, outside: 0, where: [], used: [] });
49
+ let index = null;
50
+ const isDeclKeyword = (kind) => kind === ts_morph_1.ts.SyntaxKind.FunctionKeyword ||
51
+ kind === ts_morph_1.ts.SyntaxKind.ClassKeyword ||
52
+ kind === ts_morph_1.ts.SyntaxKind.ConstKeyword ||
53
+ kind === ts_morph_1.ts.SyntaxKind.LetKeyword ||
54
+ kind === ts_morph_1.ts.SyntaxKind.VarKeyword ||
55
+ kind === ts_morph_1.ts.SyntaxKind.InterfaceKeyword ||
56
+ kind === ts_morph_1.ts.SyntaxKind.TypeKeyword ||
57
+ kind === ts_morph_1.ts.SyntaxKind.EnumKeyword ||
58
+ kind === ts_morph_1.ts.SyntaxKind.AbstractKeyword ||
59
+ kind === ts_morph_1.ts.SyntaxKind.AsyncKeyword;
60
+ // One file's text → its occurrences. The scanner is the parser's own lexer: it
61
+ // knows a comment from a string from a template from a regex, which is the reason
62
+ // the index can be built without an AST at all.
63
+ // eslint-disable-next-line complexity, max-lines-per-function -- a token scanner is a state machine: the roles (value / member / import / export / declaration) are decided from one running cursor and the previous token, and the branches are its states.
64
+ const scanInto = (into, rel, text) => {
65
+ const scanner = ts_morph_1.ts.createScanner(ts_morph_1.ts.ScriptTarget.Latest, true, ts_morph_1.ts.LanguageVariant.JSX, text);
66
+ const touch = (name) => {
67
+ let files = into.get(name);
68
+ if (!files) {
69
+ files = new Map();
70
+ into.set(name, files);
71
+ }
72
+ let found = files.get(rel);
73
+ if (!found) {
74
+ found = empty();
75
+ files.set(rel, found);
76
+ }
77
+ return found;
78
+ };
79
+ let previous = ts_morph_1.ts.SyntaxKind.Unknown;
80
+ let depth = 0;
81
+ // `export { … } from "x"`: the names between the braces, kept until `from`
82
+ // says they are a republish. Any other token ends the guess.
83
+ let pendingExport = null;
84
+ let pendingState = "idle";
85
+ // `import { … } from` / `import x from`: the same shape, marked as a binding.
86
+ let pendingImport = null;
87
+ let importing = false;
88
+ // The next identifier is a declaration of its own name (`function foo`).
89
+ let declareNext = false;
90
+ const flush = (names, field) => {
91
+ for (const name of names ?? [])
92
+ touch(name)[field] += 1;
93
+ };
94
+ for (;;) {
95
+ const kind = scanner.scan();
96
+ if (kind === ts_morph_1.ts.SyntaxKind.EndOfFileToken)
97
+ break;
98
+ if (kind === ts_morph_1.ts.SyntaxKind.OpenBraceToken) {
99
+ depth += 1;
100
+ if (pendingState === "after-export") {
101
+ pendingExport = [];
102
+ pendingState = "in-list";
103
+ }
104
+ else if (pendingState !== "in-list") {
105
+ flush(pendingExport, "exported");
106
+ pendingExport = null;
107
+ pendingState = "idle";
108
+ flush(pendingImport, "imported");
109
+ pendingImport = null;
110
+ importing = false;
111
+ }
112
+ previous = kind;
113
+ continue;
114
+ }
115
+ if (kind === ts_morph_1.ts.SyntaxKind.CloseBraceToken) {
116
+ depth -= 1;
117
+ if (pendingState === "in-list")
118
+ pendingState = "after-close";
119
+ previous = kind;
120
+ continue;
121
+ }
122
+ if (kind === ts_morph_1.ts.SyntaxKind.ExportKeyword) {
123
+ flush(pendingExport, "exported");
124
+ pendingExport = null;
125
+ pendingState = "after-export";
126
+ declareNext = false;
127
+ previous = kind;
128
+ continue;
129
+ }
130
+ if (kind === ts_morph_1.ts.SyntaxKind.ImportKeyword) {
131
+ importing = true;
132
+ pendingImport = null;
133
+ previous = kind;
134
+ continue;
135
+ }
136
+ if (kind === ts_morph_1.ts.SyntaxKind.FromKeyword) {
137
+ flush(pendingExport, "exported");
138
+ pendingExport = null;
139
+ pendingState = "idle";
140
+ flush(pendingImport, "imported");
141
+ pendingImport = null;
142
+ importing = false;
143
+ previous = kind;
144
+ continue;
145
+ }
146
+ if (kind === ts_morph_1.ts.SyntaxKind.Identifier) {
147
+ const name = scanner.getTokenText();
148
+ const found = touch(name);
149
+ if (declareNext && depth === 0) {
150
+ found.declares = true;
151
+ found.declared += 1;
152
+ declareNext = false;
153
+ }
154
+ else if (pendingState === "in-list") {
155
+ if (pendingExport !== null)
156
+ pendingExport.push(name);
157
+ }
158
+ else if (pendingState === "after-export") {
159
+ // `export const x` / `export default x`: no list, the name is a value.
160
+ pendingState = "idle";
161
+ if (previous === ts_morph_1.ts.SyntaxKind.DotToken || previous === ts_morph_1.ts.SyntaxKind.QuestionDotToken)
162
+ found.member += 1;
163
+ else
164
+ found.plain += 1;
165
+ }
166
+ else if (importing) {
167
+ pendingImport?.push(name);
168
+ found.imported += 1;
169
+ if (pendingImport === null)
170
+ pendingImport = [name];
171
+ }
172
+ else if (previous === ts_morph_1.ts.SyntaxKind.DotToken || previous === ts_morph_1.ts.SyntaxKind.QuestionDotToken) {
173
+ found.member += 1;
174
+ }
175
+ else {
176
+ found.plain += 1;
177
+ }
178
+ previous = kind;
179
+ continue;
180
+ }
181
+ // Anything else ends a list being guessed at (an `as` alias keeps it: the
182
+ // LOCAL name is a binding of the imported one, and the checker names the
183
+ // pair by the one on the left).
184
+ if (kind !== ts_morph_1.ts.SyntaxKind.CommaToken && kind !== ts_morph_1.ts.SyntaxKind.AsKeyword) {
185
+ if (pendingState !== "idle") {
186
+ flush(pendingExport, "exported");
187
+ pendingExport = null;
188
+ pendingState = "idle";
189
+ }
190
+ if (pendingImport !== null || importing) {
191
+ flush(pendingImport, "imported");
192
+ pendingImport = null;
193
+ importing = false;
194
+ }
195
+ }
196
+ if (depth === 0 && isDeclKeyword(kind))
197
+ declareNext = true;
198
+ else if (kind !== ts_morph_1.ts.SyntaxKind.DefaultKeyword)
199
+ declareNext = false;
200
+ previous = kind;
201
+ }
202
+ flush(pendingExport, "exported");
203
+ flush(pendingImport, "imported");
204
+ };
205
+ // Build the index for the files this run can see. Called once, before any file is
206
+ // read: an answer about a name is a statement about every file, so a partial
207
+ // index would answer with a part of the truth.
208
+ const primeUsageIndex = (repoRoot, repoFiles) => {
209
+ const into = new Map();
210
+ for (const rel of repoFiles) {
211
+ let text;
212
+ try {
213
+ text = fs.readFileSync(path.join(repoRoot, rel), "utf8");
214
+ }
215
+ catch {
216
+ continue;
217
+ }
218
+ scanInto(into, rel, text);
219
+ }
220
+ index = into;
221
+ };
222
+ exports.primeUsageIndex = primeUsageIndex;
223
+ // A member of an object or a shape is named after the property; a value, a
224
+ // function, a class or a type is named after the binding. The two are counted from
225
+ // different occurrences, which is what keeps `a.foo` from reading as a use of `foo`.
226
+ const isMemberKind = (kindName) => kindName === "PropertyDeclaration" ||
227
+ kindName === "MethodDeclaration" ||
228
+ kindName === "PropertySignature" ||
229
+ kindName === "MethodSignature" ||
230
+ kindName === "EnumMember" ||
231
+ kindName === "GetAccessor" ||
232
+ kindName === "SetAccessor";
233
+ // How many uses of the name one file's part counts, given the role the
234
+ // declaration plays (a member is counted from its occurrences after a dot).
235
+ const tally = (member, found) => member ? found.member : found.plain + found.imported + found.exported;
236
+ // The name's parts in every file but the declaring one: `outside` counts the
237
+ // occurrences, `where` the files that mention it, `used` the files that would
238
+ // break without it. A file that owns the name is skipped — its occurrences are
239
+ // its own declaration, not a use.
240
+ const sumParts = (files, rel, member) => {
241
+ const sums = emptySums();
242
+ for (const [file, found] of files) {
243
+ if (file !== rel && found.declares)
244
+ continue;
245
+ const n = tally(member, found);
246
+ sums.total += n;
247
+ if (file === rel)
248
+ continue;
249
+ sums.outside += n;
250
+ if (n > 0)
251
+ sums.where.push(file);
252
+ if (isUse(member, found))
253
+ sums.used.push(file);
254
+ }
255
+ return sums;
256
+ };
257
+ // Whether a file's occurrences are USES rather than a republish or a member of
258
+ // another object: `usedIn` counts places that would break if the name went away.
259
+ const isUse = (member, found) => member ? found.member > found.exported : found.plain + found.imported > 0;
260
+ // The answer for one name, in the shape `usageFact` returns. `null` where the
261
+ // question does not apply — the same rule as the checker path: only a named,
262
+ // exported piece has a reach beyond itself.
263
+ const usageFromIndex = (name, rel, exported, kindName) => {
264
+ if (index === null || name === null || !exported)
265
+ return null;
266
+ const files = index.get(name);
267
+ if (files === undefined)
268
+ return { total: 0, outside: 0, files: [], usedIn: [] };
269
+ const sums = sumParts(files, rel, isMemberKind(kindName));
270
+ return { total: sums.total, outside: sums.outside, files: sums.where.sort(), usedIn: sums.used.sort() };
271
+ };
272
+ exports.usageFromIndex = usageFromIndex;
@@ -0,0 +1,7 @@
1
+ type UsageMode = "checker" | "index";
2
+ declare const DEFAULT_USAGE: UsageMode;
3
+ declare const usageModeOf: (raw: string | undefined) => UsageMode;
4
+ declare const setUsageMode: (next: UsageMode) => void;
5
+ declare const usageMode: () => UsageMode;
6
+ export { DEFAULT_USAGE, setUsageMode, usageMode, usageModeOf };
7
+ export type { UsageMode };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usageModeOf = exports.usageMode = exports.setUsageMode = exports.DEFAULT_USAGE = void 0;
4
+ const DEFAULT_USAGE = "checker";
5
+ exports.DEFAULT_USAGE = DEFAULT_USAGE;
6
+ let mode = DEFAULT_USAGE;
7
+ // Anything but the exact spelling of `index` keeps the checker: a typo must not
8
+ // silently change what a rule is told about the code.
9
+ const usageModeOf = (raw) => (raw === "index" ? "index" : DEFAULT_USAGE);
10
+ exports.usageModeOf = usageModeOf;
11
+ const setUsageMode = (next) => {
12
+ mode = next;
13
+ };
14
+ exports.setUsageMode = setUsageMode;
15
+ const usageMode = () => mode;
16
+ exports.usageMode = usageMode;
@@ -0,0 +1,19 @@
1
+ import { type Index, type Usage } from "./fa-index";
2
+ import type { RunArgs } from "./index-run";
3
+ import type { Candidate } from "./entities/facts";
4
+ import type { SourceFile } from "ts-morph";
5
+ type UsageArgs = {
6
+ run: RunArgs;
7
+ index: Index;
8
+ zone: ReadonlySet<string>;
9
+ absOf: ReadonlyMap<string, string>;
10
+ };
11
+ type UsageStats = {
12
+ files: number;
13
+ asked: number;
14
+ answered: number;
15
+ };
16
+ declare const usageFor: (sf: SourceFile, candidates: readonly Candidate[], repoRoot: string) => Usage;
17
+ declare const runUsagePass: (args: UsageArgs) => UsageStats;
18
+ export { runUsagePass, usageFor };
19
+ export type { UsageStats };