@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
@@ -0,0 +1,264 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Whether a component or hook can carry a name, read without loading
5
+ * any doc: from Core's file and folder names, and from integrations' doc file
6
+ * names and the words in those docs' text. Each is a summary kept between
7
+ * runs while those folders and docs are unchanged (../fs/kept-tree.mjs).
8
+ *
9
+ * @input Core's folder or integrations' components folders, and a name
10
+ * folded as a reader may type it ({@link foldEntryName})
11
+ * @output false only when discovery lists no component or hook there whose
12
+ * folded name is that name; for Core, the top folders that can hold one
13
+ * @position foundation/discovery: lets the docs not-found error skip
14
+ * component and hook discovery for a name no Core file or folder name, and
15
+ * no integration doc's file name or text, carries
16
+ */
17
+
18
+ import * as fs from 'node:fs';
19
+ import * as path from 'node:path';
20
+ import {fileURLToPath} from 'node:url';
21
+ import {hasNameLine, keptTreeSummary, nameLines} from '../fs/kept-tree.mjs';
22
+
23
+ /** A component doc's suffix, as integration discovery reads it. */
24
+ const INTEGRATION_DOC_RE = /\.doc\.(ts|mjs|js)$/;
25
+
26
+ /**
27
+ * A name as a reader may type it: case, spaces and hyphens do not count.
28
+ * @param {string} name
29
+ * @returns {string}
30
+ */
31
+ export function foldEntryName(name) {
32
+ return name.toLowerCase().replace(/[\s-]+/g, '');
33
+ }
34
+
35
+ /**
36
+ * Visit each file and folder under `dir`, outside `node_modules`, until
37
+ * `visit` returns true.
38
+ * @param {string} dir
39
+ * @param {(name: string, dir: string, isDir: boolean) => boolean} visit
40
+ * @returns {boolean} whether a visit returned true
41
+ */
42
+ function walkUntil(dir, visit) {
43
+ let entries;
44
+ try {
45
+ entries = fs.readdirSync(dir, {withFileTypes: true});
46
+ } catch {
47
+ return false;
48
+ }
49
+ for (const entry of entries) {
50
+ if (entry.name === 'node_modules') continue;
51
+ const isDir = entry.isDirectory();
52
+ if (visit(entry.name, dir, isDir)) return true;
53
+ if (isDir && walkUntil(path.join(dir, entry.name), visit)) return true;
54
+ }
55
+ return false;
56
+ }
57
+
58
+ /** This module's own file: its code decides the kept summaries' shape. */
59
+ const OWN_FILE = fileURLToPath(import.meta.url);
60
+
61
+ /**
62
+ * The folded names Core's files and folders give, each with a top folder of
63
+ * `src` that holds one, as lines ({@link nameLines}) of `<kind><name>\t<top>`:
64
+ * kind `t` for a `.tsx` stem (a component), `o` for a `.doc.mjs` stem (a
65
+ * hook), `d` for a folder name (a component). A file directly in `src` is
66
+ * under the top folder `''`, and a top folder under its own name. A folded
67
+ * name holds no white space, so a tab ends it.
68
+ * @param {string} coreDir
69
+ * @returns {string | string[]}
70
+ */
71
+ function coreNameIndex(coreDir) {
72
+ return keptTreeSummary(
73
+ {
74
+ kind: 'core-entry-names',
75
+ roots: [path.join(coreDir, 'src')],
76
+ code: [OWN_FILE],
77
+ skip: name => name === 'node_modules',
78
+ },
79
+ ([{folders}]) => {
80
+ /** @type {string[]} */
81
+ const lines = [];
82
+ for (const {rel, entries} of folders) {
83
+ const top = rel === '' ? '' : rel.split(path.sep)[0];
84
+ for (const {name, isDir} of entries) {
85
+ if (isDir) {
86
+ if (name !== 'node_modules') {
87
+ lines.push(`d${foldEntryName(name)}\t${rel === '' ? name : top}`);
88
+ }
89
+ } else if (name.endsWith('.doc.mjs')) {
90
+ const stem = name.slice(0, -'.doc.mjs'.length);
91
+ lines.push(`o${foldEntryName(stem)}\t${top}`);
92
+ } else if (name.endsWith('.tsx')) {
93
+ lines.push(
94
+ `t${foldEntryName(name.slice(0, -'.tsx'.length))}\t${top}`,
95
+ );
96
+ }
97
+ }
98
+ }
99
+ return nameLines(lines);
100
+ },
101
+ );
102
+ }
103
+
104
+ /**
105
+ * The tops the index lines that start with `prefix` name.
106
+ * @param {string | string[]} lines
107
+ * @param {string} prefix
108
+ * @returns {string[]}
109
+ */
110
+ function topsAfter(lines, prefix) {
111
+ if (typeof lines !== 'string') {
112
+ return lines
113
+ .filter(line => line.startsWith(prefix))
114
+ .map(line => line.slice(prefix.length));
115
+ }
116
+ const needle = `\n${prefix}`;
117
+ const tops = [];
118
+ for (
119
+ let at = lines.indexOf(needle);
120
+ at >= 0;
121
+ at = lines.indexOf(needle, at + 1)
122
+ ) {
123
+ const start = at + needle.length;
124
+ tops.push(lines.slice(start, lines.indexOf('\n', start)));
125
+ }
126
+ return tops;
127
+ }
128
+
129
+ /**
130
+ * Which Core entries can fold to `wanted`. Every Core component takes its
131
+ * name from a `.tsx` file (without an `XDS` prefix) or a folder, and every
132
+ * hook from its doc's file name, so a name no such file carries is neither.
133
+ * @param {string} coreDir
134
+ * @param {string} wanted a folded name
135
+ * @returns {{component: boolean, hook: boolean, componentTops: Set<string>, hookTops: Set<string>}}
136
+ * `hook` also counts a hook named `use` + `wanted`; the tops are the top
137
+ * folders of `src` that hold such a file or folder
138
+ */
139
+ export function coreFilesNaming(coreDir, wanted) {
140
+ const index = coreNameIndex(coreDir);
141
+ const componentTops = new Set([
142
+ ...topsAfter(index, `t${wanted}\t`),
143
+ ...topsAfter(index, `txds${wanted}\t`),
144
+ ...topsAfter(index, `d${wanted}\t`),
145
+ ]);
146
+ const hookTops = new Set([
147
+ ...topsAfter(index, `o${wanted}\t`),
148
+ ...topsAfter(index, `ouse${wanted}\t`),
149
+ ]);
150
+ return {
151
+ component: componentTops.size > 0,
152
+ hook: hookTops.size > 0,
153
+ componentTops,
154
+ hookTops,
155
+ };
156
+ }
157
+
158
+ /** A name a doc's text can spell: a run of word characters. */
159
+ const WORD_RE = /[A-Za-z0-9_$]+/g;
160
+
161
+ /**
162
+ * What each integration's component docs can name: each doc's folded file
163
+ * stem, and each word in its text, in lower case. `unreadable` when a doc
164
+ * could not be read.
165
+ * @param {string[]} componentsDirs
166
+ * @returns {Array<{stems: string | string[], words: string | string[], unreadable: boolean}>}
167
+ */
168
+ function integrationNameIndexes(componentsDirs) {
169
+ return keptTreeSummary(
170
+ {
171
+ kind: 'integration-component-names',
172
+ roots: componentsDirs,
173
+ code: [OWN_FILE],
174
+ // Integration discovery reads no doc in these folders.
175
+ skip: name => name === 'node_modules' || name === '__tests__',
176
+ },
177
+ trees =>
178
+ trees.map(({folders, readText}) => {
179
+ const stems = new Set();
180
+ const words = new Set();
181
+ let unreadable = false;
182
+ for (const {rel, entries} of folders) {
183
+ for (const {name, isDir} of entries) {
184
+ if (isDir || !INTEGRATION_DOC_RE.test(name)) continue;
185
+ stems.add(foldEntryName(name.replace(INTEGRATION_DOC_RE, '')));
186
+ let text;
187
+ try {
188
+ text = readText(rel === '' ? name : path.join(rel, name));
189
+ } catch {
190
+ unreadable = true;
191
+ continue;
192
+ }
193
+ for (const word of text.match(WORD_RE) ?? []) {
194
+ words.add(word.toLowerCase());
195
+ }
196
+ }
197
+ }
198
+ return {stems: nameLines(stems), words: nameLines(words), unreadable};
199
+ }),
200
+ );
201
+ }
202
+
203
+ /**
204
+ * Whether an integration component can fold to `wanted`, for each
205
+ * components folder in order. Integration discovery names a component after
206
+ * its doc's file, or after a name the doc spells out (its export, or a family
207
+ * member), so a doc whose file name and text both lack the name lists no
208
+ * such component.
209
+ * @param {Array<string | undefined>} componentsDirs
210
+ * @param {string} wanted a folded name
211
+ * @returns {boolean[]}
212
+ */
213
+ export function integrationsFilesNaming(componentsDirs, wanted) {
214
+ // A name of word characters alone is a whole word of the text exactly when
215
+ // it is one of the text's words: the kept index answers it.
216
+ if (!/^[a-z0-9_$]+$/.test(wanted)) {
217
+ return componentsDirs.map(dir => !!dir && docsSpell(dir, wanted));
218
+ }
219
+ const dirs = componentsDirs.flatMap(dir => (dir ? [dir] : []));
220
+ const indexes = dirs.length > 0 ? integrationNameIndexes(dirs) : [];
221
+ let at = 0;
222
+ return componentsDirs.map(dir => {
223
+ if (!dir) return false;
224
+ const {stems, words, unreadable} = indexes[at++];
225
+ return (
226
+ unreadable || hasNameLine(stems, wanted) || hasNameLine(words, wanted)
227
+ );
228
+ });
229
+ }
230
+
231
+ /**
232
+ * {@link integrationsFilesNaming} for one components folder.
233
+ * @param {string | undefined} componentsDir
234
+ * @param {string} wanted a folded name
235
+ * @returns {boolean}
236
+ */
237
+ export function integrationFilesNaming(componentsDir, wanted) {
238
+ return integrationsFilesNaming([componentsDir], wanted)[0];
239
+ }
240
+
241
+ /**
242
+ * Whether a component doc under `componentsDir` has a file stem that folds to
243
+ * `wanted`, or text that holds it as a whole word, read from the disk.
244
+ * @param {string} componentsDir
245
+ * @param {string} wanted a folded name
246
+ * @returns {boolean}
247
+ */
248
+ function docsSpell(componentsDir, wanted) {
249
+ const token = new RegExp(
250
+ `(?<![\\w$])${wanted.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![\\w$])`,
251
+ 'i',
252
+ );
253
+ return walkUntil(componentsDir, (name, dir, isDir) => {
254
+ if (isDir || !INTEGRATION_DOC_RE.test(name)) return false;
255
+ if (foldEntryName(name.replace(INTEGRATION_DOC_RE, '')) === wanted) {
256
+ return true;
257
+ }
258
+ try {
259
+ return token.test(fs.readFileSync(path.join(dir, name), 'utf8'));
260
+ } catch {
261
+ return true;
262
+ }
263
+ });
264
+ }
@@ -7,9 +7,13 @@
7
7
  * Categories from HookDoc.category: focus, layout, animation, interaction, data, media, streaming
