@astryxdesign/cli 0.7.16 → 0.7.17-canary.g9a957aa

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 (229) hide show
  1. package/README.md +12 -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 +47 -9
  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 +32 -0
  14. package/api/build/kit/words.mjs +49 -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 +48 -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 +491 -186
  34. package/api/render/render.doc.mjs +10 -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 +38 -0
  46. package/api/theme/build/build.mjs +144 -24
  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 +35 -0
  50. package/api/theme-edit/_adapter.mjs +477 -41
  51. package/api/theme-edit/_check.d.mts +28 -22
  52. package/api/theme-edit/_check.mjs +1077 -200
  53. package/api/theme-edit/_compiler.mjs +9 -0
  54. package/api/theme-edit/_context.mjs +60 -3
  55. package/api/theme-edit/_css.mjs +21 -1
  56. package/api/theme-edit/_edit.d.mts +22 -0
  57. package/api/theme-edit/_edit.mjs +932 -82
  58. package/api/theme-edit/_how-commands.d.mts +49 -0
  59. package/api/theme-edit/_how-commands.mjs +386 -1
  60. package/api/theme-edit/_how-question.d.mts +56 -0
  61. package/api/theme-edit/_how-question.mjs +3509 -168
  62. package/api/theme-edit/_how.mjs +104 -4
  63. package/api/theme-edit/_marks.d.mts +31 -5
  64. package/api/theme-edit/_marks.mjs +57 -5
  65. package/api/theme-edit/_normal.d.mts +137 -0
  66. package/api/theme-edit/_normal.mjs +612 -0
  67. package/api/theme-edit/_palette.mjs +10 -4
  68. package/api/theme-edit/_parts.d.mts +4 -0
  69. package/api/theme-edit/_parts.mjs +28 -2
  70. package/api/theme-edit/_preview-app.d.mts +7 -1
  71. package/api/theme-edit/_preview-app.mjs +191 -15
  72. package/api/theme-edit/_preview.d.mts +64 -8
  73. package/api/theme-edit/_preview.mjs +401 -83
  74. package/api/theme-edit/_settings.d.mts +139 -5
  75. package/api/theme-edit/_settings.mjs +1659 -112
  76. package/api/theme-edit/_tables.mjs +17 -1
  77. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  78. package/api/theme-edit/theme-edit.type.mjs +4 -1
  79. package/api/theme-edit/themeEditPreviewApp.doc.mjs +2 -2
  80. package/assets/codemods/run-codemod.mjs +73 -6
  81. package/assets/codemods/transforms/next/index.mjs +11 -1
  82. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  83. package/assets/docs/author-a-theme.doc.mjs +1 -0
  84. package/assets/docs/theme.doc.dense.mjs +2 -2
  85. package/assets/docs/theme.doc.mjs +1 -1
  86. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  87. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  88. package/assets/docs/tree/render-pages.doc.mjs +43 -2
  89. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  90. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  91. package/assets/docs/use-a-theme.doc.mjs +1 -1
  92. package/assets/docs.generated.json +2 -2
  93. package/assets/self-audit.generated.json +1 -1
  94. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  95. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  96. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  97. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  98. package/assets/templates/components.generated.json +1 -1
  99. package/assets/templates/pages/ai-chat/template.doc.mjs +8 -4
  100. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  101. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  102. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  103. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  104. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  105. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  106. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  107. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  108. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  109. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  110. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  111. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  112. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  113. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  114. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  115. package/assets/templates/pages/editor/template.doc.mjs +1 -7
  116. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  117. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  118. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  119. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  120. package/assets/templates/pages/ide/page.tsx +24 -2
  121. package/assets/templates/pages/library/template.doc.mjs +4 -1
  122. package/assets/templates/pages/login/template.doc.mjs +2 -1
  123. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  124. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  125. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  126. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  127. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  128. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  129. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  130. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  131. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  132. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  133. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  134. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  135. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  136. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  137. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  138. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  139. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -1
  140. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  141. package/authoring/debug/parse.d.mts +3 -3
  142. package/authoring/doctypes/_schema.d.mts +3 -3
  143. package/authoring/doctypes/command/command.doc.mjs +1 -1
  144. package/authoring/doctypes/template/template.doc.mjs +1 -1
  145. package/authoring/doctypes/template/type.ts +9 -0
  146. package/clients/cli/bin/astryx.mjs +6 -9
  147. package/clients/cli/build-id.generated.json +1 -1
  148. package/clients/cli/commands/component.doc.mjs +1 -1
  149. package/clients/cli/commands/component.mjs +20 -2
  150. package/clients/cli/commands/docs.doc.mjs +7 -1
  151. package/clients/cli/commands/docs.mjs +3 -1
  152. package/clients/cli/commands/doctor.mjs +22 -14
  153. package/clients/cli/commands/experimental/render.mjs +32 -1
  154. package/clients/cli/commands/experimental/theme.mjs +27 -2
  155. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  156. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  157. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  158. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  159. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  160. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  161. package/clients/cli/commands/search.doc.mjs +2 -1
  162. package/clients/cli/commands/search.mjs +6 -1
  163. package/clients/cli/commands/template.mjs +4 -2
  164. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  165. package/clients/cli/commands/theme.doc.mjs +1 -1
  166. package/clients/cli/commands/theme.mjs +138 -3
  167. package/clients/cli/commands/upgrade.mjs +42 -7
  168. package/clients/cli/index.mjs +1 -1
  169. package/clients/cli/lib/component-format.mjs +205 -98
  170. package/clients/cli/lib/hook-format.mjs +9 -19
  171. package/clients/cli/manifest.generated.json +1 -1
  172. package/foundation/agent-docs/agent-docs.mjs +1 -1
  173. package/foundation/config/theme-state.d.mts +13 -1
  174. package/foundation/config/theme-state.mjs +47 -7
  175. package/foundation/discovery/component-discovery.d.mts +11 -0
  176. package/foundation/discovery/component-discovery.mjs +27 -2
  177. package/foundation/discovery/component-replacement.mjs +130 -1
  178. package/foundation/discovery/entry-name-files.d.mts +43 -0
  179. package/foundation/discovery/entry-name-files.mjs +264 -0
  180. package/foundation/discovery/hook-discovery.d.mts +8 -2
  181. package/foundation/discovery/hook-discovery.mjs +20 -7
  182. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  183. package/foundation/discovery/runner-allowlist.mjs +2 -0
  184. package/foundation/discovery/template-adapter.d.mts +52 -0
  185. package/foundation/discovery/template-adapter.mjs +169 -0
  186. package/foundation/discovery/theme-imports.d.mts +14 -0
  187. package/foundation/discovery/theme-imports.mjs +43 -1
  188. package/foundation/doc-compiler/import.mjs +7 -1
  189. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  190. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  191. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  192. package/foundation/fs/cache-eviction.d.mts +21 -0
  193. package/foundation/fs/cache-eviction.mjs +73 -0
  194. package/foundation/fs/gather-cache.d.mts +25 -4
  195. package/foundation/fs/gather-cache.mjs +138 -52
  196. package/foundation/fs/jiti-cache.d.mts +19 -1
  197. package/foundation/fs/jiti-cache.mjs +130 -6
  198. package/foundation/fs/kept-tree.d.mts +60 -0
  199. package/foundation/fs/kept-tree.mjs +154 -0
  200. package/foundation/fs/module-loader.d.mts +18 -2
  201. package/foundation/fs/module-loader.mjs +92 -20
  202. package/foundation/identity/provider-identity.d.mts +6 -0
  203. package/foundation/identity/provider-identity.mjs +10 -1
  204. package/foundation/render/file-header.d.mts +66 -0
  205. package/foundation/render/file-header.mjs +118 -0
  206. package/foundation/render/host-answer.d.mts +18 -0
  207. package/foundation/render/host-answer.mjs +46 -0
  208. package/foundation/render/host-exit.d.mts +1 -0
  209. package/foundation/render/host-exit.mjs +6 -1
  210. package/foundation/render/html-reader.d.mts +55 -2
  211. package/foundation/render/html-reader.mjs +145 -26
  212. package/foundation/render/markup-edits.d.mts +57 -0
  213. package/foundation/render/markup-edits.mjs +182 -0
  214. package/foundation/render/page-host.mjs +29 -12
  215. package/foundation/render/page-worker.mjs +79 -10
  216. package/foundation/render/render-page.d.mts +34 -2
  217. package/foundation/render/render-page.mjs +210 -29
  218. package/foundation/render/source-block.d.mts +73 -6
  219. package/foundation/render/source-block.mjs +170 -19
  220. package/foundation/render/ts-paths.d.mts +4 -1
  221. package/foundation/render/ts-paths.mjs +7 -3
  222. package/foundation/response/error-codes.d.mts +2 -1
  223. package/foundation/response/error-codes.doc.mjs +7 -1
  224. package/foundation/response/error-codes.mjs +7 -0
  225. package/foundation/text/string-utils.d.mts +3 -2
  226. package/foundation/text/string-utils.mjs +16 -3
  227. package/foundation/text/suggest-order.d.mts +9 -0
  228. package/foundation/text/suggest-order.mjs +13 -0
  229. 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
  }
