@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
@@ -673,7 +673,7 @@ export function generateCompressedIndex(
673
673
  } else {
674
674
  lines.push("- Style with component props first, then tokens (var(--color-*|--spacing-*|--radius-*)). No raw hex/px. No StyleX/Tailwind compiler here — don't use xstyle/utility classes directly. Some templates use StyleX and need a compiler plugin; see `astryx docs styling-overview`.");
675
675
  }
676
- lines.push('- THEMES: palettes and custom colors go through the theme, never :root overrides. To make or change a theme (colors, fonts, corners, spacing, a look from a picture), prefer the experimental theme editor over hand-written theme files: `astryx experimental theme editor new <name> --like neutral`, then `editor set <name> <thing> <value>` or `editor how "<what you want>"`; wire it with `astryx theme add <name>`; after each change look at it with `astryx experimental theme editor show <name> --png` and open the PNGs it writes (changes nothing in the app); a theme change is not done until you have looked at the pictures. In code, extend an imported theme to customize it; `theme eject <slug>` only forks source. See `astryx docs theme`.');
676
+ lines.push('- THEMES: palettes and custom colors go through the theme, never :root overrides. To make or change a theme (colors, fonts, corners, spacing, a look from a picture), prefer the experimental theme editor over hand-written theme files: `astryx experimental theme editor new <name> --like neutral`, then `editor set <name> <thing> <value>` or `editor how "<what you want>"`; wire it with `astryx theme add <name>`; after each change look at it with `astryx experimental theme editor show <name> --png` (takes pictures of real components) and open the PNGs it writes; a theme change is not done until you have looked at the pictures. In code, extend an imported theme to customize it; `theme eject <slug>` only forks source. See `astryx docs theme`.');
677
677
  // Self-check — post-generation pass. Validated via vibe tests (internal/vibe-tests/
678
678
  // prompt-purity-test): on complex multi-step UIs the rules above alone still leave raw
679
679
  // CSS in ~11-13% of runs; a re-read-and-fix pass cuts that ~4x at negligible token cost.
@@ -86,14 +86,21 @@ export function readThemeState(cwd?: string): ThemeState;
86
86
  * @property {string} stylesheetFile
87
87
  * @property {string} [fontStylesheetFile]
88
88
  * @property {'bundled'|'package'|'local'} source
89
+ * @property {'light'|'dark'} [mode] the one color mode its built module
90
+ * exports; absent for a theme with both modes
89
91
  */
90
92
  /**
91
93
  * Render one generated module from final resolved state.
92
94
  * @param {ResolvedAppTheme[]} themes
93
95
  * @param {string} defaultSlug
94
96
  * @param {boolean} typescript
97
+ * @param {{keepModes?: boolean}} [options] `keepModes`: the module has
98
+ * exported `themeModes` before, so it keeps exporting it (empty when no
99
+ * theme has one mode), as the app's wiring imports it
95
100
  */
96
- export function renderThemeModule(themes: ResolvedAppTheme[], defaultSlug: string, typescript: boolean): string;
101
+ export function renderThemeModule(themes: ResolvedAppTheme[], defaultSlug: string, typescript: boolean, { keepModes }?: {
102
+ keepModes?: boolean;
103
+ }): string;
97
104
  /**
98
105
  * Resolve a project-relative import from the generated module to a local file.
99
106
  * @param {string} moduleFile
@@ -167,4 +174,9 @@ export type ResolvedAppTheme = {
167
174
  stylesheetFile: string;
168
175
  fontStylesheetFile?: string | undefined;
169
176
  source: "bundled" | "package" | "local";
177
+ /**
178
+ * the one color mode its built module
179
+ * exports; absent for a theme with both modes
180
+ */
181
+ mode?: "light" | "dark" | undefined;
170
182
  };