8
8
  * Hooks without a category go in 'Other'.
9
9
  * @param {string} coreDir
10
+ * @param {(name: string) => boolean} [keep] the hooks to read; the others are
11
+ * left out, and their docs are not read
12
+ * @param {Set<string>} [tops] the top folders of `src` outside `hooks` to
13
+ * read, when only these can hold a hook `keep` accepts
10
14
  * @returns {Record<string, string[]>}
11
15
  */
12
- export function discoverHooks(coreDir: string): Record<string, string[]>;
16
+ export function discoverHooks(coreDir: string, keep?: (name: string) => boolean, tops?: Set<string>): Record<string, string[]>;
13
17
  /**
14
18
  * Find the .doc.mjs file for a hook by name.
15
19
  * Searches hooks/ directory and component directories.
@@ -23,6 +27,8 @@ export function findHookDoc(coreDir: string, name: string): string | null;
23
27
  /**
24
28
  * Get all discovered hook names as a flat array (for fuzzy matching).
25
29
  * @param {string} coreDir
30
+ * @param {(name: string) => boolean} [keep] as for {@link discoverHooks}
31
+ * @param {Set<string>} [tops] as for {@link discoverHooks}
26
32
  * @returns {string[]}
27
33
  */
28
- export function getAllHookNames(coreDir: string): string[];
34
+ export function getAllHookNames(coreDir: string, keep?: (name: string) => boolean, tops?: Set<string>): string[];
@@ -74,9 +74,13 @@ function hookNameFromFile(fileName) {
74
74
  * Categories from HookDoc.category: focus, layout, animation, interaction, data, media, streaming
75
75
  * Hooks without a category go in 'Other'.
76
76
  * @param {string} coreDir
77
+ * @param {(name: string) => boolean} [keep] the hooks to read; the others are
78
+ * left out, and their docs are not read
79
+ * @param {Set<string>} [tops] the top folders of `src` outside `hooks` to
80
+ * read, when only these can hold a hook `keep` accepts
77
81
  * @returns {Record<string, string[]>}
78
82
  */
79
- export function discoverHooks(coreDir) {
83
+ export function discoverHooks(coreDir, keep = () => true, tops) {
80
84
  const srcDir = path.join(coreDir, 'src');
81
85
  const hooksDir = path.join(srcDir, 'hooks');
82
86
 
@@ -90,6 +94,7 @@ export function discoverHooks(coreDir) {
90
94
  if (!entry.isFile()) continue;
91
95
  if (!entry.name.endsWith('.doc.mjs')) continue;
92
96
  const hookName = hookNameFromFile(entry.name);
97
+ if (!keep(hookName)) continue;
93
98
  const docPath = path.join(hooksDir, entry.name);
94
99
  const {category} = readHookMeta(docPath);
95
100
  hookCategories.set(hookName, category || 'Other');
@@ -102,8 +107,9 @@ export function discoverHooks(coreDir) {
102
107
  const topEntries = listDirEntries(srcDir);
103
108
  for (const entry of topEntries) {
104
109
  if (!entry.isDirectory() || SKIP_DIRS.has(entry.name) || entry.name === 'hooks') continue;
110
+ if (tops && !tops.has(entry.name)) continue;
105
111
  const dirPath = path.join(srcDir, entry.name);
106
- scanDirForHookDocs(dirPath, hookCategories);
112
+ scanDirForHookDocs(dirPath, hookCategories, keep);
107
113
  }
108
114
  }
109
115
 
@@ -140,17 +146,22 @@ export function discoverHooks(coreDir) {
140
146
  * Recursively scan a directory for use*.doc.mjs files.
141
147
  * @param {string} dirPath
142
148
  * @param {Map<string, string>} hookCategories
149
+ * @param {(name: string) => boolean} keep
143
150
  */
144
- function scanDirForHookDocs(dirPath, hookCategories) {
151
+ function scanDirForHookDocs(dirPath, hookCategories, keep) {
145
152
  if (!pathExists(dirPath)) return;
146
153
  const entries = listDirEntries(dirPath);
147
154
  for (const entry of entries) {
148
155
  if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) {
149
- scanDirForHookDocs(path.join(dirPath, entry.name), hookCategories);
156
+ scanDirForHookDocs(path.join(dirPath, entry.name), hookCategories, keep);
150
157
  } else if (entry.isFile() && HOOK_DOC_FILE_RE.test(entry.name)) {
151
158
  const hookName = hookNameFromFile(entry.name);
152
159
  const docPath = path.join(dirPath, entry.name);
153
- if (!hookCategories.has(hookName) && !isBesideOwnHook(docPath, hookName)) {
160
+ if (
161
+ keep(hookName) &&
162
+ !hookCategories.has(hookName) &&
163
+ !isBesideOwnHook(docPath, hookName)
164
+ ) {
154
165
  const {category} = readHookMeta(docPath);
155
166
  hookCategories.set(hookName, category || 'Other');
156
167
  }
@@ -258,9 +269,11 @@ function searchDirForHookDoc(dirPath, candidates) {
258
269
  /**
259
270
  * Get all discovered hook names as a flat array (for fuzzy matching).
260
271
  * @param {string} coreDir
272
+ * @param {(name: string) => boolean} [keep] as for {@link discoverHooks}
273
+ * @param {Set<string>} [tops] as for {@link discoverHooks}
261
274
  * @returns {string[]}
262
275
  */
263
- export function getAllHookNames(coreDir) {
264
- const hooks = discoverHooks(coreDir);
276
+ export function getAllHookNames(coreDir, keep, tops) {
277
+ const hooks = discoverHooks(coreDir, keep, tops);
265
278
  return Object.values(hooks).flat();
266
279
  }
@@ -1,6 +1,16 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * The target one subpath of a package's exports maps to under a list of
6
+ * conditions, its wildcard filled in, as written in the package (`./x`).
7
+ * Null when the package exports no such subpath.
8
+ * @param {unknown} exportsField
9
+ * @param {string} subpath `.` or a `./`-prefixed subpath
10
+ * @param {readonly string[]} conditions
11
+ * @returns {string|null}
12
+ */
13
+ export function conditionalExportTarget(exportsField: unknown, subpath: string, conditions: readonly string[]): string | null;
4
14
  /**
5
15
  * The file a subpath's `source` condition names, when that file is in the
6
16
  * package. A package that ships its source (or a workspace package before it
@@ -8,8 +8,9 @@
8
8
  * their legacy public deep paths and are resolved from files on disk.
9
9
  *
10
10
  * @input Parsed package.json, package directory, and a public subpath
11
- * @output The public specifier and confined target file, when exported, and
12
- * the file a subpath's `source` condition names, when the package has it
11
+ * @output The public specifier and confined target file, when exported, the
12
+ * file a subpath's `source` condition names, when the package has it, and
13
+ * the target a subpath maps to under given conditions
13
14
  * @position packages/cli/foundation/discovery — shared package import metadata
14
15
  */
15
16
 
@@ -61,6 +62,16 @@ function targetString(value) {
61
62
  return null;
62
63
  }
63
64
 
65
+ /**
66
+ * The order Node and TypeScript try export patterns in: the longer part
67
+ * before the `*` first, then the longer key.
68
+ * @param {string} a
69
+ * @param {string} b
70
+ */
71
+ function patternKeyCompare(a, b) {
72
+ return b.indexOf('*') - a.indexOf('*') || b.length - a.length;
73
+ }
74
+
64
75
  /**
65
76
  * Find an exact or one-star subpath mapping and the wildcard value it matched.
66
77
  * @param {Record<string, unknown>} map
@@ -72,7 +83,7 @@ function subpathValue(map, subpath) {
72
83
  }
73
84
  const patterns = Object.keys(map)
74
85
  .filter(key => key.startsWith('./') && key.split('*').length === 2)
75
- .sort((a, b) => b.length - a.length);
86
+ .sort(patternKeyCompare);
76
87
  for (const pattern of patterns) {
77
88
  const star = pattern.indexOf('*');
78
89
  const prefix = pattern.slice(0, star);
@@ -186,6 +197,48 @@ function rawExportValue(exportsField, subpath) {
186
197
  : null;
187
198
  }
188
199
 
200
+ /**
201
+ * Select one string target under a list of conditions, matched in the order
202
+ * the export object lists them, as Node and TypeScript match them; `default`
203
+ * always matches.
204
+ * @param {unknown} value
205
+ * @param {readonly string[]} conditions
206
+ * @returns {string|null}
207
+ */
208
+ function conditionTarget(value, conditions) {
209
+ if (typeof value === 'string') return value;
210
+ if (Array.isArray(value)) {
211
+ for (const item of value) {
212
+ const selected = conditionTarget(item, conditions);
213
+ if (selected) return selected;
214
+ }
215
+ return null;
216
+ }
217
+ if (!isRecord(value)) return null;
218
+ for (const [key, item] of Object.entries(value)) {
219
+ if (key !== 'default' && !conditions.includes(key)) continue;
220
+ const selected = conditionTarget(item, conditions);
221
+ if (selected) return selected;
222
+ }
223
+ return null;
224
+ }
225
+
226
+ /**
227
+ * The target one subpath of a package's exports maps to under a list of
228
+ * conditions, its wildcard filled in, as written in the package (`./x`).
229
+ * Null when the package exports no such subpath.
230
+ * @param {unknown} exportsField
231
+ * @param {string} subpath `.` or a `./`-prefixed subpath
232
+ * @param {readonly string[]} conditions
233
+ * @returns {string|null}
234
+ */
235
+ export function conditionalExportTarget(exportsField, subpath, conditions) {
236
+ const selected = rawExportValue(exportsField, subpath);
237
+ if (!selected) return null;
238
+ const target = conditionTarget(selected.value, conditions);
239
+ return target === null ? null : target.replaceAll('*', selected.wildcard);
240
+ }
241
+
189
242
  /**
190
243
  * The file a subpath's `source` condition names, when that file is in the
191
244
  * package. A package that ships its source (or a workspace package before it
@@ -32,6 +32,7 @@ export const RUNNER_COMMAND_ALLOWLIST: Readonly<{
32
32
  'packages/cli/assets/docs/tree/cli-command.doc.mjs': "explains how printed commands start, the pinned `npx @astryxdesign/cli@<version>` among them";
33
33
  'packages/cli/assets/docs/tree/who-answers.doc.mjs': "explains how printed commands start, the pinned `npx @astryxdesign/cli@<version>` among them";
34
34
  'packages/cli/assets/docs/tree/project-global-or-both.doc.mjs': "compares running the CLI with npx to installing it, and is found by searching for that command";
35
+ 'packages/cli/assets/docs/tree/render-pages.doc.mjs': "quotes the note a rendered file opens with, whose commands are pinned to `npx @astryxdesign/cli@<version>`";
35
36
  'packages/cli/assets/docs/tree/install-once.doc.mjs': "names a pinned release, `npx @astryxdesign/cli@<version>`, which answers as that version";
36
37
  'packages/cli/assets/docs/tree/doc-syntax.doc.mjs': "shows what each doc token renders as, in every package manager";
37
38
  'packages/cli/assets/docs/tree/add-a-topic.doc.mjs': "shows what a reader sees for a command token, with their runner";
@@ -43,6 +43,8 @@ export const RUNNER_COMMAND_ALLOWLIST = Object.freeze({
43
43
  'explains how printed commands start, the pinned `npx @astryxdesign/cli@<version>` among them',
44
44
  'packages/cli/assets/docs/tree/project-global-or-both.doc.mjs':
45
45
  'compares running the CLI with npx to installing it, and is found by searching for that command',
46
+ 'packages/cli/assets/docs/tree/render-pages.doc.mjs':
47
+ 'quotes the note a rendered file opens with, whose commands are pinned to `npx @astryxdesign/cli@<version>`',
46
48
  'packages/cli/assets/docs/tree/install-once.doc.mjs':
47
49
  'names a pinned release, `npx @astryxdesign/cli@<version>`, which answers as that version',
48
50
  'packages/cli/assets/docs/tree/doc-syntax.doc.mjs':
@@ -158,6 +158,31 @@ export function listTemplates(): string[];
158
158
  * @returns {string | null}
159
159
  */
160
160
  export function findPageDocFile(dirPath: string): string | null;
161
+ /**
162
+ * The ids of Core's templates that `keep` accepts, read from file names: each
163
+ * page folder, and each block doc that has its same-stem source. Discovery
164
+ * gives Core's templates exactly these ids. Only a kept block's source is
165
+ * looked for.
166
+ * @param {(id: string) => boolean} [keep]
167
+ * @returns {string[]}
168
+ */
169
+ export function coreTemplateIds(keep?: (id: string) => boolean): string[];
170
+ /**
171
+ * Which template files can give an id that folds to `wanted`, read from a
172
+ * kept summary of file names: `blocks` false means {@link coreTemplateIds}
173
+ * gives no block id that folds to it, and `listed` says whether any of the
174
+ * integrations ships a template doc whose id ({@link integrationTemplateIds})
175
+ * folds to it.
176
+ * @param {Array<{templates?: string}>} integrations
177
+ * @param {string} wanted a folded name
178
+ * @returns {{blocks: boolean, listed: boolean}}
179
+ */
180
+ export function templateFilesNaming(integrations: Array<{
181
+ templates?: string;
182
+ }>, wanted: string): {
183
+ blocks: boolean;
184
+ listed: boolean;
185
+ };
161
186
  /**
162
187
  * Discover only the templates built into @astryxdesign/core. Integration
163
188
  * authoring checks use this narrower surface so a broken project config or a
@@ -214,6 +239,33 @@ export function discoverAllWithErrors(cwd?: string): Promise<{
214
239
  templates: DiscoveredTemplate[];
215
240
  errors: Array<TemplateDiscoveryError | TemplateReplacementError>;
216
241
  }>;
242
+ /**
243
+ * The id of each template doc an integration ships, valid or not, read from
244
+ * file names alone.
245
+ * @param {{templates?: string}} integration
246
+ * @returns {string[]}
247
+ */
248
+ export function integrationTemplateIds(integration: {
249
+ templates?: string;
250
+ }): string[];
251
+ /**
252
+ * Whether any template doc an integration ships can declare a replacement,
253
+ * read from its text without loading it.
254
+ * @param {{templates?: string}} integration
255
+ * @returns {boolean}
256
+ */
257
+ export function integrationMayReplaceTemplate(integration: {
258
+ templates?: string;
259
+ }): boolean;
260
+ /**
261
+ * Whether any template doc any of the integrations ships can declare a
262
+ * replacement, read from a kept summary of the docs' text.
263
+ * @param {Array<{templates?: string}>} integrations
264
+ * @returns {boolean}
265
+ */
266
+ export function integrationsMayReplaceTemplate(integrations: Array<{
267
+ templates?: string;
268
+ }>): boolean;
217
269
  /**
218
270
  * Discover the templates contributed by a SINGLE integration. Same per-template
219
271
  * rules as {@link discoverIntegrationTemplates} (same-stem source required,