@astryxdesign/cli 0.7.16 → 0.7.17-canary.gb36275e

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 (239) hide show
  1. package/README.md +13 -23
  2. package/api/build/_adapter.d.mts +5 -0
  3. package/api/build/_adapter.mjs +49 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +2 -1
  7. package/api/build/kit/rank.mjs +59 -12
  8. package/api/build/kit/weights.d.mts +16 -3
  9. package/api/build/kit/weights.json +1 -1
  10. package/api/build/kit/weights.mjs +238 -31
  11. package/api/build/kit/word-model.d.mts +23 -0
  12. package/api/build/kit/word-model.mjs +46 -0
  13. package/api/build/kit/words.d.mts +42 -0
  14. package/api/build/kit/words.mjs +82 -1
  15. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  16. package/api/component/list/list.d.mts +1 -1
  17. package/api/component/list/list.mjs +46 -5
  18. package/api/discover/_adapter.d.mts +1 -1
  19. package/api/docs/_adapter.d.mts +26 -2
  20. package/api/docs/_adapter.mjs +217 -5
  21. package/api/docs/docs.d.mts +3 -0
  22. package/api/docs/docs.doc.mjs +7 -1
  23. package/api/docs/docs.mjs +12 -0
  24. package/api/docs/docs.type.d.mts +5 -0
  25. package/api/docs/docs.type.mjs +2 -0
  26. package/api/docs/node/node.mjs +1 -1
  27. package/api/doctor/_adapter.d.mts +27 -5
  28. package/api/doctor/_adapter.mjs +77 -6
  29. package/api/doctor/built-checks.mjs +38 -13
  30. package/api/doctor/doctor.d.mts +4 -3
  31. package/api/doctor/doctor.mjs +14 -7
  32. package/api/doctor/theme-checks.mjs +121 -17
  33. package/api/render/_adapter.mjs +531 -192
  34. package/api/render/render.doc.mjs +11 -3
  35. package/api/render/render.type.d.mts +30 -0
  36. package/api/render/render.type.mjs +19 -0
  37. package/api/search/ORDERING.md +1 -1
  38. package/api/search/_candidate-score.mjs +51 -32
  39. package/api/search/_fit-order.mjs +3 -3
  40. package/api/search/_result.d.mts +5 -5
  41. package/api/search/_score.d.mts +6 -1
  42. package/api/search/_score.mjs +15 -3
  43. package/api/search/search.d.mts +1 -1
  44. package/api/theme/_adapter.mjs +10 -0
  45. package/api/theme/build/build.d.mts +47 -0
  46. package/api/theme/build/build.mjs +147 -25
  47. package/api/theme/theme.type.d.mts +10 -0
  48. package/api/theme/theme.type.mjs +7 -1
  49. package/api/theme-edit/_adapter.d.mts +48 -0
  50. package/api/theme-edit/_adapter.mjs +675 -42
  51. package/api/theme-edit/_check.d.mts +28 -22
  52. package/api/theme-edit/_check.mjs +1481 -252
  53. package/api/theme-edit/_color.d.mts +9 -0
  54. package/api/theme-edit/_color.mjs +41 -1
  55. package/api/theme-edit/_compiler.mjs +9 -0
  56. package/api/theme-edit/_context.mjs +60 -3
  57. package/api/theme-edit/_css.mjs +21 -1
  58. package/api/theme-edit/_edit.d.mts +22 -0
  59. package/api/theme-edit/_edit.mjs +1196 -88
  60. package/api/theme-edit/_how-commands.d.mts +57 -0
  61. package/api/theme-edit/_how-commands.mjs +536 -1
  62. package/api/theme-edit/_how-question.d.mts +65 -0
  63. package/api/theme-edit/_how-question.mjs +4401 -225
  64. package/api/theme-edit/_how.mjs +104 -4
  65. package/api/theme-edit/_marks.d.mts +31 -5
  66. package/api/theme-edit/_marks.mjs +57 -5
  67. package/api/theme-edit/_normal.d.mts +153 -0
  68. package/api/theme-edit/_normal.mjs +661 -0
  69. package/api/theme-edit/_palette.mjs +10 -4
  70. package/api/theme-edit/_parts.d.mts +8 -0
  71. package/api/theme-edit/_parts.mjs +103 -2
  72. package/api/theme-edit/_preview-app.d.mts +7 -1
  73. package/api/theme-edit/_preview-app.mjs +205 -17
  74. package/api/theme-edit/_preview.d.mts +64 -8
  75. package/api/theme-edit/_preview.mjs +447 -89
  76. package/api/theme-edit/_settings.d.mts +176 -5
  77. package/api/theme-edit/_settings.mjs +1936 -128
  78. package/api/theme-edit/_tables.d.mts +6 -0
  79. package/api/theme-edit/_tables.mjs +32 -1
  80. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  81. package/api/theme-edit/theme-edit.type.mjs +4 -1
  82. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  83. package/assets/codemods/run-codemod.mjs +73 -6
  84. package/assets/codemods/transforms/next/index.mjs +11 -1
  85. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  86. package/assets/docs/author-a-theme.doc.mjs +1 -0
  87. package/assets/docs/theme.doc.dense.mjs +2 -2
  88. package/assets/docs/theme.doc.mjs +1 -1
  89. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  90. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  91. package/assets/docs/tree/render-pages.doc.mjs +43 -2
  92. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  93. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  94. package/assets/docs/use-a-theme.doc.mjs +1 -1
  95. package/assets/docs.generated.json +2 -2
  96. package/assets/self-audit.generated.json +1 -1
  97. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  98. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  99. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  100. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  101. package/assets/templates/components.generated.json +1 -1
  102. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  103. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  104. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  105. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  106. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  107. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  108. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  109. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  110. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  111. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  112. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  113. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  114. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  115. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  116. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  117. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  118. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  119. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  120. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  121. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  122. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  123. package/assets/templates/pages/ide/page.tsx +24 -2
  124. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  125. package/assets/templates/pages/library/template.doc.mjs +4 -1
  126. package/assets/templates/pages/login/template.doc.mjs +2 -1
  127. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  128. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  129. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  130. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  131. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  132. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  133. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  134. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  135. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  136. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  137. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  138. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  139. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  140. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  141. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  142. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  143. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  144. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  145. package/authoring/debug/parse.d.mts +3 -3
  146. package/authoring/doctypes/_schema.d.mts +3 -3
  147. package/authoring/doctypes/command/command.doc.mjs +1 -1
  148. package/authoring/doctypes/template/template.doc.mjs +1 -1
  149. package/authoring/doctypes/template/type.ts +9 -0
  150. package/clients/cli/bin/astryx.mjs +6 -9
  151. package/clients/cli/build-id.generated.json +1 -1
  152. package/clients/cli/commands/component.doc.mjs +1 -1
  153. package/clients/cli/commands/component.mjs +20 -2
  154. package/clients/cli/commands/docs.doc.mjs +7 -1
  155. package/clients/cli/commands/docs.mjs +3 -1
  156. package/clients/cli/commands/doctor.mjs +22 -14
  157. package/clients/cli/commands/experimental/render.mjs +32 -1
  158. package/clients/cli/commands/experimental/theme.mjs +65 -14
  159. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  160. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  161. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  162. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  163. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  164. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  165. package/clients/cli/commands/search.doc.mjs +2 -1
  166. package/clients/cli/commands/search.mjs +6 -1
  167. package/clients/cli/commands/template.mjs +4 -2
  168. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  169. package/clients/cli/commands/theme.doc.mjs +1 -1
  170. package/clients/cli/commands/theme.mjs +153 -5
  171. package/clients/cli/commands/upgrade.mjs +42 -7
  172. package/clients/cli/index.mjs +1 -1
  173. package/clients/cli/lib/component-format.mjs +205 -98
  174. package/clients/cli/lib/hook-format.mjs +9 -19
  175. package/clients/cli/manifest.generated.json +1 -1
  176. package/foundation/agent-docs/agent-docs.mjs +1 -1
  177. package/foundation/config/theme-state.d.mts +13 -1
  178. package/foundation/config/theme-state.mjs +47 -7
  179. package/foundation/discovery/component-discovery.d.mts +11 -0
  180. package/foundation/discovery/component-discovery.mjs +27 -2
  181. package/foundation/discovery/component-replacement.mjs +130 -1
  182. package/foundation/discovery/entry-name-files.d.mts +43 -0
  183. package/foundation/discovery/entry-name-files.mjs +264 -0
  184. package/foundation/discovery/hook-discovery.d.mts +8 -2
  185. package/foundation/discovery/hook-discovery.mjs +20 -7
  186. package/foundation/discovery/package-exports.d.mts +10 -0
  187. package/foundation/discovery/package-exports.mjs +56 -3
  188. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  189. package/foundation/discovery/runner-allowlist.mjs +2 -0
  190. package/foundation/discovery/template-adapter.d.mts +52 -0
  191. package/foundation/discovery/template-adapter.mjs +173 -10
  192. package/foundation/discovery/theme-imports.d.mts +14 -0
  193. package/foundation/discovery/theme-imports.mjs +43 -1
  194. package/foundation/doc-compiler/import.mjs +7 -1
  195. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  196. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  197. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  198. package/foundation/fs/cache-eviction.d.mts +21 -0
  199. package/foundation/fs/cache-eviction.mjs +73 -0
  200. package/foundation/fs/gather-cache.d.mts +25 -4
  201. package/foundation/fs/gather-cache.mjs +163 -53
  202. package/foundation/fs/jiti-cache.d.mts +19 -1
  203. package/foundation/fs/jiti-cache.mjs +130 -6
  204. package/foundation/fs/kept-tree.d.mts +60 -0
  205. package/foundation/fs/kept-tree.mjs +154 -0
  206. package/foundation/fs/module-loader.d.mts +18 -2
  207. package/foundation/fs/module-loader.mjs +92 -20
  208. package/foundation/identity/provider-identity.d.mts +6 -0
  209. package/foundation/identity/provider-identity.mjs +10 -1
  210. package/foundation/render/embedded-imports.d.mts +5 -4
  211. package/foundation/render/embedded-imports.mjs +7 -16
  212. package/foundation/render/file-header.d.mts +66 -0
  213. package/foundation/render/file-header.mjs +118 -0
  214. package/foundation/render/host-answer.d.mts +18 -0
  215. package/foundation/render/host-answer.mjs +46 -0
  216. package/foundation/render/host-exit.d.mts +1 -0
  217. package/foundation/render/host-exit.mjs +6 -1
  218. package/foundation/render/html-reader.d.mts +55 -2
  219. package/foundation/render/html-reader.mjs +145 -26
  220. package/foundation/render/markup-edits.d.mts +57 -0
  221. package/foundation/render/markup-edits.mjs +182 -0
  222. package/foundation/render/page-host.mjs +29 -12
  223. package/foundation/render/page-worker.mjs +83 -13
  224. package/foundation/render/render-page.d.mts +34 -2
  225. package/foundation/render/render-page.mjs +210 -29
  226. package/foundation/render/source-block.d.mts +73 -6
  227. package/foundation/render/source-block.mjs +170 -19
  228. package/foundation/render/ts-paths.d.mts +53 -6
  229. package/foundation/render/ts-paths.mjs +286 -41
  230. package/foundation/response/error-codes.d.mts +3 -1
  231. package/foundation/response/error-codes.d.ts +1 -0
  232. package/foundation/response/error-codes.doc.mjs +12 -1
  233. package/foundation/response/error-codes.mjs +10 -0
  234. package/foundation/text/string-utils.d.mts +3 -2
  235. package/foundation/text/string-utils.mjs +16 -3
  236. package/foundation/text/suggest-order.d.mts +9 -0
  237. package/foundation/text/suggest-order.mjs +13 -0
  238. package/host/index.mjs +8 -6
  239. package/package.json +6 -6