@@ -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,
@@ -24,6 +24,7 @@
24
24
 
25
25
  import * as fs from 'node:fs';
26
26
  import * as path from 'node:path';
27
+ import {fileURLToPath} from 'node:url';
27
28
  import {readDocView} from '../doc-compiler/read.mjs';
28
29
  import {importDocModule} from '../doc-compiler/import.mjs';
29
30
  import {readStore, storedKey} from '../doc-compiler/stored-docs.mjs';
@@ -40,6 +41,8 @@ import {
40
41
  TEMPLATE_COMPONENTS_FILE,
41
42
  } from './template-source-tree.mjs';
42
43
  import {persistedGather} from '../fs/gather-cache.mjs';
44
+ import {hasNameLine, keptTreeSummary, nameLines} from '../fs/kept-tree.mjs';
45
+ import {foldEntryName} from './entry-name-files.mjs';
43
46
  import {EXACT_CODEC} from '../fs/exact-codec.mjs';
44
47
  import {hostedRun} from '../runtime/package-root.mjs';
45
48
  import {babelParser} from '../runtime/lazy-dependencies.mjs';
@@ -1251,6 +1254,99 @@ async function discoverBlocks() {
1251
1254
  return blocks;
1252
1255
  }
1253
1256
 
1257
+ /**
1258
+ * The ids of Core's templates that `keep` accepts, read from file names: each
1259
+ * page folder, and each block doc that has its same-stem source. Discovery
1260
+ * gives Core's templates exactly these ids. Only a kept block's source is
1261
+ * looked for.
1262
+ * @param {(id: string) => boolean} [keep]
1263
+ * @returns {string[]}
1264
+ */
1265
+ export function coreTemplateIds(keep = () => true) {
1266
+ const ids = listTemplates().filter(keep);
1267
+ /** @param {string} dir */
1268
+ const walk = dir => {
1269
+ let entries;
1270
+ try {
1271
+ entries = fs.readdirSync(dir, {withFileTypes: true});
1272
+ } catch {
1273
+ return;
1274
+ }
1275
+ for (const entry of entries) {
1276
+ const full = path.join(dir, entry.name);
1277
+ if (entry.isDirectory()) {
1278
+ walk(full);
1279
+ continue;
1280
+ }
1281
+ if (!TEMPLATE_SUFFIX_RE.test(entry.name)) continue;
1282
+ const suffix = matchedTemplateSuffix(entry.name);
1283
+ if (!suffix) continue;
1284
+ const basename = entry.name.slice(0, -suffix.length);
1285
+ if (keep(basename) && fs.existsSync(path.join(dir, basename + '.tsx'))) {
1286
+ ids.push(basename);
1287
+ }
1288
+ }
1289
+ };
1290
+ walk(BLOCKS_DIR);
1291
+ return ids;
1292
+ }
1293
+
1294
+ /** This module's own file: its code decides the kept summaries' shape. */
1295
+ const OWN_FILE = fileURLToPath(import.meta.url);
1296
+
1297
+ /** The file of foldEntryName, which decides the template-ids summary too. */
1298
+ const FOLD_FILE = fileURLToPath(
1299
+ new URL('./entry-name-files.mjs', import.meta.url),
1300
+ );
1301
+
1302
+ /**
1303
+ * Which template files can give an id that folds to `wanted`, read from a
1304
+ * kept summary of file names: `blocks` false means {@link coreTemplateIds}
1305
+ * gives no block id that folds to it, and `listed` says whether any of the
1306
+ * integrations ships a template doc whose id ({@link integrationTemplateIds})
1307
+ * folds to it.
1308
+ * @param {Array<{templates?: string}>} integrations
1309
+ * @param {string} wanted a folded name
1310
+ * @returns {{blocks: boolean, listed: boolean}}
1311
+ */
1312
+ export function templateFilesNaming(integrations, wanted) {
1313
+ const roots = integrations.flatMap(integration =>
1314
+ typeof integration?.templates === 'string' && integration.templates !== ''
1315
+ ? [integration.templates]
1316
+ : [],
1317
+ );
1318
+ /** @type {Array<string | string[]>} */
1319
+ const [blocks, ...listed] = keptTreeSummary(
1320
+ {
1321
+ kind: 'template-ids',
1322
+ roots: [BLOCKS_DIR, ...roots],
1323
+ code: [OWN_FILE, FOLD_FILE],
1324
+ },
1325
+ trees =>
1326
+ trees.map(({folders}, at) => {
1327
+ const folded = new Set();
1328
+ for (const {rel, entries} of folders) {
1329
+ for (const {name, isDir} of entries) {
1330
+ if (isDir) continue;
1331
+ const suffix = matchedTemplateSuffix(name);
1332
+ if (!suffix) continue;
1333
+ // Core's block ids are stems; an integration's are paths.
1334
+ const id =
1335
+ at === 0
1336
+ ? name.slice(0, -suffix.length)
1337
+ : path.join(rel, name).slice(0, -suffix.length);
1338
+ folded.add(foldEntryName(id.split(path.sep).join('/')));
1339
+ }
1340
+ }
1341
+ return nameLines(folded);
1342
+ }),
1343
+ );
1344
+ return {
1345
+ blocks: hasNameLine(blocks, wanted),
1346
+ listed: listed.some(ids => hasNameLine(ids, wanted)),
1347
+ };
1348
+ }
1349
+
1254
1350
  /**
1255
1351
  * Discover blocks from external packages that declare `astryx.blocks` in
1256
1352
  * their package.json. Same shape as discoverBlocks() output.
@@ -1681,6 +1777,79 @@ function findIntegrationDocFiles(root) {
1681
1777
  return results;
1682
1778
  }
1683
1779
 
1780
+ /**
1781
+ * Code that lets a template doc declare a replacement: the field itself, or an
1782
+ * import, a require or a spread that can bring it in. Comments do not count.
1783
+ */
1784
+ const MAY_REPLACE_RE =
1785
+ /\breplaces\b|^\s*import\b|\bimport\s*\(|\brequire\s*\(|\.\.\.\s*[A-Za-z_$]/m;
1786
+
1787
+ /**
1788
+ * The id of each template doc an integration ships, valid or not, read from
1789
+ * file names alone.
1790
+ * @param {{templates?: string}} integration
1791
+ * @returns {string[]}
1792
+ */
1793
+ export function integrationTemplateIds(integration) {
1794
+ const root = integration?.templates;
1795
+ if (!root) return [];
1796
+ return findIntegrationDocFiles(root).flatMap(docPath => {
1797
+ const suffix = matchedTemplateSuffix(docPath);
1798
+ if (!suffix) return [];
1799
+ return [
1800
+ path
1801
+ .relative(root, docPath)
1802
+ .slice(0, -suffix.length)
1803
+ .split(path.sep)
1804
+ .join('/'),
1805
+ ];
1806
+ });
1807
+ }
1808
+
1809
+ /**
1810
+ * Whether any template doc an integration ships can declare a replacement,
1811
+ * read from its text without loading it.
1812
+ * @param {{templates?: string}} integration
1813
+ * @returns {boolean}
1814
+ */
1815
+ export function integrationMayReplaceTemplate(integration) {
1816
+ return integrationsMayReplaceTemplate([integration]);
1817
+ }
1818
+
1819
+ /**
1820
+ * Whether any template doc any of the integrations ships can declare a
1821
+ * replacement, read from a kept summary of the docs' text.
1822
+ * @param {Array<{templates?: string}>} integrations
1823
+ * @returns {boolean}
1824
+ */
1825
+ export function integrationsMayReplaceTemplate(integrations) {
1826
+ const roots = integrations.flatMap(integration =>
1827
+ typeof integration?.templates === 'string' && integration.templates !== ''
1828
+ ? [integration.templates]
1829
+ : [],
1830
+ );
1831
+ if (roots.length === 0) return false;
1832
+ return keptTreeSummary(
1833
+ {kind: 'integration-template-replaces', roots, code: [OWN_FILE]},
1834
+ trees =>
1835
+ trees.some(({folders, readText}) =>
1836
+ folders.some(({rel, entries}) =>
1837
+ entries.some(({name, isDir}) => {
1838
+ if (isDir || !matchedTemplateSuffix(name)) return false;
1839
+ try {
1840
+ const code = readText(rel === '' ? name : path.join(rel, name))
1841
+ .replace(/\/\*[\s\S]*?\*\//g, '')
1842
+ .replace(/^\s*\/\/.*$/gm, '');
1843
+ return MAY_REPLACE_RE.test(code);
1844
+ } catch {
1845
+ return true;
1846
+ }
1847
+ }),
1848
+ ),
1849
+ ),
1850
+ );
1851
+ }
1852
+
1684
1853
  /**
1685
1854
  * Discover templates contributed by configured integrations.
1686
1855
  *
@@ -1,6 +1,20 @@
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
+ * `{mode}` for a built theme module that exports one color mode
6
+ * (`export const colorModes = ["light"];`, which `theme build` writes beside
7
+ * the theme export), read without running it; nothing for a module with
8
+ * both modes, which exports none.
9
+ * @param {string | null | undefined} moduleFile
10
+ * @param {string} [exportName] the theme's export: a module that re-exports
11
+ * only the theme by name (`export {oceanTheme} from './ocean.js'`) is
12
+ * read where the theme is declared
13
+ * @returns {{mode?: 'light' | 'dark'}}
14
+ */
15
+ export function builtColorMode(moduleFile: string | null | undefined, exportName?: string): {
16
+ mode?: "light" | "dark";
17
+ };
4
18
  /**
5
19
  * Resolve a discovered theme to app imports.
6
20
  * @param {import('./theme-discovery.mjs').DiscoveredTheme} theme