@astryxdesign/cli 0.6.3-canary.dea6813 → 0.6.3-canary.df1837b

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 (284) hide show
  1. package/README.md +79 -58
  2. package/api/blog/blog.doc.mjs +1 -0
  3. package/api/build/build.doc.mjs +1 -0
  4. package/api/component/component.doc.mjs +2 -1
  5. package/api/component/component.mjs +3 -3
  6. package/api/component/component.type.d.mts +5 -4
  7. package/api/component/component.type.mjs +5 -4
  8. package/api/component/detail/blocks/blocks.d.mts +2 -1
  9. package/api/component/detail/blocks/blocks.mjs +4 -3
  10. package/api/component/list/list.d.mts +0 -5
  11. package/api/component/list/list.mjs +37 -9
  12. package/api/discover/discover.doc.mjs +1 -0
  13. package/api/docs/_adapter.d.mts +3 -8
  14. package/api/docs/_adapter.mjs +13 -105
  15. package/api/docs/docs.doc.mjs +1 -0
  16. package/api/docs/list/list.mjs +3 -7
  17. package/api/doctor/doctor.d.mts +25 -3
  18. package/api/doctor/doctor.doc.mjs +1 -0
  19. package/api/doctor/doctor.mjs +185 -13
  20. package/api/doctor/doctor.test.mjs +326 -1
  21. package/api/gap-report/gap-report.doc.mjs +1 -0
  22. package/api/hook/_adapter.mjs +19 -5
  23. package/api/hook/hook.doc.mjs +1 -0
  24. package/api/hook/list/list.d.mts +1 -1
  25. package/api/hook/list/list.mjs +69 -17
  26. package/api/init/init.doc.mjs +1 -0
  27. package/api/integration/add-contribution.mjs +7 -7
  28. package/api/integration/add-contribution.test.mjs +37 -3
  29. package/api/integration/add-theme.mjs +34 -64
  30. package/api/integration/add-theme.test.mjs +105 -21
  31. package/api/integration/authoring-checks.test.mjs +8 -4
  32. package/api/integration/integration-block-exports.test.mjs +10 -6
  33. package/api/integration/integrationAdd.doc.mjs +1 -0
  34. package/api/integration/integrationAddAgentDoc.doc.mjs +1 -0
  35. package/api/integration/integrationAddCodemod.doc.mjs +1 -0
  36. package/api/integration/integrationAddComponent.doc.mjs +1 -0
  37. package/api/integration/integrationAddDoc.doc.mjs +1 -0
  38. package/api/integration/integrationAddTemplate.doc.mjs +1 -0
  39. package/api/integration/integrationAddTheme.doc.mjs +6 -5
  40. package/api/integration/integrationComponentConflicts.doc.mjs +1 -0
  41. package/api/integration/integrationDocConflicts.doc.mjs +1 -0
  42. package/api/integration/integrationPackCheck.doc.mjs +1 -0
  43. package/api/integration/integrationTemplateConflicts.doc.mjs +1 -0
  44. package/api/integration/pack-check.test.mjs +17 -47
  45. package/api/integration/summarizeIssues.doc.mjs +1 -0
  46. package/api/integration/validate-integration-fixes.test.mjs +1389 -0
  47. package/api/integration/validate-integration.mjs +50 -102
  48. package/api/integration/validate-integration.test.mjs +85 -23
  49. package/api/integration/validate-unread-theme-folders.test.mjs +110 -0
  50. package/api/integration/validateIntegration.doc.mjs +1 -0
  51. package/api/json/assertResponse.doc.mjs +1 -0
  52. package/api/json/isError.doc.mjs +1 -0
  53. package/api/json/parseResponse.doc.mjs +1 -0
  54. package/api/layout/layoutCheck.doc.mjs +1 -0
  55. package/api/layout/layoutExpand.doc.mjs +1 -0
  56. package/api/layout/layoutGrammar.doc.mjs +1 -0
  57. package/api/search/search.doc.mjs +1 -0
  58. package/api/search/search.mjs +16 -6
  59. package/api/swizzle/swizzle.doc.mjs +1 -0
  60. package/api/template/template-suffix.test.mjs +41 -21
  61. package/api/template/template.doc.mjs +1 -0
  62. package/api/theme/_adapter.d.mts +2 -3
  63. package/api/theme/_adapter.mjs +4 -5
  64. package/api/theme/add/add.binary.test.mjs +10 -17
  65. package/api/theme/add/add.test.mjs +14 -1
  66. package/api/theme/generateTonalPalette.doc.mjs +1 -0
  67. package/api/theme/integration-themes.test.mjs +39 -28
  68. package/api/theme/list/list.test.mjs +19 -20
  69. package/api/theme/listThemes.doc.mjs +6 -5
  70. package/api/theme/themeAdd.doc.mjs +4 -3
  71. package/api/theme/themeBuild.doc.mjs +1 -0
  72. package/api/theme/themeList.doc.mjs +6 -3
  73. package/api/theme/themeListAvailable.doc.mjs +5 -3
  74. package/api/theme/themePaletteGenerate.doc.mjs +1 -0
  75. package/api/theme/themeTargets.doc.mjs +1 -0
  76. package/api/theme/themeTemplate.doc.mjs +1 -0
  77. package/api/upgrade/_adapter.d.mts +32 -5
  78. package/api/upgrade/_adapter.mjs +97 -69
  79. package/api/upgrade/provider-agreement.test.mjs +152 -0
  80. package/api/upgrade/run/run.mjs +356 -59
  81. package/api/upgrade/upgrade.doc.mjs +6 -1
  82. package/api/upgrade/upgrade.type.d.mts +34 -0
  83. package/api/upgrade/upgrade.type.mjs +15 -0
  84. package/assets/codemods/__tests__/runner.test.mjs +330 -8
  85. package/assets/codemods/integration-discovery.mjs +8 -2
  86. package/assets/codemods/integration-discovery.test.mjs +15 -0
  87. package/assets/codemods/integration-runner.mjs +56 -4
  88. package/assets/codemods/integration-runner.protection.test.mjs +153 -0
  89. package/assets/codemods/run-codemod.mjs +177 -34
  90. package/assets/codemods/runner.mjs +350 -102
  91. package/assets/codemods/transform-prop.mjs +109 -0
  92. package/assets/codemods/transform-prop.test.mjs +95 -0
  93. package/assets/codemods/transforms/next/__tests__/migrate-native-picker-to-presentation.test.mjs +63 -0
  94. package/assets/codemods/transforms/next/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +220 -0
  95. package/assets/codemods/transforms/next/index.mjs +19 -1
  96. package/assets/codemods/transforms/next/migrate-native-picker-to-presentation.mjs +148 -0
  97. package/assets/codemods/transforms/next/migrate-theme-catalog-to-descriptors.mjs +141 -0
  98. package/assets/codemods/transforms/v0.0.14/__tests__/rename-status-variants.test.mjs +86 -165
  99. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +72 -210
  100. package/assets/codemods/transforms/v0.1.8/__tests__/rename-avatar-size-scale.test.mjs +83 -115
  101. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +57 -186
  102. package/assets/docs/cli-integrations.doc.mjs +30 -30
  103. package/assets/docs/cli.doc.mjs +15 -0
  104. package/assets/docs/theme.doc.mjs +1 -1
  105. package/assets/templates/blocks/components/DateInput/DateInputDateRange.tsx +1 -1
  106. package/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs +14 -0
  107. package/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx +100 -0
  108. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaInlineRail.doc.mjs +14 -0
  109. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaInlineRail.tsx +61 -0
  110. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaOverscrollChaining.doc.mjs +14 -0
  111. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaOverscrollChaining.tsx +126 -0
  112. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaShowcase.doc.mjs +15 -0
  113. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaShowcase.tsx +86 -0
  114. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaStickyGroupHeaders.doc.mjs +14 -0
  115. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaStickyGroupHeaders.tsx +99 -0
  116. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaStickyPassthrough.doc.mjs +14 -0
  117. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaStickyPassthrough.tsx +122 -0
  118. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaTwoAxisBoard.doc.mjs +14 -0
  119. package/assets/templates/blocks/components/ScrollableArea/ScrollableAreaTwoAxisBoard.tsx +95 -0
  120. package/assets/templates/blocks/components/TimeInput/TimeInputConstrained.tsx +1 -0
  121. package/assets/templates/themes/butter/butterTheme.doc.mjs +11 -0
  122. package/assets/templates/themes/chocolate/chocolateTheme.doc.mjs +11 -0
  123. package/assets/templates/themes/gothic/gothicTheme.doc.mjs +11 -0
  124. package/assets/templates/themes/matcha/matchaTheme.doc.mjs +11 -0
  125. package/assets/templates/themes/neutral/neutralTheme.doc.mjs +11 -0
  126. package/assets/templates/themes/stone/stoneTheme.doc.mjs +11 -0
  127. package/assets/templates/themes/y2k/y2kTheme.doc.mjs +11 -0
  128. package/authoring/codemod/codemod.doc.mjs +1 -1
  129. package/authoring/codemod/type.ts +12 -0
  130. package/authoring/config/config.doc.mjs +1 -1
  131. package/authoring/debug/debug.doc.d.mts +11 -0
  132. package/authoring/debug/debug.doc.mjs +182 -0
  133. package/authoring/doctypes/base/graph-fields.doc.mjs +1 -1
  134. package/authoring/doctypes/command/command.doc.mjs +1 -1
  135. package/authoring/doctypes/command/type.ts +1 -1
  136. package/authoring/doctypes/component/type.ts +2 -2
  137. package/authoring/doctypes/doctypes-new.test.mjs +48 -6
  138. package/authoring/doctypes/enum/enum.doc.mjs +1 -1
  139. package/authoring/doctypes/enum/type.ts +1 -1
  140. package/authoring/doctypes/function/function.doc.mjs +1 -1
  141. package/authoring/doctypes/function/type.ts +1 -1
  142. package/authoring/doctypes/hook/type.ts +2 -2
  143. package/authoring/doctypes/load-contract.test.mjs +2 -1
  144. package/authoring/doctypes/parse.d.mts +4 -2
  145. package/authoring/doctypes/parse.mjs +7 -3
  146. package/authoring/doctypes/reference/reference.doc.mjs +1 -1
  147. package/authoring/doctypes/reference/type.ts +2 -2
  148. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  149. package/authoring/doctypes/schema/type.ts +1 -2
  150. package/authoring/doctypes/template/template.doc.mjs +3 -3
  151. package/authoring/doctypes/theme/parse.d.mts +35 -0
  152. package/authoring/doctypes/theme/parse.mjs +76 -0
  153. package/authoring/doctypes/theme/theme.doc.d.mts +9 -0
  154. package/authoring/doctypes/theme/theme.doc.mjs +79 -0
  155. package/authoring/doctypes/theme/type.ts +42 -0
  156. package/authoring/doctypes/types.ts +2 -1
  157. package/authoring/gap-report/gap-report.doc.d.mts +12 -0
  158. package/authoring/gap-report/gap-report.doc.mjs +183 -0
  159. package/authoring/index.d.mts +1 -0
  160. package/authoring/index.d.ts +6 -4
  161. package/authoring/index.mjs +2 -1
  162. package/authoring/integration/integration.doc.mjs +2 -2
  163. package/authoring/integration/type.ts +3 -9
  164. package/clients/cli/__tests__/cliManifest.test.ts +27 -29
  165. package/clients/cli/commands/blog.doc.mjs +1 -1
  166. package/clients/cli/commands/build.doc.mjs +1 -1
  167. package/clients/cli/commands/component-package.test.mjs +28 -0
  168. package/clients/cli/commands/component.doc.mjs +1 -1
  169. package/clients/cli/commands/discover.doc.mjs +1 -1
  170. package/clients/cli/commands/docs.doc.mjs +1 -1
  171. package/clients/cli/commands/doctor-integration-components.doc.mjs +1 -1
  172. package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
  173. package/clients/cli/commands/doctor-integration-templates.doc.mjs +1 -1
  174. package/clients/cli/commands/doctor-integration-validate.doc.mjs +1 -1
  175. package/clients/cli/commands/doctor-integration.doc.mjs +1 -1
  176. package/clients/cli/commands/doctor-integration.test.mjs +15 -7
  177. package/clients/cli/commands/doctor.doc.mjs +1 -1
  178. package/clients/cli/commands/gap-report.doc.mjs +1 -1
  179. package/clients/cli/commands/hook.doc.mjs +1 -1
  180. package/clients/cli/commands/init.doc.mjs +1 -1
  181. package/clients/cli/commands/integration-add.controls.test.mjs +1 -1
  182. package/clients/cli/commands/integration-add.doc.mjs +1 -1
  183. package/clients/cli/commands/integration-pack.doc.mjs +1 -1
  184. package/clients/cli/commands/integration-real-world.test.mjs +3 -9
  185. package/clients/cli/commands/integration.doc.mjs +1 -1
  186. package/clients/cli/commands/layout-check.doc.mjs +1 -1
  187. package/clients/cli/commands/layout-expand.doc.mjs +1 -1
  188. package/clients/cli/commands/layout-grammar.doc.mjs +1 -1
  189. package/clients/cli/commands/layout.doc.mjs +1 -1
  190. package/clients/cli/commands/manifest.doc.mjs +1 -1
  191. package/clients/cli/commands/search.doc.mjs +1 -1
  192. package/clients/cli/commands/swizzle.doc.mjs +1 -1
  193. package/clients/cli/commands/template.doc.mjs +1 -1
  194. package/clients/cli/commands/theme-add.doc.mjs +2 -2
  195. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  196. package/clients/cli/commands/theme-list.doc.mjs +2 -2
  197. package/clients/cli/commands/theme-palette-generate.doc.mjs +3 -3
  198. package/clients/cli/commands/theme-palette.doc.mjs +1 -1
  199. package/clients/cli/commands/theme-targets.doc.mjs +1 -1
  200. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  201. package/clients/cli/commands/theme.doc.mjs +1 -1
  202. package/clients/cli/commands/upgrade.doc.mjs +3 -2
  203. package/clients/cli/commands/upgrade.file-protection.test.mjs +228 -0
  204. package/clients/cli/commands/upgrade.mjs +3 -0
  205. package/clients/cli/lib/hook-format.mjs +14 -5
  206. package/foundation/config/project-themes.test.mjs +11 -19
  207. package/foundation/config/project.d.mts +8 -0
  208. package/foundation/config/project.mjs +50 -21
  209. package/foundation/config/project.test.mjs +3 -16
  210. package/foundation/discovery/authoring-self-docs.d.mts +6 -0
  211. package/foundation/discovery/authoring-self-docs.mjs +17 -7
  212. package/foundation/discovery/authoring-surface.d.mts +74 -0
  213. package/foundation/discovery/authoring-surface.mjs +525 -0
  214. package/foundation/discovery/authoring-surface.test.mjs +392 -0
  215. package/foundation/discovery/cli-self-docs.d.mts +113 -0
  216. package/foundation/discovery/cli-self-docs.mjs +514 -0
  217. package/foundation/discovery/cli-self-docs.test.mjs +437 -0
  218. package/foundation/discovery/component-loader.d.mts +35 -38
  219. package/foundation/discovery/component-loader.mjs +53 -222
  220. package/foundation/discovery/docs-discovery.d.mts +3 -2
  221. package/foundation/discovery/docs-discovery.mjs +8 -12
  222. package/foundation/discovery/docs-discovery.test.mjs +8 -5
  223. package/foundation/discovery/template-adapter.d.mts +7 -0
  224. package/foundation/discovery/template-adapter.mjs +27 -40
  225. package/foundation/discovery/template-adapter.test.mjs +15 -0
  226. package/foundation/discovery/theme-discovery.d.mts +67 -7
  227. package/foundation/discovery/theme-discovery.mjs +916 -186
  228. package/foundation/discovery/theme-discovery.test.mjs +613 -219
  229. package/foundation/doc-compiler/bundle.d.mts +47 -0
  230. package/foundation/doc-compiler/bundle.mjs +218 -0
  231. package/foundation/doc-compiler/bundle.test.mjs +255 -0
  232. package/foundation/doc-compiler/compile.d.mts +200 -0
  233. package/foundation/doc-compiler/compile.mjs +254 -5
  234. package/foundation/doc-compiler/diagnostics.d.mts +126 -0
  235. package/foundation/doc-compiler/diagnostics.mjs +277 -0
  236. package/foundation/doc-compiler/doc-compiler.test.mjs +28 -1
  237. package/foundation/doc-compiler/doc-loads.test.mjs +1642 -0
  238. package/foundation/doc-compiler/import.d.mts +24 -0
  239. package/foundation/doc-compiler/import.mjs +59 -0
  240. package/foundation/doc-compiler/inputs.d.mts +102 -0
  241. package/foundation/doc-compiler/inputs.mjs +286 -0
  242. package/foundation/doc-compiler/inputs.test.mjs +299 -0
  243. package/foundation/doc-compiler/ir.d.mts +13 -0
  244. package/foundation/doc-compiler/ir.mjs +189 -12
  245. package/foundation/doc-compiler/lower-doc.test.mjs +492 -0
  246. package/foundation/doc-compiler/overlays.d.mts +37 -0
  247. package/foundation/doc-compiler/overlays.mjs +206 -0
  248. package/foundation/doc-compiler/parse-readable.d.mts +9 -0
  249. package/foundation/doc-compiler/parse-readable.mjs +29 -0
  250. package/foundation/doc-compiler/read.d.mts +126 -0
  251. package/foundation/doc-compiler/read.mjs +320 -0
  252. package/foundation/doc-compiler/read.test.mjs +313 -0
  253. package/foundation/doc-compiler/source.d.mts +33 -0
  254. package/foundation/doc-compiler/source.mjs +128 -0
  255. package/foundation/fs/file-protection.d.mts +33 -0
  256. package/foundation/fs/file-protection.mjs +825 -0
  257. package/foundation/fs/file-protection.test.mjs +250 -0
  258. package/foundation/integrations/autolink.d.mts +58 -1
  259. package/foundation/integrations/autolink.mjs +143 -57
  260. package/foundation/integrations/contribution-fixes.d.mts +145 -0
  261. package/foundation/integrations/contribution-fixes.mjs +1284 -0
  262. package/foundation/integrations/contribution-inventory.d.mts +1 -1
  263. package/foundation/integrations/contribution-inventory.mjs +17 -20
  264. package/foundation/integrations/contribution-inventory.test.mjs +67 -27
  265. package/foundation/integrations/integrations.d.mts +3 -0
  266. package/foundation/integrations/integrations.mjs +11 -97
  267. package/foundation/integrations/provider-ledger.test.mjs +275 -0
  268. package/foundation/integrations/provider-resolution.d.mts +152 -0
  269. package/foundation/integrations/provider-resolution.mjs +576 -0
  270. package/foundation/integrations/provider-resolution.test.mjs +369 -0
  271. package/foundation/integrations/theme-descriptor.d.mts +8 -0
  272. package/foundation/integrations/theme-descriptor.mjs +44 -0
  273. package/foundation/integrations/validate-contributions.mjs +104 -10
  274. package/foundation/response/error-codes.d.mts +3 -1
  275. package/foundation/response/error-codes.d.ts +2 -0
  276. package/foundation/response/error-codes.doc.mjs +12 -2
  277. package/foundation/response/error-codes.mjs +7 -1
  278. package/foundation/response/error-codes.test.mjs +55 -11
  279. package/foundation/response/response-types.doc.mjs +8 -8
  280. package/foundation/response/response-types.doc.test.mjs +158 -0
  281. package/foundation/response/response.doc.mjs +1 -1
  282. package/foundation/text/string-utils.mjs +22 -10
  283. package/package.json +10 -9
  284. package/assets/templates/themes/manifest.json +0 -95