@@ -22,7 +22,9 @@ import {
22
22
  resolveImportPath,
23
23
  resolveIntegrationImportPath,
24
24
  } from '../../../foundation/discovery/component-discovery.mjs';
25
- import {discoverExternalPackages} from '../../../foundation/fs/paths.mjs';
25
+ import {EXACT_CODEC} from '../../../foundation/fs/exact-codec.mjs';
26
+ import {persistedGather} from '../../../foundation/fs/gather-cache.mjs';
27
+ import {CLI_ROOT, discoverExternalPackages, realDir} from '../../../foundation/fs/paths.mjs';
26
28
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
27
29
  import {AstryxError} from '../../error.mjs';
28
30
  import {
@@ -162,10 +164,49 @@ async function replacementEntry(replacement, detail, {zh, dense, lang}) {
162
164
  * @param {string|null} opts.lang
163
165
  * @returns {Promise<ComponentListResponse>}
164
166
  */
165
- export async function componentList(
166
- coreDir,
167
- {cwd, category, detail, zh, dense, lang},
168
- ) {
167
+ export async function componentList(coreDir, opts) {
168
+ const {cwd, category, detail, zh, dense, lang} = opts;
169
+ // A function of the files it reads (Core's component folders and docs, the
170
+ // integrations and their docs), which the kept gather stamps: a later run
171
+ // with every one unchanged reads the list back.
172
+ return /** @type {ComponentListResponse} */ (
173
+ await persistedGather(
174
+ [
175
+ 'component-list',
176
+ realDir(cwd),
177
+ coreDir,
178
+ CLI_ROOT,
179
+ category ?? null,
180
+ detail,
181
+ zh,
182
+ dense,
183
+ lang,
184
+ ],
185
+ () => componentListNow(coreDir, opts),
186
+ COMPONENT_LIST_CODEC,
187
+ )
188
+ );
189
+ }
190
+
191
+ /** The component list, kept exactly, with the envelope's shape. */
192
+ const COMPONENT_LIST_CODEC = {
193
+ ...EXACT_CODEC,
194
+ valid: (/** @type {any} */ value) =>
195
+ value != null &&
196
+ value.type === 'component.list' &&
197
+ value.data != null &&
198
+ typeof value.data.detail === 'string' &&
199
+ value.data.components != null &&
200
+ typeof value.data.components === 'object',
201
+ };
202
+
203
+ /**
204
+ * componentList, worked out now.
205
+ * @param {string} coreDir
206
+ * @param {Parameters<typeof componentList>[1]} options
207
+ * @returns {Promise<ComponentListResponse>}
208
+ */
209
+ async function componentListNow(coreDir, {cwd, category, detail, zh, dense, lang}) {
169
210
  const components = discoverComponents(coreDir);
170
211
  // An active integration replacement takes its Core component's slot in
171
212
  // every list view (spec:AST-035 FR11); the Core original stays reachable
@@ -216,7 +216,7 @@ export const OFFICIAL_LIST_FILE: string;
216
216
  */
217
217
  export const EXPERIMENTAL_KINDS: readonly ["icon-set"];
218
218
  /** The item kinds every project reads: the catalog kinds, less experimental ones. */
219
- export const STABLE_KINDS: ("template" | "component" | "doc" | "theme" | "codemod" | "agent-doc" | "icon-set")[];
219
+ export const STABLE_KINDS: ("component" | "template" | "doc" | "theme" | "codemod" | "agent-doc" | "icon-set")[];
220
220
  /** The list and detail entry fields for each item kind, in display order. */
221
221
  export const KIND_FIELDS: readonly [readonly ["component", "components"], readonly ["template", "templates"], readonly ["doc", "docs"], readonly ["theme", "themes"], readonly ["codemod", "codemods"], readonly ["agent-doc", "agentDocs"], readonly ["icon-set", "iconSets"]];
222
222
  export type ScannedPackage = import("./_package-scanner.mjs").ScannedPackage;
@@ -366,12 +366,36 @@ export function routeOwner(tree: DocsTree, entry: import("../../foundation/disco
366
366
  * Otherwise it suggests the docs the argument names in another spelling, or
367
367
  * failing that the topics and top-level namespaces, closest first and cut
368
368
  * where the matches get weaker (every one of them when none shares a word
369
- * with the argument).
369
+ * with the argument). When the argument is the name of a component, hook or
370
+ * template, the command that reads that entry comes first and takes the last
371
+ * suggestion's place, so the list keeps its length; when no suggested doc
372
+ * shares a word with the argument, that command is the only suggestion.
370
373
  * @param {unknown} topic
371
374
  * @param {DocsCatalog} catalog
375
+ * @param {{cwd?: string}} [options]
372
376
  * @returns {Promise<AstryxError>}
373
377
  */
374
- export function unknownTopicError(topic: unknown, catalog: DocsCatalog): Promise<AstryxError>;
378
+ export function unknownTopicError(topic: unknown, catalog: DocsCatalog, { cwd }?: {
379
+ cwd?: string;
380
+ }): Promise<AstryxError>;
381
+ /**
382
+ * The command that reads the component, hook or template a docs argument
383
+ * names, or null. Only an exact name counts, in any case and with or without
384
+ * spaces and hyphens; a hook also answers to its name without `use`. A
385
+ * component wins over a hook, and a hook over a template. A route never names
386
+ * one of them.
387
+ * @param {string} topic
388
+ * @param {{components?: string[], hooks?: string[], templates?: string[]}} names
389
+ * @returns {{name: string, reason: string} | null}
390
+ */
391
+ export function entryCommand(topic: string, { components, hooks, templates }: {
392
+ components?: string[];
393
+ hooks?: string[];
394
+ templates?: string[];
395
+ }): {
396
+ name: string;
397
+ reason: string;
398
+ } | null;
375
399
  /**
376
400
  * A sentence naming the packages whose docs did not load, or nothing: a doc
377
401
  * that fails to load withdraws its package's docs, so a reader who cannot
@@ -68,23 +68,45 @@ import {
68
68
  import {CLI_PROVIDER_ID} from '../../foundation/identity/providers.mjs';
69
69
  import {
70
70
  CORE_PACKAGE,
71
+ discoverComponentNamesWhere,
72
+ discoverIntegrationComponents,
71
73
  discoverOwnedComponents,
72
74
  discoverValidIntegrationComponents,
73
75
  } from '../../foundation/discovery/component-discovery.mjs';
74
76
  import {loadComponentDoc} from '../../foundation/discovery/component-loader.mjs';
75
77
  import {
78
+ coreFilesNaming,
79
+ foldEntryName,
80
+ integrationsFilesNaming,
81
+ } from '../../foundation/discovery/entry-name-files.mjs';
82
+ import {getAllHookNames} from '../../foundation/discovery/hook-discovery.mjs';
83
+ import {
84
+ coreTemplateIds,
76
85
  discoverCoreTemplates,
77
86
  discoverIntegrationTemplatesForOne,
87
+ integrationsMayReplaceTemplate,
88
+ listTemplates,
89
+ templateFilesNaming,
78
90
  } from '../../foundation/discovery/template-adapter.mjs';
79
91
  import {findCoreDir} from '../../foundation/fs/paths.mjs';
80
92
  import {reusedWhileUnchanged} from '../../foundation/fs/read-record.mjs';
81
93
  import {AstryxError} from '../error.mjs';
82
94
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
83
- import {orderRouteSuggestions} from '../../foundation/text/suggest-order.mjs';
95
+ import {
96
+ carriesTypedWord,
97
+ orderRouteSuggestions,
98
+ } from '../../foundation/text/suggest-order.mjs';
84
99
  import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
85
100
 
86
101
  export {OVERLAY_LANGUAGES, overlayLanguages};
87
102
 
103
+ /**
104
+ * The project each loaded catalog came from, so a later step of the same read
105
+ * does not load the project again.
106
+ * @type {WeakMap<DocsCatalog, Project>}
107
+ */
108
+ const projectOfCatalog = new WeakMap();
109
+
88
110
  /**
89
111
  * The project's topics: the built-in ones plus whatever the configured
90
112
  * integrations contribute.
@@ -101,7 +123,9 @@ export {OVERLAY_LANGUAGES, overlayLanguages};
101
123
  export async function loadDocsCatalog(cwd = process.cwd()) {
102
124
  try {
103
125
  const project = await Project.load(cwd);
104
- return await project.docs();
126
+ const catalog = await project.docs();
127
+ projectOfCatalog.set(catalog, project);
128
+ return catalog;
105
129
  } catch {
106
130
  return DocsCatalog.fromBuiltins();
107
131
  }
@@ -1932,12 +1956,16 @@ function movedRoute(topic, tree) {
1932
1956
  * Otherwise it suggests the docs the argument names in another spelling, or
1933
1957
  * failing that the topics and top-level namespaces, closest first and cut
1934
1958
  * where the matches get weaker (every one of them when none shares a word
1935
- * with the argument).
1959
+ * with the argument). When the argument is the name of a component, hook or
1960
+ * template, the command that reads that entry comes first and takes the last
1961
+ * suggestion's place, so the list keeps its length; when no suggested doc
1962
+ * shares a word with the argument, that command is the only suggestion.
1936
1963
  * @param {unknown} topic
1937
1964
  * @param {DocsCatalog} catalog
1965
+ * @param {{cwd?: string}} [options]
1938
1966
  * @returns {Promise<AstryxError>}
1939
1967
  */
1940
- export async function unknownTopicError(topic, catalog) {
1968
+ export async function unknownTopicError(topic, catalog, {cwd} = {}) {
1941
1969
  const tree = await projectTree(catalog);
1942
1970
  /** @type {Array<{name: string, reason: string}>} */
1943
1971
  let suggestions = [];
@@ -1975,7 +2003,10 @@ export async function unknownTopicError(topic, catalog) {
1975
2003
  )
1976
2004
  .map(node => ({name: node.route, reason: node.summary}));
1977
2005
  }
2006
+ // Every topic and namespace: the list a name no doc shares a word with gets.
2007
+ let everyDoc = false;
1978
2008
  if (suggestions.length === 0) {
2009
+ everyDoc = true;
1979
2010
  suggestions = [
1980
2011
  ...tree
1981
2012
  .roots()
@@ -2001,6 +2032,16 @@ export async function unknownTopicError(topic, catalog) {
2001
2032
  ERROR_CODES.ERR_UNKNOWN_TOPIC,
2002
2033
  );
2003
2034
  }
2035
+ const elsewhere =
2036
+ suggestions.length > 0 ? await entryElsewhere(topic, catalog, cwd) : null;
2037
+ if (elsewhere) {
2038
+ const sharesAWord =
2039
+ !everyDoc ||
2040
+ suggestions.some(entry => carriesTypedWord(String(topic), entry.name));
2041
+ suggestions = sharesAWord
2042
+ ? [elsewhere, ...suggestions.slice(0, -1)]
2043
+ : [elsewhere];
2044
+ }
2004
2045
  return new AstryxError(
2005
2046
  `Unknown topic "${String(topic)}"${notLoaded(catalog)}`,
2006
2047
  suggestions,
@@ -2008,6 +2049,177 @@ export async function unknownTopicError(topic, catalog) {
2008
2049
  );
2009
2050
  }
2010
2051
 
2052
+ /**
2053
+ * The command that reads the component, hook or template a docs argument
2054
+ * names, or null. Only an exact name counts, in any case and with or without
2055
+ * spaces and hyphens; a hook also answers to its name without `use`. A
2056
+ * component wins over a hook, and a hook over a template. A route never names
2057
+ * one of them.
2058
+ * @param {string} topic
2059
+ * @param {{components?: string[], hooks?: string[], templates?: string[]}} names
2060
+ * @returns {{name: string, reason: string} | null}
2061
+ */
2062
+ export function entryCommand(
2063
+ topic,
2064
+ {components = [], hooks = [], templates = []},
2065
+ ) {
2066
+ if (topic.includes('/')) return null;
2067
+ const wanted = foldEntryName(topic);
2068
+ if (wanted === '') return null;
2069
+ const component = components.find(name => foldEntryName(name) === wanted);
2070
+ if (component) {
2071
+ return {
2072
+ name: `astryx component ${component}`,
2073
+ reason: 'a component, not a docs topic',
2074
+ };
2075
+ }
2076
+ const hook = hooks.find(name => {
2077
+ const folded = foldEntryName(name);
2078
+ return folded === wanted || folded === `use${wanted}`;
2079
+ });
2080
+ if (hook) {
2081
+ return {name: `astryx hook ${hook}`, reason: 'a hook, not a docs topic'};
2082
+ }
2083
+ const template = templates.find(name => foldEntryName(name) === wanted);
2084
+ if (template) {
2085
+ return {
2086
+ name: `astryx template ${template}`,
2087
+ reason: 'a template, not a docs topic',
2088
+ };
2089
+ }
2090
+ return null;
2091
+ }
2092
+
2093
+ /**
2094
+ * {@link entryCommand} over the names the project's catalogs hold. File names
2095
+ * and doc text say first which catalogs can hold the argument; a catalog is
2096
+ * asked only then, only for the names that fold to the argument, and only
2097
+ * when the one before it has no match. So a name no file carries reads no doc.
2098
+ * A check that fails gives no hint.
2099
+ * @param {unknown} topic
2100
+ * @param {DocsCatalog} catalog the catalog the read used; its project is
2101
+ * reused
2102
+ * @param {string} [cwd]
2103
+ * @returns {Promise<{name: string, reason: string} | null>}
2104
+ */
2105
+ async function entryElsewhere(topic, catalog, cwd = process.cwd()) {
2106
+ if (typeof topic !== 'string' || topic.includes('/')) return null;
2107
+ const wanted = foldEntryName(topic);
2108
+ if (wanted === '') return null;
2109
+ let project = projectOfCatalog.get(catalog);
2110
+ try {
2111
+ project ??= await Project.load(cwd);
2112
+ } catch {
2113
+ return null;
2114
+ }
2115
+ const coreDir = project.coreDir();
2116
+ const integrations = project.loadedIntegrations;
2117
+ /** @param {string} name */
2118
+ const isWanted = name => foldEntryName(name) === wanted;
2119
+ /** @param {string} name */
2120
+ const isWantedHook = name =>
2121
+ isWanted(name) || foldEntryName(name) === `use${wanted}`;
2122
+ /** @type {{component: boolean, hook: boolean, componentTops?: Set<string>, hookTops?: Set<string>}} */
2123
+ let inCore = {component: false, hook: false};
2124
+ try {
2125
+ if (coreDir) inCore = coreFilesNaming(coreDir, wanted);
2126
+ } catch {
2127
+ inCore = {component: true, hook: true};
2128
+ }
2129
+ /** @type {Array<() => Promise<{components?: string[], hooks?: string[], templates?: string[]}>>} */
2130
+ const catalogs = [
2131
+ async () => ({
2132
+ components:
2133
+ coreDir && inCore.component
2134
+ ? discoverComponentNamesWhere(coreDir, isWanted, inCore.componentTops)
2135
+ : [],
2136
+ }),
2137
+ async () => ({
2138
+ components: await integrationComponentNames(
2139
+ integrations,
2140
+ wanted,
2141
+ isWanted,
2142
+ ),
2143
+ }),
2144
+ async () => ({
2145
+ hooks:
2146
+ coreDir && inCore.hook
2147
+ ? getAllHookNames(coreDir, isWantedHook, inCore.hookTops)
2148
+ : [],
2149
+ }),
2150
+ async () => ({
2151
+ templates: await templateNames(project, integrations, wanted),
2152
+ }),
2153
+ ];
2154
+ for (const load of catalogs) {
2155
+ let names;
2156
+ try {
2157
+ names = await load();
2158
+ } catch {
2159
+ continue;
2160
+ }
2161
+ const found = entryCommand(topic, names);
2162
+ if (found) return found;
2163
+ }
2164
+ return null;
2165
+ }
2166
+
2167
+ /**
2168
+ * The names `isWanted` accepts among the valid components of the loaded
2169
+ * integrations, in project order. Only an integration whose files can carry
2170
+ * the name is read, and it loads its docs only when it lists such a name.
2171
+ * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} integrations
2172
+ * @param {string} wanted the folded name
2173
+ * @param {(name: string) => boolean} isWanted
2174
+ * @returns {Promise<string[]>}
2175
+ */
2176
+ async function integrationComponentNames(integrations, wanted, isWanted) {
2177
+ const naming = integrationsFilesNaming(
2178
+ integrations.map(integration => integration.components),
2179
+ wanted,
2180
+ );
2181
+ for (const [at, integration] of integrations.entries()) {
2182
+ if (!naming[at]) continue;
2183
+ if (!discoverIntegrationComponents(integration).some(r => isWanted(r.name)))
2184
+ continue;
2185
+ const {components} = await discoverValidIntegrationComponents(integration);
2186
+ const names = components.map(r => r.name).filter(isWanted);
2187
+ if (names.length > 0) return names;
2188
+ }
2189
+ return [];
2190
+ }
2191
+
2192
+ /**
2193
+ * The template ids that fold to `wanted`, as the project's template list
2194
+ * holds them. Core's ids come from file names. The whole list loads only when
2195
+ * an integration ships a template doc with such an id, when more than one
2196
+ * Core id folds to it (the list decides their order), or when one does and
2197
+ * an integration template may replace it.
2198
+ * @param {Project} project
2199
+ * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} integrations
2200
+ * @param {string} wanted the folded name
2201
+ * @returns {Promise<string[]>}
2202
+ */
2203
+ async function templateNames(project, integrations, wanted) {
2204
+ /** @param {string} name */
2205
+ const isWanted = name => foldEntryName(name) === wanted;
2206
+ const {blocks, listed} = templateFilesNaming(integrations, wanted);
2207
+ const core = blocks
2208
+ ? coreTemplateIds(isWanted)
2209
+ : listTemplates().filter(isWanted);
2210
+ if (
2211
+ !listed &&
2212
+ core.length < 2 &&
2213
+ (core.length === 0 || !integrationsMayReplaceTemplate(integrations))
2214
+ ) {
2215
+ return core;
2216
+ }
2217
+ return /** @type {Array<{dirName?: unknown}>} */ (await project.templates())
2218
+ .map(record => record.dirName)
2219
+ .filter(name => typeof name === 'string')
2220
+ .filter(isWanted);
2221
+ }
2222
+
2011
2223
  /**
2012
2224
  * A sentence naming the packages whose docs did not load, or nothing: a doc
2013
2225
  * that fails to load withdraws its package's docs, so a reader who cannot
@@ -2041,7 +2253,7 @@ export async function resolveTopicDocs(topic, options = {}, loaded) {
2041
2253
  undefined,
2042
2254
  ERROR_CODES.ERR_UNKNOWN_TOPIC,
2043
2255
  )
2044
- : await unknownTopicError(topic, found.catalog);
2256
+ : await unknownTopicError(topic, found.catalog, {cwd});
2045
2257
  }
2046
2258
  const {catalog, entry} = found;
2047
2259
  const node = await lowerTopic(catalog, entry, effectiveLang);
@@ -8,6 +8,8 @@
8
8
  * @param {string} [options.lang]
9
9
  * @param {boolean} [options.zh]
10
10
  * @param {boolean} [options.dense]
11
+ * @param {boolean} [options.list] return the topic list, the same as giving
12
+ * no topic; docs() refuses a topic or section beside it
11
13
  * @param {boolean} [options.index] return the topic's section index instead of
12
14
  * the whole doc
13
15
  * @param {number | 'all'} [options.depth] how many levels below a docs-tree
@@ -27,6 +29,7 @@ export function docs(topic?: string, section?: string, options?: {
27
29
  lang?: string | undefined;
28
30
  zh?: boolean | undefined;
29
31
  dense?: boolean | undefined;
32
+ list?: boolean | undefined;
30
33
  index?: boolean | undefined;
31
34
  depth?: number | "all" | undefined;
32
35
  detail?: "compact" | "full" | "brief" | undefined;
@@ -78,6 +78,12 @@ export const doc = {
78
78
  description:
79
79
  'Return the token-efficient dense doc variant. It is written to be read whole, so it returns the whole doc.',
80
80
  },
81
+ {
82
+ name: 'options.list',
83
+ type: 'boolean',
84
+ description:
85
+ 'Return the topic list, the same as giving no topic. It takes no topic or section.',
86
+ },
81
87
  {
82
88
  name: 'options.index',
83
89
  type: 'boolean',
@@ -133,7 +139,7 @@ export const doc = {
133
139
  throws: [
134
140
  {
135
141
  code: 'ERR_INVALID_ARGUMENT',
136
- when: "depth is not a whole number of levels or 'all'",
142
+ when: "depth is not a whole number of levels or 'all', or list is set with a topic or section",
137
143
  },
138
144
  {
139
145
  code: 'ERR_INVALID_DETAIL',
package/api/docs/docs.mjs CHANGED
@@ -13,6 +13,9 @@
13
13
  * docs(route) -> node -> docs.node
14
14
  * docs(route, undefined, {depth: 2}) -> node -> docs.node, two levels
15
15
  *
16
+ * `list` names the list read. It is the same as no topic, so docs() refuses
17
+ * a topic or section beside it instead of dropping it.
18
+ *
16
19
  * A topic read returns the whole doc, as it always has; `index` returns its
17
20
  * sections, so a reader can open one by its key (spec:AST-047). The CLI's text
18
21
  * view lists the sections by default. A route names a node
@@ -114,6 +117,8 @@ function depthRead(options) {
114
117
  * @param {string} [options.lang]
115
118
  * @param {boolean} [options.zh]
116
119
  * @param {boolean} [options.dense]
120
+ * @param {boolean} [options.list] return the topic list, the same as giving
121
+ * no topic; docs() refuses a topic or section beside it
117
122
  * @param {boolean} [options.index] return the topic's section index instead of
118
123
  * the whole doc
119
124
  * @param {number | 'all'} [options.depth] how many levels below a docs-tree
@@ -148,6 +153,13 @@ export async function docs(topic, section, options = {}) {
148
153
  */
149
154
  async function docsRead(topic, section, options = {}) {
150
155
  const read = depthRead(options);
156
+ if (options.list && (topic || section)) {
157
+ throw new AstryxError(
158
+ 'Ask for the topic list or one topic, not both: --list takes no topic or section.',
159
+ undefined,
160
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
161
+ );
162
+ }
151
163
  if (!topic) return list(options);
152
164
  const found = await resolveDocsArgument(topic, options);
153
165
  if (found.kind === 'node') {
@@ -376,6 +376,11 @@ export type DocsOptions = {
376
376
  lang?: string | undefined;
377
377
  zh?: boolean | undefined;
378
378
  dense?: boolean | undefined;
379
+ /**
380
+ * return the topic list, the same as giving no
381
+ * topic; docs() refuses a topic or section beside it
382
+ */
383
+ list?: boolean | undefined;
379
384
  /**
380
385
  * return a topic's section index instead of its
381
386
  * whole doc
@@ -245,6 +245,8 @@
245
245
  * @property {string} [lang]
246
246
  * @property {boolean} [zh]
247
247
  * @property {boolean} [dense]
248
+ * @property {boolean} [list] return the topic list, the same as giving no
249
+ * topic; docs() refuses a topic or section beside it
248
250
  * @property {boolean} [index] return a topic's section index instead of its
249
251
  * whole doc
250
252
  * @property {number | 'all'} [depth] how many levels below a docs-tree
@@ -295,7 +295,7 @@ export function typedEdges(tree, node) {
295
295
  export async function node(route, options = {}) {
296
296
  const found = await resolveDocsArgument(route, options);
297
297
  if (found.kind !== 'node')
298
- throw await unknownTopicError(route, found.catalog);
298
+ throw await unknownTopicError(route, found.catalog, options);
299
299
  return {
300
300
  type: 'docs.node',
301
301
  // The docs tree names each node's npm package as its provider.
@@ -5,19 +5,26 @@
5
5
  * A doctor check that reads only files, kept between runs through the kept
6
6
  * gather (foundation/fs/gather-cache.mjs): a later `doctor` with every file,
7
7
  * folder, module and environment variable it read unchanged reads the check
8
- * back. Only the docs checks go through here; a check that depends on the
9
- * time, the network or anything else the stamps do not see never does.
8
+ * back. Only the docs checks and the theme-wiring scan go through here; a
9
+ * check that depends on the time, the network or anything else the stamps do
10
+ * not see never does.
10
11
  * @template T
11
12
  * @param {{name: string, cwd: string, coreDir: string | null}} where - The
12
13
  * check, the project folder, and the Core folder the project loads.
13
14
  * @param {() => Promise<T>} check
15
+ * @param {{encode: (value: any) => any, decode: (stored: any) => any, valid?: (value: any) => boolean}} [codec]
16
+ * How the value is kept: a check record unless given.
14
17
  * @returns {Promise<T>}
15
18
  */
16
19
  export function keptFileCheck<T>({ name, cwd, coreDir }: {
17
20
  name: string;
18
21
  cwd: string;
19
22
  coreDir: string | null;
20
- }, check: () => Promise<T>): Promise<T>;
23
+ }, check: () => Promise<T>, codec?: {
24
+ encode: (value: any) => any;
25
+ decode: (stored: any) => any;
26
+ valid?: (value: any) => boolean;
27
+ }): Promise<T>;
21
28
  /**
22
29
  * Package written to the generated app record for one discovered theme.
23
30
  * @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
@@ -88,6 +95,16 @@ export function doctorElementPropOrigins(file: string, element: Parameters<typeo
88
95
  * @returns {Set<string>}
89
96
  */
90
97
  export function doctorStylesheetImports(css: string): Set<string>;
98
+ /**
99
+ * The file a local stylesheet `@import` names, from the stylesheet that
100
+ * imports it: a relative path, or a package's file as Node resolves it
101
+ * (`@fontsource/inter/index.css`). Null for a URL (http, https, `//`) or an
102
+ * import that does not resolve.
103
+ * @param {string} specifier
104
+ * @param {string} fromFile
105
+ * @returns {string | null}
106
+ */
107
+ export function doctorStylesheetImportFile(specifier: string, fromFile: string): string | null;
91
108
  /**
92
109
  * The `@astryxdesign/core` range a package's peerDependencies declare, and
93
110
  * whether it accepts `coreVersion` (spec:AST-017/FR12). The one rule every
@@ -284,7 +301,13 @@ export function builtIntegrationPackages(target: string, cwd: string): string[];
284
301
  export { placeholderFixes } from "../../foundation/discovery/template-icons.mjs";
285
302
  export { installCommandFor as packageInstallCommand } from "../../foundation/discovery/template-needs.mjs";
286
303
  export { resolveRecordedTheme } from "../theme/theme.mjs";
304
+ export { themeIdentifier } from "../theme/_fork.mjs";
287
305
  export { collectUnloadedFonts } from "../theme/build/font-warning.mjs";
306
+ export namespace THEME_WIRING_CODEC {
307
+ function encode(value: any): any;
308
+ function decode(value: any): any;
309
+ function valid(value: any): any;
310
+ }
288
311
  export const SOURCE_EXTENSIONS: Set<string>;
289
312
  export { displayHomePath };
290
313
  /** `doctor --built` reads at most this many files, of at most this size. */
@@ -299,6 +322,5 @@ import { stateLockHolder } from '../../foundation/release/global-state.mjs';
299
322
  import { displayHomePath } from '../../foundation/agent-docs/computer-agent-text.mjs';
300
323
  export { iconUseCommand, unlistedIconSets } from "../../foundation/discovery/icon-set-discovery.mjs";
301
324
  export { isLocalThemeOwner, planThemeAppWrite, readThemeState, resolveThemeModule } from "../../foundation/config/theme-state.mjs";
302
- export { GENERATED_MARKER, isPrivateVarRefusal, missingThemePackage, themeBuild, validateThemePrivateInputs } from "../theme/build/build.mjs";
303
- export { APP_COPY_MARK, EDITOR_GENERATED_MARK } from "../theme-edit/_marks.mjs";
325
+ export { fileMark, generatedSourceCommand, isPrivateVarRefusal, missingThemePackage, themeBuild, validateThemePrivateInputs } from "../theme/build/build.mjs";
304
326
  export { AUTHORING_AUDIT, authoringAudit, authoringAuditData } from "./_authoring-audit.mjs";