@astryxdesign/cli 0.7.2-canary.ba6a6e2 → 0.7.2-canary.bd72a5f

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 (294) hide show
  1. package/README.md +74 -73
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/component/_adapter.d.mts +72 -1
  4. package/api/component/_adapter.mjs +209 -7
  5. package/api/component/component.mjs +82 -15
  6. package/api/component/component.test.mjs +80 -0
  7. package/api/component/doc-links.test.mjs +386 -0
  8. package/api/component/integration-export-name.test.mjs +644 -0
  9. package/api/component/list/list.mjs +42 -4
  10. package/api/discover/_adapter.d.mts +119 -12
  11. package/api/discover/_adapter.mjs +449 -10
  12. package/api/discover/_adapter.test.mjs +599 -17
  13. package/api/discover/_catalog-view.d.mts +16 -5
  14. package/api/discover/_catalog-view.mjs +32 -8
  15. package/api/discover/detail/doc/doc.mjs +9 -1
  16. package/api/discover/discover.d.mts +11 -0
  17. package/api/discover/discover.doc.mjs +7 -6
  18. package/api/discover/discover.mjs +107 -19
  19. package/api/discover/discover.type.d.mts +18 -7
  20. package/api/discover/discover.type.mjs +15 -7
  21. package/api/discover/list/list.d.mts +4 -3
  22. package/api/discover/list/list.mjs +17 -10
  23. package/api/docs/_adapter.d.mts +74 -0
  24. package/api/docs/_adapter.mjs +550 -14
  25. package/api/docs/integration-tree.test.mjs +22 -0
  26. package/api/docs/integrationDocs.test.mjs +124 -0
  27. package/api/docs/list/list.mjs +12 -2
  28. package/api/doctor/doctor.mjs +27 -3
  29. package/api/doctor/doctor.test.mjs +43 -0
  30. package/api/doctor/theme-checks.mjs +1 -1
  31. package/api/doctor/theme-checks.test.mjs +136 -0
  32. package/api/gap-report/gap-report.d.mts +3 -0
  33. package/api/gap-report/gap-report.doc.mjs +11 -3
  34. package/api/gap-report/gap-report.mjs +219 -52
  35. package/api/gap-report/gap-report.test.mjs +233 -0
  36. package/api/gap-report/gap-report.type.d.mts +41 -0
  37. package/api/gap-report/gap-report.type.mjs +18 -0
  38. package/api/index.d.mts +2 -0
  39. package/api/index.mjs +2 -0
  40. package/api/init/run/run.mjs +2 -2
  41. package/api/integration/_adapter.d.mts +45 -0
  42. package/api/integration/_adapter.mjs +112 -0
  43. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  44. package/api/integration/add-contribution.mjs +8 -4
  45. package/api/integration/add-contribution.test.mjs +4 -2
  46. package/api/integration/authoring-checks.mjs +108 -4
  47. package/api/integration/authoring-checks.test.mjs +808 -0
  48. package/api/integration/authoring-checks.type.d.mts +143 -0
  49. package/api/integration/authoring-checks.type.mjs +74 -2
  50. package/api/integration/check/check.d.mts +96 -0
  51. package/api/integration/check/check.mjs +357 -0
  52. package/api/integration/check/check.test.mjs +489 -0
  53. package/api/integration/integration-check.type.d.mts +118 -0
  54. package/api/integration/integration-check.type.mjs +84 -0
  55. package/api/integration/integrationCheck.doc.d.mts +10 -0
  56. package/api/integration/integrationCheck.doc.mjs +73 -0
  57. package/api/integration/integrationComponentConflicts.doc.mjs +45 -6
  58. package/api/integration/integrationDocConflicts.doc.mjs +22 -5
  59. package/api/integration/pack-check.mjs +357 -114
  60. package/api/integration/pack-check.test.mjs +726 -0
  61. package/api/integration/validate-integration-fixes.test.mjs +67 -0
  62. package/api/integration/validate-integration.mjs +36 -3
  63. package/api/integration/validate-integration.test.mjs +88 -8
  64. package/api/integration/validate-integration.type.d.mts +8 -0
  65. package/api/integration/validate-integration.type.mjs +12 -1
  66. package/api/integration/validateIntegration.doc.mjs +19 -3
  67. package/api/search/search.d.mts +81 -12
  68. package/api/search/search.domain-priority.test.mjs +108 -18
  69. package/api/search/search.integration-check.test.mjs +24 -0
  70. package/api/search/search.mjs +611 -54
  71. package/api/search/search.test.mjs +175 -0
  72. package/api/swizzle/copy/copy.mjs +28 -14
  73. package/api/theme/build/build.family.test.mjs +64 -0
  74. package/api/theme/build/build.mjs +180 -24
  75. package/api/theme/themeBuild.doc.mjs +4 -4
  76. package/api/upgrade/_adapter.d.mts +40 -2
  77. package/api/upgrade/_adapter.mjs +117 -4
  78. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  79. package/api/upgrade/run/run.mjs +30 -1
  80. package/api/upgrade/status/status.d.mts +21 -5
  81. package/api/upgrade/status/status.mjs +45 -8
  82. package/api/upgrade/upgrade.doc.mjs +5 -3
  83. package/api/upgrade/upgrade.type.d.mts +23 -0
  84. package/api/upgrade/upgrade.type.mjs +16 -1
  85. package/assets/codemods/runner.mjs +7 -1
  86. package/assets/discover/official-packages.json +367 -0
  87. package/assets/docs/README.md +10 -0
  88. package/assets/docs/author-a-theme.doc.mjs +3 -3
  89. package/assets/docs/browser-support.doc.mjs +1 -1
  90. package/assets/docs/getting-started.doc.mjs +3 -3
  91. package/assets/docs/styling-overview.doc.mjs +1 -1
  92. package/assets/docs/theme.doc.dense.mjs +1 -1
  93. package/assets/docs/theme.doc.mjs +2 -2
  94. package/assets/docs/theme.doc.zh.mjs +1 -1
  95. package/assets/docs/tree/add-a-component.doc.mjs +11 -1
  96. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  97. package/assets/docs/tree/add-a-topic.doc.mjs +11 -8
  98. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  99. package/assets/docs/tree/block-template.doc.mjs +8 -20
  100. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  101. package/assets/docs/tree/check-the-props.doc.mjs +201 -0
  102. package/assets/docs/tree/check-your-docs.doc.mjs +65 -7
  103. package/assets/docs/tree/checks.doc.mjs +26 -18
  104. package/assets/docs/tree/codemods.doc.mjs +4 -4
  105. package/assets/docs/tree/component-family.doc.mjs +8 -6
  106. package/assets/docs/tree/component-imports.doc.mjs +10 -2
  107. package/assets/docs/tree/components.doc.mjs +1 -1
  108. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +30 -21
  109. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  110. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  111. package/assets/docs/tree/docs.doc.mjs +3 -3
  112. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  113. package/assets/docs/tree/document-the-theme.doc.mjs +3 -3
  114. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  115. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  116. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  117. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  118. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  119. package/assets/docs/tree/integrations.doc.mjs +8 -0
  120. package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
  121. package/assets/docs/tree/layout.doc.mjs +6 -6
  122. package/assets/docs/tree/links.doc.mjs +6 -5
  123. package/assets/docs/tree/migration-setup.doc.mjs +3 -2
  124. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  125. package/assets/docs/tree/migration.doc.mjs +0 -1
  126. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  127. package/assets/docs/tree/page-template.doc.mjs +4 -8
  128. package/assets/docs/tree/publishing.doc.mjs +4 -4
  129. package/assets/docs/tree/quick-start.doc.mjs +38 -22
  130. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  131. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  132. package/assets/docs/tree/sections-and-placement.doc.mjs +6 -8
  133. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  134. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  135. package/assets/docs/tree/single-component.doc.mjs +15 -6
  136. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  137. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  138. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  139. package/assets/docs/tree/template-doc-overview.doc.mjs +5 -16
  140. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  141. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  142. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  143. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  144. package/assets/docs/tree/templates.doc.mjs +1 -1
  145. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  146. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  147. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  148. package/assets/docs/tree/troubleshooting.doc.mjs +16 -8
  149. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  150. package/assets/docs/tree/upgrading.doc.mjs +4 -4
  151. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  152. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  153. package/assets/docs/tree/versioning.doc.mjs +7 -6
  154. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  155. package/assets/docs/use-a-theme.doc.mjs +2 -2
  156. package/assets/docs/working-with-ai.doc.mjs +43 -4
  157. package/assets/theme.template.ts +1 -1
  158. package/authoring/codemod/codemod.doc.mjs +7 -3
  159. package/authoring/config/config.doc.mjs +9 -6
  160. package/authoring/config/type.ts +4 -2
  161. package/authoring/discover/discover.doc.mjs +1 -1
  162. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  163. package/authoring/doctypes/command/command.doc.mjs +14 -12
  164. package/authoring/doctypes/component/component.doc.mjs +30 -27
  165. package/authoring/doctypes/component/type.ts +21 -8
  166. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  167. package/authoring/doctypes/function/function.doc.mjs +9 -8
  168. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  169. package/authoring/doctypes/hook/type.ts +4 -0
  170. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  171. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  172. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  173. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  174. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  175. package/authoring/doctypes/template/parse.d.mts +6 -2
  176. package/authoring/doctypes/template/parse.mjs +3 -1
  177. package/authoring/doctypes/template/template.doc.mjs +3 -3
  178. package/authoring/doctypes/template/type.ts +22 -0
  179. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  180. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  181. package/authoring/identity/identity.doc.mjs +3 -3
  182. package/authoring/index.d.ts +1 -0
  183. package/authoring/integration/integration.doc.mjs +12 -4
  184. package/authoring/integration/parse.test.mjs +10 -0
  185. package/authoring/integration/schema.d.mts +2 -0
  186. package/authoring/integration/schema.mjs +1 -0
  187. package/authoring/integration/type.ts +4 -0
  188. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  189. package/clients/cli/commands/build-theme.mjs +1 -1
  190. package/clients/cli/commands/build-theme.path-safety.test.mjs +224 -6
  191. package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
  192. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  193. package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
  194. package/clients/cli/commands/discover.doc.mjs +1 -1
  195. package/clients/cli/commands/discover.mjs +144 -93
  196. package/clients/cli/commands/discover.no-source.test.mjs +447 -33
  197. package/clients/cli/commands/discover.sources.test.mjs +20 -1
  198. package/clients/cli/commands/doctor-integration-components.doc.mjs +18 -4
  199. package/clients/cli/commands/doctor-integration-docs.doc.mjs +19 -5
  200. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  201. package/clients/cli/commands/doctor-integration.test.mjs +884 -0
  202. package/clients/cli/commands/doctor.mjs +281 -5
  203. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  204. package/clients/cli/commands/gap-report.mjs +24 -2
  205. package/clients/cli/commands/gap-report.test.mjs +79 -0
  206. package/clients/cli/commands/integration-authoring.test.mjs +46 -0
  207. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  208. package/clients/cli/commands/integration-check.test.mjs +411 -0
  209. package/clients/cli/commands/integration.doc.mjs +6 -2
  210. package/clients/cli/commands/integration.mjs +116 -5
  211. package/clients/cli/commands/json-contract.test.mjs +5 -1
  212. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  213. package/clients/cli/commands/swizzle.mjs +5 -3
  214. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  215. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  216. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  217. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  218. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  219. package/clients/cli/index.mjs +30 -5
  220. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  221. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  222. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  223. package/foundation/agent-docs/agent-docs.mjs +8 -6
  224. package/foundation/config/project.mjs +82 -0
  225. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  226. package/foundation/discovery/component-discovery.d.mts +190 -10
  227. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  228. package/foundation/discovery/component-discovery.mjs +864 -56
  229. package/foundation/discovery/component-discovery.test.mjs +96 -0
  230. package/foundation/discovery/component-replacement.mjs +18 -0
  231. package/foundation/discovery/component-replacement.test.mjs +40 -0
  232. package/foundation/discovery/copied-passages.d.mts +216 -0
  233. package/foundation/discovery/copied-passages.mjs +720 -0
  234. package/foundation/discovery/copied-passages.test.mjs +124 -0
  235. package/foundation/discovery/doc-consistency.d.mts +34 -0
  236. package/foundation/discovery/doc-consistency.mjs +513 -0
  237. package/foundation/discovery/doc-consistency.test.mjs +347 -0
  238. package/foundation/discovery/doc-fluff.d.mts +112 -0
  239. package/foundation/discovery/doc-fluff.mjs +328 -0
  240. package/foundation/discovery/doc-fluff.test.mjs +142 -0
  241. package/foundation/discovery/doc-types.d.mts +157 -0
  242. package/foundation/discovery/doc-types.mjs +1231 -0
  243. package/foundation/discovery/doc-types.test.mjs +744 -0
  244. package/foundation/discovery/docs-discovery.d.mts +88 -0
  245. package/foundation/discovery/docs-discovery.mjs +83 -2
  246. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  247. package/foundation/discovery/integration-doc-files.mjs +231 -0
  248. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  249. package/foundation/discovery/module-exports.d.mts +27 -0
  250. package/foundation/discovery/module-exports.mjs +356 -31
  251. package/foundation/discovery/module-exports.test.mjs +172 -0
  252. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  253. package/foundation/discovery/package-tsconfig.mjs +228 -0
  254. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  255. package/foundation/discovery/project-typescript.d.mts +32 -0
  256. package/foundation/discovery/project-typescript.mjs +89 -0
  257. package/foundation/discovery/prop-drift.d.mts +297 -0
  258. package/foundation/discovery/prop-drift.mjs +2428 -0
  259. package/foundation/discovery/prop-drift.test.mjs +2337 -0
  260. package/foundation/discovery/stray-pointers.d.mts +52 -0
  261. package/foundation/discovery/stray-pointers.mjs +293 -0
  262. package/foundation/discovery/stray-pointers.test.mjs +86 -0
  263. package/foundation/discovery/type-match.d.mts +53 -0
  264. package/foundation/discovery/type-match.mjs +660 -0
  265. package/foundation/discovery/type-match.test.mjs +169 -0
  266. package/foundation/discovery/type-text.d.mts +68 -0
  267. package/foundation/discovery/type-text.mjs +658 -0
  268. package/foundation/discovery/type-text.test.mjs +196 -0
  269. package/foundation/discovery/unresolved-references.d.mts +62 -0
  270. package/foundation/discovery/unresolved-references.mjs +790 -0
  271. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  272. package/foundation/doc-compiler/doc-loads.test.mjs +30 -0
  273. package/foundation/doc-compiler/inputs.mjs +23 -0
  274. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  275. package/foundation/doc-compiler/links.d.mts +41 -5
  276. package/foundation/doc-compiler/links.mjs +167 -28
  277. package/foundation/doc-compiler/links.test.mjs +97 -4
  278. package/foundation/doc-compiler/tree.mjs +30 -1
  279. package/foundation/doc-compiler/tree.test.mjs +7 -0
  280. package/foundation/env/package-manager.d.mts +32 -0
  281. package/foundation/env/package-manager.mjs +47 -0
  282. package/foundation/env/package-manager.test.mjs +194 -7
  283. package/foundation/fs/module-loader.d.mts +2 -1
  284. package/foundation/fs/module-loader.mjs +60 -4
  285. package/foundation/fs/module-loader.test.mjs +194 -0
  286. package/foundation/integrations/contribution-inventory.d.mts +11 -0
  287. package/foundation/integrations/contribution-inventory.mjs +56 -3
  288. package/foundation/integrations/issue.ts +6 -0
  289. package/foundation/integrations/validate-contributions.mjs +30 -1
  290. package/foundation/response/response-types.doc.mjs +15 -9
  291. package/foundation/xle/registry.mjs +4 -0
  292. package/foundation/xle/registry.test.mjs +28 -0
  293. package/package.json +11 -11
  294. package/scripts/postinstall.mjs +3 -3