@@ -1,245 +1,76 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file Component doc loader — load and merge translations
5
- */
6
-
7
- import {pathToFileURL} from 'node:url';
8
- import {importUserModule} from '../fs/module-loader.mjs';
9
- import {parseDoc} from '../../authoring/doctypes/parse.mjs';
10
-
11
- /**
12
- * Load a component doc through the shared load/validation boundary.
13
- *
14
- * This is the typed counterpart to {@link loadDocs}: it loads `.doc.ts` via
15
- * jiti (and `.doc.mjs`/`.doc.js` via native import) and validates via
16
- * `parseDoc`, which accepts BOTH formats, so this loader reads whichever the
17
- * file uses:
18
- * - NEW: a stamped default export (`export default {type: 'component', ...}`
19
- * / `'function'` / `'generic'`) — the same single-export convention the
20
- * other authoring parsers use for config/integration/template. These carry
21
- * a stamped `type` and validate against the matching per-kind parser.
22
- * - OLD: the legacy loose `export const docs = {...}` (no `type`), validated
23
- * against the permissive legacy union.
24
- * The default export wins when both are present. Throws a readable
25
- * `formatZodError`-style message on failure. Translations (`docsZh`/
26
- * `docsDense`) are merged exactly as {@link loadDocs} does so callers see
27
- * identical output.
4
+ * @file Component and hook doc loader.
28
5
  *
29
- * @param {string} docPath absolute path to a `.doc.{ts,mjs,js}` file
30
- * @param {{zh?: boolean, dense?: boolean, lang?: string}} [opts]
31
- * @returns {Promise<object>} the validated (and optionally translated) doc
6
+ * @input A component or hook `.doc.{ts,mjs,js}` path and the reading language
7
+ * (`lang`, or the legacy `zh`/`dense` flags).
8
+ * @output The module's own doc, with its translation laid over it for `lang`.
9
+ * @position The loaders every component and hook reader calls. Both read
10
+ * through the doc compiler (foundation/doc-compiler/read.mjs), which lowers
11
+ * the doc on every read. The two differ only in how strict they are:
12
+ * {@link loadComponentDoc} reports a doc that fails its kind's parser, and
13
+ * {@link loadDocs}, which has never checked docs, still reads one.
32
14
  */