@@ -138,8 +138,7 @@ export function projectUsesTypeScript(projectDir) {
138
138
  .readdirSync(projectDir, {withFileTypes: true})
139
139
  .some(
140
140
  entry =>
141
- entry.isFile() &&
142
- /^tsconfig(?:\.[^.]+)*\.json$/u.test(entry.name),
141
+ entry.isFile() && /^tsconfig(?:\.[^.]+)*\.json$/u.test(entry.name),
143
142
  );
144
143
  } catch {
145
144
  return false;
@@ -226,7 +225,9 @@ function validThemeRecord(value, label, source = '') {
226
225
  */
227
226
  export function parseThemeModuleRecord(source, label = 'theme module') {
228
227
  if (!source.includes(THEME_MODULE_MARKER)) {
229
- throw new ThemeStateError(`${label} does not carry the Astryx generated marker.`);
228
+ throw new ThemeStateError(
229
+ `${label} does not carry the Astryx generated marker.`,
230
+ );
230
231
  }
231
232
  const recordLines = source
232
233
  .split(/\r?\n/u)
@@ -276,7 +277,9 @@ export function resolveThemeModule(projectDir, {forWrite = false} = {}) {
276
277
  throw new ThemeStateError(
277
278
  `More than one generated theme module exists: ${generated
278
279
  .map(file => projectPath(path.relative(projectDir, file)))
279
- .join(', ')}. Keep one and remove the others before running the command again.`,
280
+ .join(
281
+ ', ',
282
+ )}. Keep one and remove the others before running the command again.`,
280
283
  );
281
284
  }
282
285
  const file = generated[0] ?? candidates[0];
@@ -391,6 +394,8 @@ export function readThemeState(cwd = process.cwd()) {
391
394
  * @property {string} stylesheetFile
392
395
  * @property {string} [fontStylesheetFile]
393
396
  * @property {'bundled'|'package'|'local'} source
397
+ * @property {'light'|'dark'} [mode] the one color mode its built module
398
+ * exports; absent for a theme with both modes
394
399
  */
395
400
 
396
401
  /**
@@ -398,8 +403,16 @@ export function readThemeState(cwd = process.cwd()) {
398
403
  * @param {ResolvedAppTheme[]} themes
399
404
  * @param {string} defaultSlug
400
405
  * @param {boolean} typescript
406
+ * @param {{keepModes?: boolean}} [options] `keepModes`: the module has
407
+ * exported `themeModes` before, so it keeps exporting it (empty when no
408
+ * theme has one mode), as the app's wiring imports it
401
409
  */
402
- export function renderThemeModule(themes, defaultSlug, typescript) {
410
+ export function renderThemeModule(
411
+ themes,
412
+ defaultSlug,
413
+ typescript,
414
+ {keepModes = false} = {},
415
+ ) {
403
416
  if (!themes.some(theme => theme.slug === defaultSlug)) {
404
417
  // The record's default names no added theme; choosing an added one as the
405
418
  // default rewrites the record.
@@ -418,7 +431,14 @@ export function renderThemeModule(themes, defaultSlug, typescript) {
418
431
  const entries = [];
419
432
  /** @type {Record<string, string>} */
420
433
  const owners = {};
434
+ /** The one color mode of each theme that has one only. */
435
+ /** @type {string[]} */
436
+ const modes = [];
421
437
  themes.forEach((theme, index) => {
438
+ if (theme.mode)
439
+ modes.push(
440
+ ` ${JSON.stringify(theme.slug)}: ${JSON.stringify(theme.mode)},`,
441
+ );
422
442
  const local = `_astryxTheme${index}`;
423
443
  imports.push(
424
444
  `import {${theme.exportName} as ${local}} from ${JSON.stringify(theme.module)};`,
@@ -430,7 +450,10 @@ export function renderThemeModule(themes, defaultSlug, typescript) {
430
450
  entries.push(` ${JSON.stringify(theme.slug)}: ${local},`);
431
451
  owners[theme.slug] = theme.owner;
432
452
  });
433
- const record = JSON.stringify({themes: owners, defaultThemeSlug: defaultSlug});
453
+ const record = JSON.stringify({
454
+ themes: owners,
455
+ defaultThemeSlug: defaultSlug,
456
+ });
434
457
  return `/**\n * ${THEME_MODULE_MARKER}\n * ${THEME_RECORD_MARKER} ${record}\n */\n\n${imports.join(
435
458
  '\n',
436
459
  )}\n\nexport const themes = {\n${entries.join('\n')}\n}${
@@ -439,7 +462,19 @@ export function renderThemeModule(themes, defaultSlug, typescript) {
439
462
  typescript ? 'export type ThemeSlug = keyof typeof themes;\n' : ''
440
463
  }\nexport const defaultThemeSlug${
441
464
  typescript ? ': keyof typeof themes' : ''
442
- } = ${JSON.stringify(defaultSlug)};\n`;
465
+ } = ${JSON.stringify(defaultSlug)};\n${
466
+ // When an added theme has one color mode: `Theme`'s `mode` for each
467
+ // such theme, so the app follows the selected one; kept (empty) once the
468
+ // module has exported it, as the app's wiring imports it. A record of
469
+ // two-mode themes that never had one writes the module as before.
470
+ modes.length > 0 || keepModes
471
+ ? `\nexport const themeModes${
472
+ typescript
473
+ ? `: Partial<Record<keyof typeof themes, 'light' | 'dark'>>`
474
+ : ''
475
+ } = {${modes.length > 0 ? `\n${modes.join('\n')}\n` : ''}};\n`
476
+ : ''
477
+ }`;
443
478
  }
444
479
 
445
480
  /**
@@ -491,6 +526,11 @@ export function planThemeAppWrite(state, themes, defaultSlug, resolvedThemes) {
491
526
  entries,
492
527
  defaultSlug,
493
528
  module.typescript,
529
+ {
530
+ keepModes: /\bexport const themeModes\b/.test(
531
+ String(module.expectedOriginal ?? ''),
532
+ ),
533
+ },
494
534
  );
495
535
  return {
496
536
  module,
@@ -33,6 +33,17 @@ export function familyMember(docs: any, name: string): any;
33
33
  * @returns {Record<string, string[]>}
34
34
  */
35
35
  export function discoverComponents(coreDir: string): Record<string, string[]>;
36
+ /**
37
+ * The Core component names `keep` accepts, in discovery order. Each name is
38
+ * listed exactly when {@link discoverComponents} lists it, but no doc is read
39
+ * for a name `keep` rejects, so a check for one name is cheap.
40
+ * @param {string} coreDir
41
+ * @param {(name: string) => boolean} keep
42
+ * @param {Set<string>} [tops] the top folders of `src` that can hold a name
43
+ * `keep` accepts; the others are not read
44
+ * @returns {string[]}
45
+ */
46
+ export function discoverComponentNamesWhere(coreDir: string, keep: (name: string) => boolean, tops?: Set<string>): string[];
36
47
  /**
37
48
  * Find the .doc.mjs file for a component.
38
49
  * For sub-components (e.g. StackItem), returns the parent's .doc.mjs
@@ -379,12 +379,30 @@ export function discoverComponents(coreDir) {
379
379
  );
380
380
  }
381
381
 
382
+ /**
383
+ * The Core component names `keep` accepts, in discovery order. Each name is
384
+ * listed exactly when {@link discoverComponents} lists it, but no doc is read
385
+ * for a name `keep` rejects, so a check for one name is cheap.
386
+ * @param {string} coreDir
387
+ * @param {(name: string) => boolean} keep
388
+ * @param {Set<string>} [tops] the top folders of `src` that can hold a name
389
+ * `keep` accepts; the others are not read
390
+ * @returns {string[]}
391
+ */
392
+ export function discoverComponentNamesWhere(coreDir, keep, tops) {
393
+ return Object.values(readComponentGroups(coreDir, keep, tops)).flat();
394
+ }
395
+
382
396
  /**
383
397
  * The component groups under `coreDir`, read from disk.
384
398
  * @param {string} coreDir
399
+ * @param {(name: string) => boolean} [keep] the names to read; the others
400
+ * are left out
401
+ * @param {Set<string>} [tops] the top folders to read, when only these can
402
+ * hold a name `keep` accepts
385
403
  * @returns {Record<string, string[]>}
386
404
  */
387
- function readComponentGroups(coreDir) {
405
+ function readComponentGroups(coreDir, keep = () => true, tops) {
388
406
  const srcDir = path.join(coreDir, 'src');
389
407
  /** @type {Map<string, string|null>} componentName → group */
390
408
  const componentGroups = new Map();
@@ -401,7 +419,10 @@ function readComponentGroups(coreDir) {
401
419
  for (const entry of entries) {
402
420
  if (entry.isDirectory()) {
403
421
  results.push(...collectXDSFiles(path.join(dirPath, entry.name)));
404
- } else if (isComponentSourceFile(entry.name, dirPath)) {
422
+ } else if (
423
+ keep(componentNameFromFile(entry.name)) &&
424
+ isComponentSourceFile(entry.name, dirPath)
425
+ ) {
405
426
  results.push(entry.name);
406
427
  }
407
428
  }
@@ -411,9 +432,11 @@ function readComponentGroups(coreDir) {
411
432
  const topEntries = listDirEntries(srcDir);
412
433
  for (const entry of topEntries) {
413
434
  if (!entry.isDirectory() || SKIP_DIRS.has(entry.name)) continue;
435
+ if (tops && !tops.has(entry.name)) continue;
414
436
 
415
437
  const dirPath = path.join(srcDir, entry.name);
416
438
  const xdsFiles = collectXDSFiles(dirPath);
439
+ if (xdsFiles.length === 0) continue;
417
440
 
418
441
  // Read the group from the directory's .doc.mjs file (if it exists)
419
442
  // Check both {Name}.doc.mjs and Astryx{Name}.doc.mjs naming conventions
@@ -461,7 +484,9 @@ function readComponentGroups(coreDir) {
461
484
  // (HStack and VStack in Stack's doc).
462
485
  for (const entry of topEntries) {
463
486
  if (!entry.isDirectory() || SKIP_DIRS.has(entry.name)) continue;
487
+ if (tops && !tops.has(entry.name)) continue;
464
488
  const name = entry.name;
489
+ if (!keep(name)) continue;
465
490
  if (componentGroups.has(name) || name.endsWith('Context')) continue;
466
491
  if (
467
492
  listDir(path.join(srcDir, name)).some(file => file.endsWith('.doc.mjs'))
@@ -10,7 +10,8 @@
10
10
  * @position foundation/discovery — the one place component replacement is
11
11
  * decided. Component detail, list, search, swizzle, gap-report routing,
12
12
  * Project, and `doctor integration components` read the result instead of
13
- * deciding it again.
13
+ * deciding it again. The result is kept between runs
14
+ * (foundation/fs/gather-cache.mjs), as part of the component list.
14
15
  *
15
16
  * A component opts in by setting `replaces` in its own doc. The replacement
16
17
  * applies only when the component's package also declares a
@@ -19,6 +20,7 @@
19
20
  * and every finding about it is a warning.
20
21
  */
21
22
 
23
+ import {createHash} from 'node:crypto';
22
24
  import * as fs from 'node:fs';
23
25
  import * as path from 'node:path';
24
26
  import {
@@ -31,6 +33,7 @@ import {
31
33
  componentReplacesCliProblem,
32
34
  } from '../integrations/cli-requirement.mjs';
33
35
  import {formatCliCommand} from '../env/package-manager.mjs';
36
+ import {persistedGather} from '../fs/gather-cache.mjs';
34
37
 
35
38
  /**
36
39
  * @typedef {import('../integrations/integrations.mjs').LoadedIntegration} LoadedIntegration
@@ -149,6 +152,132 @@ export async function resolveComponentReplacements(
149
152
  coreDir,
150
153
  loadedIntegrations,
151
154
  ) {
155
+ // Without an integration that contributes components nothing is read.
156
+ if (!loadedIntegrations.some(contributesComponents)) {
157
+ return replacementsNow(coreDir, loadedIntegrations);
158
+ }
159
+ // Every file and module the decision reads is stamped by the kept gather.
160
+ // What it reads from the loaded integrations was read when they loaded,
161
+ // before the gather, so those values are the key.
162
+ return persistedGather(
163
+ ['component-replacements', coreDir, loadedIntegrations.map(integrationKey)],
164
+ () => replacementsNow(coreDir, loadedIntegrations),
165
+ replacementsCodec(loadedIntegrations),
166
+ );
167
+ }
168
+
169
+ /**
170
+ * @param {LoadedIntegration | null | undefined} integration
171
+ * @returns {boolean} whether the decision reads the integration's components
172
+ */
173
+ function contributesComponents(integration) {
174
+ return (
175
+ integration != null &&
176
+ !integration.__loadError &&
177
+ Boolean(integration.components)
178
+ );
179
+ }
180
+
181
+ /**
182
+ * The fields of a loaded integration the decision reads: its name, its
183
+ * components folder, its issues link, its package folder and exports, why it
184
+ * failed to load, and whether it was autolinked.
185
+ * @param {LoadedIntegration | null | undefined} integration
186
+ * @returns {unknown}
187
+ */
188
+ function integrationKey(integration) {
189
+ if (integration == null) return null;
190
+ const exports = integration.__packageExports ?? null;
191
+ return [
192
+ integration.name ?? null,
193
+ integration.components ?? null,
194
+ integration.issuesUrl ?? null,
195
+ integration.__packageDir ?? null,
196
+ exports == null
197
+ ? null
198
+ : createHash('sha256').update(JSON.stringify(exports)).digest('hex'),
199
+ integration.__loadError ? String(integration.__loadError) : null,
200
+ integration.__autolinked === true,
201
+ ];
202
+ }
203
+
204
+ /**
205
+ * The result with `forTarget` answering from its active replacements.
206
+ * @param {ActiveComponentReplacement[]} active
207
+ * @param {ComponentReplacementFinding[]} findings
208
+ * @returns {ComponentReplacements}
209
+ */
210
+ function replacementsOf(active, findings) {
211
+ /** @type {Map<string, ActiveComponentReplacement>} */
212
+ const byTarget = new Map(active.map(each => [each.target, each]));
213
+ return {
214
+ active,
215
+ findings,
216
+ forTarget: name =>
217
+ typeof name === 'string' ? byTarget.get(name) : undefined,
218
+ };
219
+ }
220
+
221
+ /**
222
+ * The kept form of a result: each active replacement names its integration by
223
+ * its place in `loadedIntegrations`, which the key holds in order, and reads
224
+ * back as this run's loaded integration.
225
+ * @param {readonly LoadedIntegration[]} loadedIntegrations
226
+ */
227
+ function replacementsCodec(loadedIntegrations) {
228
+ return {
229
+ /** @param {ComponentReplacements} value */
230
+ encode: value => ({
231
+ active: value.active.map(each => ({
232
+ target: each.target,
233
+ name: each.name,
234
+ package: each.package,
235
+ docPath: each.docPath,
236
+ sourcePath: each.sourcePath,
237
+ ...(each.issuesUrl === undefined ? {} : {issuesUrl: each.issuesUrl}),
238
+ integration: loadedIntegrations.indexOf(each.integration),
239
+ })),
240
+ findings: value.findings,
241
+ }),
242
+ /** @param {any} stored @returns {ComponentReplacements} */
243
+ decode: stored =>
244
+ replacementsOf(
245
+ stored.active.map((/** @type {any} */ each) => ({
246
+ target: each.target,
247
+ name: each.name,
248
+ package: each.package,
249
+ docPath: each.docPath,
250
+ sourcePath: each.sourcePath,
251
+ issuesUrl: each.issuesUrl,
252
+ integration: loadedIntegrations[each.integration],
253
+ })),
254
+ stored.findings,
255
+ ),
256
+ /** @param {ComponentReplacements} value */
257
+ valid: value =>
258
+ Array.isArray(value.active) &&
259
+ Array.isArray(value.findings) &&
260
+ value.active.every(
261
+ each =>
262
+ each.integration != null &&
263
+ typeof each.target === 'string' &&
264
+ typeof each.name === 'string',
265
+ ) &&
266
+ value.findings.every(
267
+ finding =>
268
+ typeof finding?.code === 'string' &&
269
+ typeof finding.message === 'string',
270
+ ),
271
+ };
272
+ }
273
+
274
+ /**
275
+ * resolveComponentReplacements, gathered now.
276
+ * @param {string|null} coreDir
277
+ * @param {readonly LoadedIntegration[]} loadedIntegrations
278
+ * @returns {Promise<ComponentReplacements>}
279
+ */
280
+ async function replacementsNow(coreDir, loadedIntegrations) {
152
281
  /** @type {ComponentReplacementFinding[]} */
153
282
  const findings = [];
154
283
  /** @type {Map<string, ActiveComponentReplacement>} */
@@ -0,0 +1,43 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * A name as a reader may type it: case, spaces and hyphens do not count.
6
+ * @param {string} name
7
+ * @returns {string}
8
+ */
9
+ export function foldEntryName(name: string): string;
10
+ /**
11
+ * Which Core entries can fold to `wanted`. Every Core component takes its
12
+ * name from a `.tsx` file (without an `XDS` prefix) or a folder, and every
13
+ * hook from its doc's file name, so a name no such file carries is neither.
14
+ * @param {string} coreDir
15
+ * @param {string} wanted a folded name
16
+ * @returns {{component: boolean, hook: boolean, componentTops: Set<string>, hookTops: Set<string>}}
17
+ * `hook` also counts a hook named `use` + `wanted`; the tops are the top
18
+ * folders of `src` that hold such a file or folder
19
+ */
20
+ export function coreFilesNaming(coreDir: string, wanted: string): {
21
+ component: boolean;
22
+ hook: boolean;
23
+ componentTops: Set<string>;
24
+ hookTops: Set<string>;
25
+ };
26
+ /**
27
+ * Whether an integration component can fold to `wanted`, for each
28
+ * components folder in order. Integration discovery names a component after
29
+ * its doc's file, or after a name the doc spells out (its export, or a family
30
+ * member), so a doc whose file name and text both lack the name lists no
31
+ * such component.
32
+ * @param {Array<string | undefined>} componentsDirs
33
+ * @param {string} wanted a folded name
34
+ * @returns {boolean[]}
35
+ */
36
+ export function integrationsFilesNaming(componentsDirs: Array<string | undefined>, wanted: string): boolean[];
37
+ /**
38
+ * {@link integrationsFilesNaming} for one components folder.
39
+ * @param {string | undefined} componentsDir
40
+ * @param {string} wanted a folded name
41
+ * @returns {boolean}
42
+ */
43
+ export function integrationFilesNaming(componentsDir: string | undefined, wanted: string): boolean;