@@ -0,0 +1,52 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * The strings of a doc the CLI resolves links in (spec:AST-047 FR9). In a
6
+ * topic: its description and summary, then the text of prose and heading
7
+ * blocks, list items, and table cells in each section's content, with the
8
+ * section's title. In a component doc (any doc with no sections): every text
9
+ * field, such as its description, usage, best practices, and each prop's and
10
+ * example's description, with the field's path. Code is never read.
11
+ *
12
+ * @param {unknown} doc an authored doc object
13
+ * @returns {{text: string, section: string | null, field: string | null}[]}
14
+ */
15
+ export function linkableStrings(doc: unknown): {
16
+ text: string;
17
+ section: string | null;
18
+ field: string | null;
19
+ }[];
20
+ /**
21
+ * Every pointer span in one prose string, in order.
22
+ * @param {string} text
23
+ * @returns {string[]} the doc name each one points at
24
+ */
25
+ export function pointersIn(text: string): string[];
26
+ /**
27
+ * Each stray pointer in a package's topics and component docs.
28
+ *
29
+ * @param {{records: {name: string, path: string}[], guides?: {name: string, ref?: {topicFile?: string}}[], namespaces?: {doc?: {name?: string}}[], components?: {name: string, file: string}[]}} discovered
30
+ * @returns {Promise<import('../../api/integration/authoring-checks.type.mjs').StrayPointer[]>}
31
+ */
32
+ export function findStrayPointers(discovered: {
33
+ records: {
34
+ name: string;
35
+ path: string;
36
+ }[];
37
+ guides?: {
38
+ name: string;
39
+ ref?: {
40
+ topicFile?: string;
41
+ };
42
+ }[];
43
+ namespaces?: {
44
+ doc?: {
45
+ name?: string;
46
+ };
47
+ }[];
48
+ components?: {
49
+ name: string;
50
+ file: string;
51
+ }[];
52
+ }): Promise<import("../../api/integration/authoring-checks.type.mjs").StrayPointer[]>;
@@ -0,0 +1,293 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Stray doc pointers (architecture:cli-surface DEC-8): a code span in
5
+ * prose that is exactly `astryx docs <name>` for a doc that exists. The doc's
6
+ * `{@link}` prints the command that opens the doc and is checked by doctor's
7
+ * link check, so a written command is a pointer nothing checks.
8
+ *
9
+ * @input the docs a package ships, as discoverIntegrationDocs returns them
10
+ * @output each stray pointer, with the link that replaces it
11
+ * @position foundation/discovery, called through api/integration/_adapter.mjs
12
+ */
13
+
14
+ import fs from 'node:fs';
15
+
16
+ import {textFields} from '../doc-compiler/links.mjs';
17
+ import {builtinGuideFiles} from './docs-discovery.mjs';
18
+ import {
19
+ fileWords,
20
+ lineAtOffset,
21
+ loadQuietly,
22
+ locateWords,
23
+ textWords,
24
+ } from './copied-passages.mjs';
25
+
26
+ /**
27
+ * A code span that is exactly the command opening one doc. A command with
28
+ * more words, a flag, or a route is a walkthrough, not a pointer. A name holds
29
+ * what a topic name may (letters, digits, `_` and `-`), never opening with `-`.
30
+ */
31
+ const POINTER = /`astryx docs ([A-Za-z0-9_][A-Za-z0-9_-]*)`/g;
32
+
33
+ /** @type {Promise<Map<string, string>> | undefined} */
34
+ let coreKinds;
35
+
36
+ /**
37
+ * The CLI's own docs by name, each with the kind a link names it by: a
38
+ * namespace doc as `namespace`, a topic or guide as `generic`.
39
+ * @returns {Promise<Map<string, string>>}
40
+ */
41
+ function loadCoreKinds() {
42
+ coreKinds ??= (async () => {
43
+ const kinds = new Map();
44
+ for (const file of builtinGuideFiles()) {
45
+ const doc = await loadQuietly(file);
46
+ if (typeof doc?.name === 'string') {
47
+ kinds.set(doc.name, doc.type === 'namespace' ? 'namespace' : 'generic');
48
+ }
49
+ }
50
+ return kinds;
51
+ })();
52
+ return coreKinds;
53
+ }
54
+
55
+ /**
56
+ * The strings of a doc the CLI resolves links in (spec:AST-047 FR9). In a
57
+ * topic: its description and summary, then the text of prose and heading
58
+ * blocks, list items, and table cells in each section's content, with the
59
+ * section's title. In a component doc (any doc with no sections): every text
60
+ * field, such as its description, usage, best practices, and each prop's and
61
+ * example's description, with the field's path. Code is never read.
62
+ *
63
+ * @param {unknown} doc an authored doc object
64
+ * @returns {{text: string, section: string | null, field: string | null}[]}
65
+ */
66
+ export function linkableStrings(doc) {
67
+ /** @type {{text: string, section: string | null, field: string | null}[]} */
68
+ const strings = [];
69
+ if (doc == null || typeof doc !== 'object') return strings;
70
+ const top = /** @type {Record<string, any>} */ (doc);
71
+ if (!Array.isArray(top.sections)) {
72
+ for (const {field, text} of textFields(doc)) {
73
+ strings.push({text, section: null, field});
74
+ }
75
+ return strings;
76
+ }
77
+ for (const field of ['description', 'summary']) {
78
+ if (typeof top[field] === 'string') {
79
+ strings.push({text: top[field], section: null, field});
80
+ }
81
+ }
82
+ /**
83
+ * @param {unknown} value
84
+ * @param {string | null} section
85
+ */
86
+ const walk = (value, section) => {
87
+ if (Array.isArray(value)) {
88
+ for (const item of value) walk(item, section);
89
+ return;
90
+ }
91
+ if (value == null || typeof value !== 'object') return;
92
+ const record = /** @type {Record<string, any>} */ (value);
93
+ const title = typeof record.title === 'string' ? record.title : section;
94
+ if (Array.isArray(record.sections)) walk(record.sections, section);
95
+ if (!Array.isArray(record.content)) return;
96
+ for (const block of record.content) {
97
+ const add = (/** @type {unknown} */ text) => {
98
+ if (typeof text === 'string') {
99
+ strings.push({text, section: title, field: null});
100
+ }
101
+ };
102
+ switch (block?.type) {
103
+ case 'prose':
104
+ case 'heading':
105
+ add(block.text);
106
+ break;
107
+ case 'list':
108
+ (block.items ?? []).forEach(add);
109
+ break;
110
+ case 'table':
111
+ (block.headers ?? []).forEach(add);
112
+ for (const row of block.rows ?? []) row.forEach(add);
113
+ break;
114
+ default:
115
+ walk(block, title);
116
+ }
117
+ }
118
+ };
119
+ walk(doc, null);
120
+ return strings;
121
+ }
122
+
123
+ /**
124
+ * Every pointer span in one prose string, in order.
125
+ * @param {string} text
126
+ * @returns {string[]} the doc name each one points at
127
+ */
128
+ export function pointersIn(text) {
129
+ return [...text.matchAll(POINTER)].map(match => match[1]);
130
+ }
131
+
132
+ /**
133
+ * Where a string's words start among a file's words, from `from` on. A
134
+ * one-line string the file holds as a quoted literal is found at that
135
+ * literal, so a list item that is only `astryx docs theme` is not placed at a
136
+ * summary or code block that writes the same words.
137
+ *
138
+ * @param {string[]} lines the file's lines
139
+ * @param {{word: string, line: number}[]} file the file's words
140
+ * @param {string} text
141
+ * @param {{word: string}[]} words the string's words
142
+ * @param {number} from
143
+ * @returns {number}
144
+ */
145
+ function locateString(lines, file, text, words, from) {
146
+ /** @type {number[]} */
147
+ const starts = [];
148
+ for (let at = locateWords(file, words); at >= 0;) {
149
+ starts.push(at);
150
+ at = locateWords(file, words, at + 1);
151
+ }
152
+ if (starts.length === 0) return -1;
153
+ const literals = text.includes('\n')
154
+ ? []
155
+ : [`'${text}'`, `"${text}"`, `'${text.replace(/'/g, "\\'")}'`];
156
+ const quoted = starts.filter(at =>
157
+ literals.some(literal => lines[file[at].line - 1]?.includes(literal)),
158
+ );
159
+ const pool = quoted.length > 0 ? quoted : starts;
160
+ return pool.find(at => at >= from) ?? pool[0];
161
+ }
162
+
163
+ /**
164
+ * Each stray pointer in a package's topics and component docs.
165
+ *
166
+ * @param {{records: {name: string, path: string}[], guides?: {name: string, ref?: {topicFile?: string}}[], namespaces?: {doc?: {name?: string}}[], components?: {name: string, file: string}[]}} discovered
167
+ * @returns {Promise<import('../../api/integration/authoring-checks.type.mjs').StrayPointer[]>}
168
+ */
169
+ export async function findStrayPointers(discovered) {
170
+ /** @type {{name: string, file: string | undefined, kind: 'topic' | 'component'}[]} */
171
+ const topics = [
172
+ ...discovered.records.map(record => ({
173
+ name: record.name,
174
+ file: record.path,
175
+ kind: /** @type {const} */ ('topic'),
176
+ })),
177
+ ...(discovered.guides ?? []).map(guide => ({
178
+ name: guide.name,
179
+ file: guide.ref?.topicFile,
180
+ kind: /** @type {const} */ ('topic'),
181
+ })),
182
+ ];
183
+ /** @type {Map<string, string>} */
184
+ const own = new Map(topics.map(topic => [topic.name, 'generic']));
185
+ for (const namespace of discovered.namespaces ?? []) {
186
+ const name = namespace?.doc?.name;
187
+ if (typeof name === 'string' && !own.has(name)) own.set(name, 'namespace');
188
+ }
189
+ for (const component of discovered.components ?? []) {
190
+ topics.push({
191
+ name: component.name,
192
+ file: component.file,
193
+ kind: 'component',
194
+ });
195
+ }
196
+ const core = await loadCoreKinds();
197
+ // A topic that extends another has no route of its own: a link to it names
198
+ // the page it shows on, the topic it extends.
199
+ /** @type {Map<string, string>} */
200
+ const extendsOf = new Map();
201
+ for (const topic of topics) {
202
+ if (!topic.file) continue;
203
+ const doc = /** @type {any} */ (await loadQuietly(topic.file));
204
+ if (typeof doc?.extends === 'string')
205
+ extendsOf.set(topic.name, doc.extends);
206
+ }
207
+ /** @param {string} target */
208
+ const linkFor = target => {
209
+ const page = extendsOf.get(target);
210
+ if (page != null) {
211
+ if (own.has(page) && !extendsOf.has(page)) {
212
+ return `{@link ${own.get(page)}:${page}}`;
213
+ }
214
+ return core.has(page)
215
+ ? `{@link @astryxdesign/cli:${core.get(page)}:${page}}`
216
+ : null;
217
+ }
218
+ return own.has(target)
219
+ ? `{@link ${own.get(target)}:${target}}`
220
+ : core.has(target)
221
+ ? `{@link @astryxdesign/cli:${core.get(target)}:${target}}`
222
+ : null;
223
+ };
224
+ /** @type {import('../../api/integration/authoring-checks.type.mjs').StrayPointer[]} */
225
+ const found = [];
226
+ for (const topic of topics) {
227
+ if (!topic.file) continue;
228
+ const doc = await loadQuietly(topic.file);
229
+ if (!doc) continue;
230
+ /** @type {{word: string, line: number}[]} */
231
+ let source = [];
232
+ /** @type {string[]} */
233
+ let lines = [];
234
+ try {
235
+ const raw = fs.readFileSync(topic.file, 'utf8');
236
+ source = fileWords(raw);
237
+ lines = raw.split('\n');
238
+ } catch {
239
+ // No line numbers; the finding still names the section.
240
+ }
241
+ // A component doc is named by its own name: a family doc by the family.
242
+ const name =
243
+ topic.kind === 'component' && typeof doc.name === 'string'
244
+ ? doc.name
245
+ : topic.name;
246
+ const label =
247
+ topic.kind === 'component' ? `component "${name}"` : `"${name}"`;
248
+ // Each string is found by its whole run of words, from where the last
249
+ // one was found, so two strings that open alike keep their own lines.
250
+ let cursor = 0;
251
+ for (const {text, section, field} of linkableStrings(doc)) {
252
+ const words = textWords(text);
253
+ const index = locateString(lines, source, text, words, cursor);
254
+ if (index >= 0) cursor = index + words.length;
255
+ for (const match of text.matchAll(POINTER)) {
256
+ const target = match[1];
257
+ const link = linkFor(target);
258
+ if (!link) continue;
259
+ const command = `astryx docs ${target}`;
260
+ const line =
261
+ index < 0
262
+ ? null
263
+ : lineAtOffset(
264
+ source,
265
+ index,
266
+ words,
267
+ /** @type {number} */ (match.index) + 1,
268
+ );
269
+ const where = [
270
+ section ? `section "${section}"` : null,
271
+ field ? `field ${field}` : null,
272
+ line == null ? null : `line ${line}`,
273
+ ]
274
+ .filter(Boolean)
275
+ .join(', ');
276
+ found.push({
277
+ topic: name,
278
+ kind: topic.kind,
279
+ section,
280
+ field,
281
+ file: topic.file,
282
+ line,
283
+ pointer: command,
284
+ link,
285
+ message:
286
+ `${label}${where ? ` (${where})` : ''} points at a doc with the written command \`${command}\`. ` +
287
+ `Replace \`${command}\`, code ticks included, with ${link}: the CLI prints the command that opens the doc, and doctor checks the link.`,
288
+ });
289
+ }
290
+ }
291
+ }
292
+ return found;
293
+ }
@@ -0,0 +1,86 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+
5
+ import {linkableStrings, pointersIn} from './stray-pointers.mjs';
6
+
7
+ describe('pointersIn', () => {
8
+ it('finds a code span that is exactly the command opening one doc', () => {
9
+ expect(
10
+ pointersIn(
11
+ 'Read `astryx docs theme`, then `astryx docs layout-spacing`.',
12
+ ),
13
+ ).toEqual(['theme', 'layout-spacing']);
14
+ });
15
+
16
+ it('leaves a walkthrough alone: more words, a flag, or a route', () => {
17
+ expect(
18
+ pointersIn(
19
+ 'Run `astryx docs theme overview`, `astryx docs --json`, `astryx docs cli/integrations`, or `astryx docs`.',
20
+ ),
21
+ ).toEqual([]);
22
+ });
23
+
24
+ it('leaves the bare name and a runner-written command alone', () => {
25
+ expect(
26
+ pointersIn('See astryx docs theme, or `pnpm astryx docs theme`.'),
27
+ ).toEqual([]);
28
+ });
29
+ });
30
+
31
+ describe('linkableStrings', () => {
32
+ it("reads a topic's description and summary, then prose, headings, list items and table cells, not code", () => {
33
+ const strings = linkableStrings({
34
+ name: 'acme',
35
+ description: 'Read `astryx docs theme`.',
36
+ summary: 'In short.',
37
+ sections: [
38
+ {
39
+ title: 'Use it',
40
+ content: [
41
+ {type: 'prose', text: 'prose'},
42
+ {type: 'heading', level: 3, text: 'heading'},
43
+ {type: 'list', style: 'unordered', items: ['item']},
44
+ {type: 'table', headers: ['head'], rows: [['cell']]},
45
+ {type: 'code', lang: 'bash', code: 'astryx docs theme'},
46
+ ],
47
+ },
48
+ ],
49
+ });
50
+ expect(strings).toEqual([
51
+ {text: 'Read `astryx docs theme`.', section: null, field: 'description'},
52
+ {text: 'In short.', section: null, field: 'summary'},
53
+ {text: 'prose', section: 'Use it', field: null},
54
+ {text: 'heading', section: 'Use it', field: null},
55
+ {text: 'item', section: 'Use it', field: null},
56
+ {text: 'head', section: 'Use it', field: null},
57
+ {text: 'cell', section: 'Use it', field: null},
58
+ ]);
59
+ });
60
+
61
+ it("reads a component doc's text fields, not its names, types, defaults, or code", () => {
62
+ const strings = linkableStrings({
63
+ type: 'component',
64
+ name: 'AcmeButton',
65
+ displayName: 'Acme Button',
66
+ usage: {
67
+ description: 'usage',
68
+ bestPractices: [{guidance: true, description: 'practice'}],
69
+ },
70
+ props: [
71
+ {name: 'tone', type: 'string', default: "'a'", description: 'prop'},
72
+ ],
73
+ examples: [{label: 'example', code: 'astryx docs theme'}],
74
+ });
75
+ expect(strings).toEqual([
76
+ {text: 'usage', section: null, field: 'usage.description'},
77
+ {
78
+ text: 'practice',
79
+ section: null,
80
+ field: 'usage.bestPractices[0].description',
81
+ },
82
+ {text: 'prop', section: null, field: 'props[0].description'},
83
+ {text: 'example', section: null, field: 'examples[0].label'},
84
+ ]);
85
+ });
86
+ });
@@ -0,0 +1,53 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * Judge a documented type. A doc may name an alias and spell out what it
6
+ * stands for, as `Name = expansion` or `Name (expansion)` (text that is not a
7
+ * type by itself): both parts are judged, and a mismatch in either is one;
8
+ * with one value after it (`Size = 'md'`, `Size = Size.Md`), or after a
9
+ * keyword, that part may be a default, and only the name is judged.
10
+ * @param {string} docType
11
+ * @param {any[]} codeTypes the prop's type in each member of the props type
12
+ * @param {JudgeContext} ctx
13
+ * @returns {TypeVerdict}
14
+ */
15
+ export function judgeType(docType: string, codeTypes: any[], ctx: JudgeContext): TypeVerdict;
16
+ export type TypeVerdict = "match" | "mismatch" | "not_compared";
17
+ export type JudgeContext = {
18
+ ts: any;
19
+ checker: any;
20
+ /**
21
+ * where names in the documented type resolve (the
22
+ * prop's declaration, else the component's source file)
23
+ */
24
+ location: any;
25
+ /**
26
+ * the prop is optional, so `undefined` is set
27
+ * aside on both sides
28
+ */
29
+ optional: boolean;
30
+ /**
31
+ * whether a source
32
+ * file is one of TypeScript's own libraries
33
+ */
34
+ isDefaultLibrary?: ((file: any) => boolean) | undefined;
35
+ /**
36
+ * the project checks without strict null
37
+ * checks, so the compiler drops `null` and `undefined` from every type and
38
+ * both are set aside on both sides
39
+ */
40
+ nullable?: boolean | undefined;
41
+ /**
42
+ * the project sets
43
+ * `exactOptionalPropertyTypes`: an optional prop takes `undefined` only when
44
+ * its type says so, and the compiler's mark for an absent prop is not a
45
+ * type the prop takes
46
+ */
47
+ exactOptional?: boolean | undefined;
48
+ /**
49
+ * the code's type as the source writes it and
50
+ * as the compiler prints it, each a list of union members
51
+ */
52
+ written: string[][];
53
+ };