33
- export async function loadComponentDoc(
34
- docPath,
35
- {zh = false, dense = false, lang} = {},
36
- ) {
37
- const mod = await importUserModule(docPath);
38
- /** @type {any} */
39
- const authored = mod?.default ?? mod?.docs;
40
-
41
- parseDoc(authored, docPath);
42
- const docs = authored;
43
15
 
44
- const locale = lang || (dense ? 'dense' : zh ? 'zh' : null);
45
- if (!locale) return docs;
16
+ import {readDocView} from '../doc-compiler/read.mjs';
46
17
 
47
- const translationKey =
48
- locale === 'zh' ? 'docsZh' : locale === 'dense' ? 'docsDense' : null;
49
- if (!translationKey || !mod[translationKey]) return docs;
50
-
51
- /** @type {any} */
52
- const translation = mod[translationKey];
53
- if (translation.props || translation.components?.some((/** @type {any} */ c) => c.props)) {
54
- return overlayComponentDoc(docs, translation);
55
- }
56
- return mergeTranslation(docs, translation);
57
- }
18
+ export {mergeTranslation} from '../doc-compiler/overlays.mjs';
58
19
 
59
20
  /**
60
- * @param {any} docs
61
- * @param {any} translation
62
- * @returns {any}
21
+ * @typedef {object} LoadDocOptions
22
+ * @property {boolean} [zh] legacy flag for `lang: 'zh'`
23
+ * @property {boolean} [dense] legacy flag for `lang: 'dense'`
24
+ * @property {string | null} [lang] wins over the legacy flags
25
+ * @property {'components' | 'hooks'} [root] which root reads the doc
26
+ * (default: components)
63
27
  */
64
- export function mergeTranslation(docs, translation) {
65
- if (!translation) return docs;
66
-
67
- /** @type {any} */
68
- const merged = {...docs};
69
-
70
- // Merge prose into usage
71
- if (merged.usage) {
72
- merged.usage = {...merged.usage};
73
- if (translation.usage?.description) merged.usage.description = translation.usage.description;
74
- else if (translation.description) merged.usage.description = translation.description;
75
- if (translation.usage?.bestPractices) merged.usage.bestPractices = translation.usage.bestPractices;
76
- if (translation.usage?.accessibility) merged.usage.accessibility = translation.usage.accessibility;
77
- }
78
-
79
- // Legacy top-level fields (for docsZh that are full ComponentDoc clones)
80
- if (translation.description && !merged.usage) merged.description = translation.description;
81
-
82
- // Merge prop descriptions for single-component docs
83
- if (translation.propDescriptions && merged.props) {
84
- merged.props = merged.props.map((/** @type {any} */ prop) => {
85
- const desc = translation.propDescriptions[prop.name];
86
- return desc != null ? {...prop, description: desc} : prop;
87
- });
88
- }
89
-
90
- // Merge hook param descriptions (HookTranslationDoc). Params are an array of
91
- // {name, type, description, required}; override description by name where the
92
- // translation has an entry. Names may include dots (e.g. 'options.isActive');
93
- // the lookup is keyed by the exact param name.
94
- if (translation.paramDescriptions && merged.params) {
95
- merged.params = merged.params.map((/** @type {any} */ param) => {
96
- const desc = translation.paramDescriptions[param.name];
97
- return desc != null ? {...param, description: desc} : param;
98
- });
99
- }
100
-
101
- // Merge hook return descriptions (HookTranslationDoc). Returns are an array
102
- // of {name, type, description}; override description by name where present.
103
- if (translation.returnDescriptions && merged.returns) {
104
- merged.returns = merged.returns.map((/** @type {any} */ ret) => {
105
- const desc = translation.returnDescriptions[ret.name];
106
- return desc != null ? {...ret, description: desc} : ret;
107
- });
108
- }
109
-
110
- // Merge sub-component translations
111
- if (translation.components && merged.components) {
112
- merged.components = merged.components.map((/** @type {any} */ comp, /** @type {any} */ i) => {
113
- const trans = translation.components.find((/** @type {any} */ t) => t.name === comp.name)
114
- || translation.components[i];
115
- if (!trans) return comp;
116
-
117
- const mergedComp = {...comp};
118
- if (trans.description) mergedComp.description = trans.description;
119
- if (trans.propDescriptions && comp.props) {
120
- mergedComp.props = comp.props.map((/** @type {any} */ prop) => {
121
- const desc = trans.propDescriptions[prop.name];
122
- return desc != null ? {...prop, description: desc} : prop;
123
- });
124
- }
125
- return mergedComp;
126
- });
127
- }
128
-
129
- return merged;
130
- }
131
28
 
132
29
  /**
133
- * Load the typed docs object from a .doc.mjs file.
134
- * Supports --lang flag: 'zh' for Chinese, 'dense' for compressed format.
135
- * Also supports legacy --zh and --dense flags.
136
- * Translations are merged onto the base docs, keeping structure intact.
137
- * @param {string} readmePath
138
- * @param {{zh?: boolean, dense?: boolean, lang?: string}} [opts]
139
- * @returns {Promise<any>}
30
+ * The overlay a read applies: `lang`, else the legacy flags.
31
+ * @param {LoadDocOptions} opts
32
+ * @returns {string | null}
140
33
  */
141
- export async function loadDocs(readmePath, {zh = false, dense = false, lang} = {}) {
142
- const mod = await import(pathToFileURL(readmePath).href);
143
- // Support both the new stamped default export (`export default {type: 'component', …}`)
144
- // and the legacy named export (`export const docs = {…}`). Default wins when both
145
- // are present, matching loadComponentDoc's precedence.
146
- const docs = mod?.default ?? mod.docs;
147
-
148
- // Resolve which translation to use (--lang takes priority over legacy flags)
149
- const locale = lang || (dense ? 'dense' : zh ? 'zh' : null);
150
- if (!locale) return docs;
151
-
152
- const translationKey = locale === 'zh' ? 'docsZh' : locale === 'dense' ? 'docsDense' : null;
153
- if (!translationKey || !mod[translationKey]) return docs;
154
-
155
- const translation = mod[translationKey];
156
-
157
- // A full ComponentDoc-shaped translation (legacy docsZh shape) used to be
158
- // returned wholesale. That made it a REPLACEMENT, not an overlay: any prop
159
- // the translation had not caught up with simply ceased to exist —
160
- // `component Button --zh` silently omitted `isInterruptible` and
161
- // `isIconOnly`. A reader of the translated docs cannot discover a prop that
162
- // is not there. Overlay it instead, so an untranslated prop falls back to
163
- // its English entry. (Same principle as the reference-doc overlays, #2182.)
164
- if (translation.props || translation.components?.some((/** @type {any} */ c) => c.props)) {
165
- return overlayComponentDoc(docs, translation);
166
- }
167
-
168
- // Otherwise it's a ComponentTranslationDoc — merge it onto docs
169
- return mergeTranslation(docs, translation);
34
+ function localeOf({zh = false, dense = false, lang} = {}) {
35
+ return lang || (dense ? 'dense' : zh ? 'zh' : null);
170
36
  }
171
37
 
172
38
  /**
173
- * Overlay a full-ComponentDoc-shaped translation onto the English doc.
39
+ * Load a component or hook doc and check it against its kind's parser.
174
40
  *
175
- * Base order and completeness win; the translation supplies text for the
176
- * entries it covers. Props are matched by name, never by position, so a
177
- * translation that is missing entries (or lists them in another order) can no
178
- * longer drop or misattribute one.
41
+ * Reads `.doc.ts` through jiti and `.doc.mjs`/`.doc.js` natively. Both formats
42
+ * load: a stamped default export (`export default {type: 'component', ...}`)
43
+ * checked against its kind, and the legacy `export const docs = {...}` checked
44
+ * against the permissive legacy union. The default export wins when both are
45
+ * present. Throws the parser's readable message when the doc fails.
179
46
  *
180
- * @param {any} docs Base (English) component doc.
181
- * @param {any} translation Translated doc, possibly covering only some props.
182
- * @returns {any} Merged doc with every base prop present.
47
+ * @param {string} docPath absolute path to a `.doc.{ts,mjs,js}` file
48
+ * @param {LoadDocOptions} [opts]
49
+ * @returns {Promise<any>} the checked (and optionally translated) doc
183
50
  */
184
- function overlayComponentDoc(docs, translation) {
185
- /** Merge one prop list: keep base entries and order, translate what's covered.
186
- * @param {any[] | undefined} baseProps
187
- * @param {any[] | undefined} tProps
188
- */
189
- const overlayProps = (baseProps, tProps) => {
190
- if (!baseProps) return baseProps;
191
- const byName = new Map((tProps ?? []).map((/** @type {any} */ p) => [p.name, p]));
192
- return baseProps.map((/** @type {any} */ prop) => {
193
- const t = byName.get(prop.name);
194
- // Take the translated text, but never let it drop the prop's contract
195
- // (type/default/required stay authoritative from the English doc).
196
- return t ? {...prop, ...t, name: prop.name, type: prop.type} : prop;
197
- });
198
- };
199
-
200
- /** Preserve canonical structured guidance added after legacy full-doc translations,
201
- * without changing established translated prose behavior.
202
- * @param {any} baseUsage
203
- * @param {any} translatedUsage
204
- */
205
- const mergeUsage = (baseUsage, translatedUsage) => {
206
- if (!translatedUsage) return baseUsage;
207
- return {
208
- ...translatedUsage,
209
- ...(translatedUsage.accessibility === undefined &&
210
- baseUsage?.accessibility !== undefined
211
- ? {accessibility: baseUsage.accessibility}
212
- : null),
213
- ...(translatedUsage.accessibilityThemeCoverage === undefined &&
214
- baseUsage?.accessibilityThemeCoverage !== undefined
215
- ? {accessibilityThemeCoverage: baseUsage.accessibilityThemeCoverage}
216
- : null),
217
- ...(translatedUsage.anatomy === undefined && baseUsage?.anatomy !== undefined
218
- ? {anatomy: baseUsage.anatomy}
219
- : null),
220
- };
221
- };
222
-
223
- const merged = {...docs, ...translation, usage: mergeUsage(docs.usage, translation.usage)};
224
-
225
- merged.props = overlayProps(docs.props, translation.props);
226
-
227
- if (docs.components) {
228
- const tByName = new Map(
229
- (translation.components ?? []).map((/** @type {any} */ c) => [c.name, c]),
230
- );
231
- merged.components = docs.components.map((/** @type {any} */ base) => {
232
- const t = tByName.get(base.name);
233
- if (!t) return base;
234
- return {...base, ...t, usage: mergeUsage(base.usage, t.usage), props: overlayProps(base.props, t.props)};
235
- });
236
- }
237
-
238
- return merged;
51
+ export async function loadComponentDoc(docPath, opts = {}) {
52
+ return readDocView(docPath, {
53
+ root: opts.root ?? 'components',
54
+ lang: localeOf(opts),
55
+ label: docPath,
56
+ strict: true,
57
+ });
239
58
  }
240
59
 
241
60
  /**
242
- * Find the doc file for a component, checking both top-level
243
- * and nested directories. Prefers {Name}.doc.mjs, then README.md
244
- * (for backward compatibility).
61
+ * Load a component or hook doc without checking it. Supports `lang` ('zh' for
62
+ * Chinese, 'dense' for compressed) and the legacy `zh`/`dense` flags; the
63
+ * translation is laid over the doc, keeping its structure. A file that exports
64
+ * no doc reads as `undefined`.
65
+ * @param {string} readmePath
66
+ * @param {LoadDocOptions} [opts]
67
+ * @returns {Promise<any>}
245
68
  */
69
+ export async function loadDocs(readmePath, opts = {}) {
70
+ return readDocView(readmePath, {
71
+ root: opts.root ?? 'components',
72
+ lang: localeOf(opts),
73
+ label: readmePath,
74
+ loader: 'native',
75
+ });
76
+ }
@@ -74,8 +74,9 @@ export function discoverIntegrationDocs(integration: {
74
74
  /**
75
75
  * Merge an extension onto a base topic: a section with a stable `id` replaces
76
76
  * the base section with the same `id`; legacy sections without IDs fall back to
77
- * title matching. A section with no match is appended, and title/description
78
- * are taken from the extension when it states them.
77
+ * title matching. A section with no match is appended. The title and
78
+ * description stay the base topic's: an extension adds to a topic, it never
79
+ * renames it. A topic that `replaces` another is the one that renames.
79
80
  *
80
81
  * Keyed by section TITLE rather than by position, the way the localization
81
82
  * overlays are — position keying grafts an overlay onto whichever section
@@ -32,9 +32,9 @@
32
32
  import * as fs from 'node:fs';
33
33
  import * as path from 'node:path';
34
34
  import {CLI_ROOT} from '../fs/paths.mjs';
35
- import {importUserModule} from '../fs/module-loader.mjs';
35
+ import {importDocModule} from '../doc-compiler/import.mjs';
36
36
  import {CLI_PROVIDER_ID} from '../identity/providers.mjs';
37
- import {parseDoc} from '../../authoring/doctypes/parse.mjs';
37
+ import {parseReadableDoc} from '../doc-compiler/parse-readable.mjs';
38
38
  import {
39
39
  sectionKey,
40
40
  sectionKeyProblems,
@@ -117,7 +117,7 @@ export function discoverBuiltinTopics() {
117
117
  * @returns {Promise<unknown>} the authored doc value
118
118
  */
119
119
  export async function loadTopicModule(file) {
120
- const mod = await importUserModule(file);
120
+ const mod = await importDocModule(file);
121
121
  const doc = mod?.docs ?? mod?.default;
122
122
  if (doc == null) {
123
123
  throw new Error(
@@ -363,7 +363,7 @@ export async function discoverIntegrationDocs(integration) {
363
363
  for (const file of files) {
364
364
  let doc;
365
365
  try {
366
- doc = parseDoc(await loadTopicModule(file), path.basename(file));
366
+ doc = parseReadableDoc(await loadTopicModule(file), path.basename(file));
367
367
  } catch (err) {
368
368
  errors.push(
369
369
  new Error(
@@ -423,8 +423,9 @@ export async function discoverIntegrationDocs(integration) {
423
423
  /**
424
424
  * Merge an extension onto a base topic: a section with a stable `id` replaces
425
425
  * the base section with the same `id`; legacy sections without IDs fall back to
426
- * title matching. A section with no match is appended, and title/description
427
- * are taken from the extension when it states them.
426
+ * title matching. A section with no match is appended. The title and
427
+ * description stay the base topic's: an extension adds to a topic, it never
428
+ * renames it. A topic that `replaces` another is the one that renames.
428
429
  *
429
430
  * Keyed by section TITLE rather than by position, the way the localization
430
431
  * overlays are — position keying grafts an overlay onto whichever section
@@ -451,12 +452,7 @@ export function mergeTopic(base, overlay) {
451
452
  : section;
452
453
  }
453
454
  }
454
- return {
455
- ...base,
456
- title: overlay.title || base.title,
457
- description: overlay.description || base.description,
458
- sections,
459
- };
455
+ return {...base, sections};
460
456
  }
461
457
 
462
458
  /**
@@ -505,11 +505,14 @@ describe('mergeTopic', () => {
505
505
  ]);
506
506
  });
507
507
 
508
- it('takes the title and description only when the overlay states them', () => {
509
- expect(mergeTopic(base, {sections: []}).title).toBe('Theme');
510
- expect(mergeTopic(base, {title: 'Theming', sections: []}).title).toBe(
511
- 'Theming',
512
- );
508
+ it('keeps the base title and description: an extension never renames a topic', () => {
509
+ const merged = mergeTopic(base, {
510
+ title: 'Acme theme notes',
511
+ description: 'Our additions.',
512
+ sections: [],
513
+ });
514
+ expect(merged.title).toBe('Theme');
515
+ expect(merged.description).toBe('Theming.');
513
516
  });
514
517
  });
515
518
 
@@ -37,6 +37,13 @@ export function stripTemplateAssetRefs(source: string): string;
37
37
  * @returns {string[]}
38
38
  */
39
39
  export function listTemplates(): string[];
40
+ /**
41
+ * Resolve the template-spec file for a core page directory: the first existing
42
+ * metadata file in {@link ALL_TEMPLATE_SUFFIXES} precedence, or null.
43
+ * @param {string} dirPath
44
+ * @returns {string | null}
45
+ */
46
+ export function findPageDocFile(dirPath: string): string | null;
40
47
  /**
41
48
  * Discover only the templates built into @astryxdesign/core. Integration
42
49
  * authoring checks use this narrower surface so a broken project config or a
@@ -24,9 +24,7 @@
24
24
  import * as fs from 'node:fs';
25
25
  import * as path from 'node:path';
26
26
  import {createRequire} from 'node:module';
27
- import {createJiti} from 'jiti';
28
- import {loadModuleWithParser} from '../fs/module-loader.mjs';
29
- import {parseTemplate} from '../../authoring/doctypes/template/parse.mjs';
27
+ import {readDocView} from '../doc-compiler/read.mjs';
30
28
  import {CLI_ROOT, discoverExternalPackages} from '../fs/paths.mjs';
31
29
  import {CORE_PROVIDER_ID} from '../identity/providers.mjs';
32
30
  import {Project} from '../config/project.mjs';
@@ -84,31 +82,28 @@ export function pkgOf(t) {
84
82
  */
85
83
 
86
84
  /**
87
- * Canonical basename suffixes for template-spec files, in precedence order.
88
- * A template spec is a scaffoldable TEMPLATE (a plain object stamped with a
89
- * `type` of `'page'` or `'block'`), so `.template.*` is the descriptive family
90
- * name.
85
+ * Released compatibility suffixes, in precedence order. Stable 0.6.0
86
+ * documented `.template.*`, so discovery keeps reading those files while all
87
+ * new authoring uses `.doc.mjs`.
91
88
  */
92
89
  const TEMPLATE_SUFFIXES = ['.template.ts', '.template.mjs', '.template.js'];
93
90
 
94
91
  /**
95
- * Legacy basename suffixes for template-spec files, in precedence order.
96
- * `.doc.*` was inherited from the component-doc convention before templates
97
- * had their own name; it is still accepted during the transition window.
92
+ * Descriptor suffixes for templates, in precedence order. New authoring always
93
+ * emits `.doc.mjs`; the TypeScript and JavaScript variants remain readable.
98
94
  */
99
95
  const DOC_SUFFIXES = ['.doc.ts', '.doc.mjs', '.doc.js'];
100
96
 
101
97
  /**
102
- * The union of canonical + legacy template-spec suffixes, canonical first so
103
- * `.template.*` wins over `.doc.*` when both stems exist. All template
104
- * discovery matches this union so a `Foo.template.ts` file is treated exactly
105
- * like a legacy `Foo.doc.mjs`.
98
+ * Every template-spec suffix, in the released precedence a core page directory
99
+ * uses to pick one file. Integration discovery never picks: every match is a
100
+ * template, so two specs for one stem list twice and read as ambiguous.
106
101
  */
107
102
  const ALL_TEMPLATE_SUFFIXES = [...TEMPLATE_SUFFIXES, ...DOC_SUFFIXES];
108
103
 
109
104
  /**
110
105
  * The template-spec suffix present on `file`, or null if none matches.
111
- * Recognizes both the canonical `.template.*` and legacy `.doc.*` families.
106
+ * Recognizes both the canonical `.doc.*` and released `.template.*` families.
112
107
  * @param {string} file
113
108
  * @returns {string | null}
114
109
  */
@@ -122,16 +117,6 @@ function matchedTemplateSuffix(file) {
122
117
  */
123
118
  const TEMPLATE_SUFFIX_RE = /\.(template|doc)\.(ts|mjs|js)$/;
124
119
 
125
- /** @type {ReturnType<typeof createJiti> | undefined} */
126
- let jitiInstance;
127
- /** Lazily-created jiti for loading `.ts` template specs (JSX-capable). */
128
- function getJiti() {
129
- if (!jitiInstance) {
130
- jitiInstance = createJiti(import.meta.url, {jsx: true});
131
- }
132
- return jitiInstance;
133
- }
134
-
135
120
  /**
136
121
  * Load an integration template doc module and validate it against the template
137
122
  * envelope at the load boundary. Default export only — `.ts` via jiti,
@@ -144,7 +129,13 @@ function getJiti() {
144
129
  * @param {string} [label]
145
130
  */
146
131
  async function loadIntegrationDoc(file, label) {
147
- return loadModuleWithParser(file, parseTemplate, {label});
132
+ return readDocView(file, {
133
+ root: 'templates',
134
+ exports: ['default'],
135
+ label: label ?? file,
136
+ strict: true,
137
+ value: 'parsed',
138
+ });
148
139
  }
149
140
 
150
141
  const TEMPLATES_DIR = path.join(CLI_ROOT, 'assets', 'templates');
@@ -492,12 +483,11 @@ function unsafeFixtureReference(source, at, reason) {
492
483
  /**
493
484
  * Load a template-spec module and return its metadata object. Supports both
494
485
  * families of suffix:
495
- * - Legacy `.doc.*` core/external specs export `export const doc = {...}`.
496
- * - Canonical `.template.*` specs export the stamped object (`type: 'page' |
497
- * 'block'`) as the default export.
498
- * Prefers the default export, falling back to the named `doc` export, so a
499
- * `Foo.template.ts` (default export) is read identically to a legacy
500
- * `Foo.doc.mjs` (`doc` export). `.ts` is loaded via jiti; `.mjs`/`.js` via a
486
+ * - Canonical `.doc.*` specs may export the stamped object (`type: 'page' |
487
+ * 'block'`) as the default export or use the historical named `doc` export.
488
+ * - Released `.template.*` compatibility specs use the same object shape.
489
+ * Prefers the default export, falling back to the named `doc` export. `.ts` is
490
+ * loaded via jiti; `.mjs`/`.js` via a
501
491
  * native dynamic import. Returns null if the file does not exist.
502
492
  *
503
493
  * @param {string} docPath absolute path to the spec file
@@ -505,10 +495,7 @@ function unsafeFixtureReference(source, at, reason) {
505
495
  */
506
496
  async function loadDocModule(docPath) {
507
497
  if (!fs.existsSync(docPath)) return null;
508
- const docModule = docPath.endsWith('.ts')
509
- ? await getJiti().import(docPath)
510
- : await import(`file://${docPath}`);
511
- return docModule.default ?? docModule.doc;
498
+ return readDocView(docPath, {root: 'templates', loader: 'template'});
512
499
  }
513
500
 
514
501
  /**
@@ -553,11 +540,11 @@ function findDocFiles(dir, pattern) {
553
540
 
554
541
  /**
555
542
  * Resolve the template-spec file for a core page directory: the first existing
556
- * `template.<suffix>` in canonical-then-legacy precedence, or null.
543
+ * metadata file in {@link ALL_TEMPLATE_SUFFIXES} precedence, or null.
557
544
  * @param {string} dirPath
558
545
  * @returns {string | null}
559
546
  */
560
- function findPageDocFile(dirPath) {
547
+ export function findPageDocFile(dirPath) {
561
548
  for (const suffix of ALL_TEMPLATE_SUFFIXES) {
562
549
  const candidate = path.join(dirPath, `template${suffix}`);
563
550
  if (fs.existsSync(candidate)) return candidate;
@@ -733,7 +720,7 @@ export async function discoverAllWithErrors(cwd = process.cwd()) {
733
720
  /**
734
721
  * Recursively collect integration template-spec files under `root`.
735
722
  * Returns absolute paths to files ending in one of ALL_TEMPLATE_SUFFIXES
736
- * (canonical `.template.*` or legacy `.doc.*`).
723
+ * (canonical `.doc.*` or released `.template.*` compatibility files).
737
724
  *
738
725
  * @param {string} root
739
726
  * @returns {string[]}
@@ -763,7 +750,7 @@ function findIntegrationDocFiles(root) {
763
750
  * Discover templates contributed by configured integrations.
764
751
  *
765
752
  * For each integration with a resolved `templates` root, every
766
- * `<id>.template.{ts,mjs,js}` (or legacy `<id>.doc.{ts,mjs,js}`) file is a
753
+ * canonical `<id>.doc.{mjs,ts,js}` (or released `<id>.template.{ts,mjs,js}`) file is a
767
754
  * template whose id is its path relative to the templates root with the
768
755
  * matched suffix stripped (kebab-case, may be nested). The doc's `type`
769
756
  * (page|block) decides scaffolding — there is no `/pages` vs `/blocks`
@@ -18,6 +18,7 @@ import * as os from 'node:os';
18
18
  import * as path from 'node:path';
19
19
  import {
20
20
  extractComponents,
21
+ findPageDocFile,
21
22
  stripTemplateAssetRefs,
22
23
  } from './template-adapter.mjs';
23
24
 
@@ -164,3 +165,17 @@ describe('stripTemplateAssetRefs', () => {
164
165
  );
165
166
  });
166
167
  });
168
+
169
+ describe('findPageDocFile', () => {
170
+ it('keeps the released precedence when one page has two specs', () => {
171
+ const page = fs.mkdtempSync(path.join(dir, 'page-'));
172
+ fs.writeFileSync(path.join(page, 'template.doc.mjs'), 'export {};\n');
173
+ fs.writeFileSync(path.join(page, 'template.doc.ts'), 'export {};\n');
174
+ expect(findPageDocFile(page)).toBe(path.join(page, 'template.doc.ts'));
175
+
176
+ fs.writeFileSync(path.join(page, 'template.template.mjs'), 'export {};\n');
177
+ expect(findPageDocFile(page)).toBe(
178
+ path.join(page, 'template.template.mjs'),
179
+ );
180
+ });
181
+ });