@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0404a74

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 (529) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +17 -0
  3. package/api/build/_adapter.mjs +53 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/blocks/blocks.weights.json +1 -1
  7. package/api/build/build.doc.mjs +4 -3
  8. package/api/build/build.type.d.mts +2 -2
  9. package/api/build/build.type.mjs +3 -3
  10. package/api/build/kit/kind.d.mts +2 -1
  11. package/api/build/kit/kind.mjs +199 -10
  12. package/api/build/kit/kit.mjs +6 -4
  13. package/api/build/kit/rank.d.mts +6 -4
  14. package/api/build/kit/rank.mjs +132 -28
  15. package/api/build/kit/signals.d.mts +7 -1
  16. package/api/build/kit/signals.mjs +21 -10
  17. package/api/build/kit/start.d.mts +5 -4
  18. package/api/build/kit/start.mjs +14 -9
  19. package/api/build/kit/weights.d.mts +39 -3
  20. package/api/build/kit/weights.json +1 -1
  21. package/api/build/kit/weights.mjs +351 -46
  22. package/api/build/kit/word-model.d.mts +23 -0
  23. package/api/build/kit/word-model.mjs +46 -0
  24. package/api/build/kit/words.d.mts +86 -0
  25. package/api/build/kit/words.mjs +241 -1
  26. package/api/build/tree.mjs +1 -1
  27. package/api/component/__fixtures__/resolutions/modules.txt +5 -6
  28. package/api/component/_adapter.d.mts +26 -2
  29. package/api/component/_adapter.mjs +135 -8
  30. package/api/component/component.mjs +14 -1
  31. package/api/component/list/list.d.mts +1 -1
  32. package/api/component/list/list.mjs +48 -6
  33. package/api/discover/_adapter.d.mts +11 -1
  34. package/api/discover/_adapter.mjs +95 -1
  35. package/api/discover/detail/item/item.mjs +5 -0
  36. package/api/discover/discover.mjs +12 -3
  37. package/api/discover/discover.type.d.mts +16 -3
  38. package/api/discover/discover.type.mjs +13 -3
  39. package/api/discover/search/search.mjs +3 -2
  40. package/api/docs/_adapter.d.mts +57 -2
  41. package/api/docs/_adapter.mjs +266 -33
  42. package/api/docs/_entry-names-lazily.d.mts +22 -0
  43. package/api/docs/_entry-names-lazily.mjs +25 -0
  44. package/api/docs/_entry-names.d.mts +23 -0
  45. package/api/docs/_entry-names.mjs +105 -0
  46. package/api/docs/docs.d.mts +3 -0
  47. package/api/docs/docs.doc.mjs +7 -1
  48. package/api/docs/docs.mjs +12 -0
  49. package/api/docs/docs.type.d.mts +5 -0
  50. package/api/docs/docs.type.mjs +2 -0
  51. package/api/docs/node/node.mjs +1 -1
  52. package/api/doctor/_adapter.d.mts +54 -5
  53. package/api/doctor/_adapter.mjs +162 -11
  54. package/api/doctor/built-checks.mjs +40 -14
  55. package/api/doctor/doctor.d.mts +15 -3
  56. package/api/doctor/doctor.doc.mjs +1 -1
  57. package/api/doctor/doctor.mjs +31 -7
  58. package/api/doctor/theme-checks.d.mts +35 -3
  59. package/api/doctor/theme-checks.mjs +377 -29
  60. package/api/hook/_adapter.d.mts +10 -4
  61. package/api/hook/_adapter.mjs +41 -5
  62. package/api/hook/detail/detail.mjs +5 -2
  63. package/api/hook/detail/params/params.mjs +10 -3
  64. package/api/icon/_records.mjs +2 -1
  65. package/api/index.d.mts +2 -0
  66. package/api/index.mjs +2 -0
  67. package/api/integration/_adapter.d.mts +44 -0
  68. package/api/integration/_adapter.mjs +77 -1
  69. package/api/integration/add-helpers.mjs +10 -0
  70. package/api/integration/authoring-checks.mjs +11 -8
  71. package/api/integration/example-scope.d.mts +14 -0
  72. package/api/integration/example-scope.mjs +44 -0
  73. package/api/integration/example-scope.type.d.mts +29 -0
  74. package/api/integration/example-scope.type.mjs +25 -0
  75. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  76. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  77. package/api/integration/pack-check.mjs +16 -1
  78. package/api/integration/validate-integration.d.mts +18 -6
  79. package/api/integration/validate-integration.mjs +129 -15
  80. package/api/integration/validate-integration.type.d.mts +22 -0
  81. package/api/integration/validate-integration.type.mjs +2 -1
  82. package/api/integration/validateIntegration.doc.mjs +1 -1
  83. package/api/render/_adapter.mjs +591 -195
  84. package/api/render/render.doc.mjs +11 -3
  85. package/api/render/render.type.d.mts +53 -1
  86. package/api/render/render.type.mjs +32 -2
  87. package/api/search/ORDERING.md +2 -2
  88. package/api/search/_adapter.d.mts +9 -0
  89. package/api/search/_adapter.mjs +85 -0
  90. package/api/search/_candidate-score.d.mts +9 -4
  91. package/api/search/_candidate-score.mjs +133 -46
  92. package/api/search/_fit-order.mjs +3 -3
  93. package/api/search/_gather-components.d.mts +3 -2
  94. package/api/search/_gather-components.mjs +12 -3
  95. package/api/search/_lexical.d.mts +14 -0
  96. package/api/search/_lexical.mjs +93 -11
  97. package/api/search/_result.d.mts +11 -9
  98. package/api/search/_result.mjs +4 -4
  99. package/api/search/_score.d.mts +6 -1
  100. package/api/search/_score.mjs +15 -3
  101. package/api/search/search-index.mjs +7 -1
  102. package/api/search/search.d.mts +1 -1
  103. package/api/template/_adapter.d.mts +16 -0
  104. package/api/template/_adapter.mjs +39 -2
  105. package/api/template/cdn/cdn.mjs +37 -8
  106. package/api/template/copy/copy.d.mts +6 -3
  107. package/api/template/copy/copy.mjs +40 -8
  108. package/api/template/template.doc.mjs +3 -3
  109. package/api/template/template.mjs +63 -11
  110. package/api/template/template.type.d.mts +1 -0
  111. package/api/template/template.type.mjs +1 -0
  112. package/api/theme/_adapter.d.mts +12 -1
  113. package/api/theme/_adapter.mjs +132 -13
  114. package/api/theme/_app-provider.d.mts +31 -0
  115. package/api/theme/_app-provider.mjs +135 -0
  116. package/api/theme/add/add.mjs +3 -1
  117. package/api/theme/build/build.d.mts +142 -1
  118. package/api/theme/build/build.mjs +692 -284
  119. package/api/theme/build/core-interception.d.mts +10 -0
  120. package/api/theme/build/core-interception.mjs +10 -0
  121. package/api/theme/build/font-warning.d.mts +80 -5
  122. package/api/theme/build/font-warning.mjs +323 -55
  123. package/api/theme/build/icon-imports.mjs +51 -9
  124. package/api/theme/build/null-values.d.mts +28 -0
  125. package/api/theme/build/null-values.mjs +191 -0
  126. package/api/theme/list/list.mjs +17 -1
  127. package/api/theme/remove/remove.d.mts +2 -1
  128. package/api/theme/remove/remove.mjs +7 -3
  129. package/api/theme/theme.type.d.mts +78 -1
  130. package/api/theme/theme.type.mjs +38 -2
  131. package/api/theme/themeAdd.doc.mjs +1 -1
  132. package/api/theme/themeListAvailable.doc.mjs +1 -1
  133. package/api/theme/themeRemove.doc.mjs +8 -5
  134. package/api/theme-edit/_adapter.d.mts +116 -4
  135. package/api/theme-edit/_adapter.mjs +1058 -93
  136. package/api/theme-edit/_catalog.d.mts +46 -2
  137. package/api/theme-edit/_catalog.mjs +115 -14
  138. package/api/theme-edit/_check.d.mts +133 -24
  139. package/api/theme-edit/_check.mjs +3392 -531
  140. package/api/theme-edit/_color.d.mts +26 -0
  141. package/api/theme-edit/_color.mjs +92 -2
  142. package/api/theme-edit/_compiler.d.mts +5 -1
  143. package/api/theme-edit/_compiler.mjs +141 -17
  144. package/api/theme-edit/_context.d.mts +74 -6
  145. package/api/theme-edit/_context.mjs +468 -76
  146. package/api/theme-edit/_css.d.mts +21 -0
  147. package/api/theme-edit/_css.mjs +87 -14
  148. package/api/theme-edit/_edit.d.mts +74 -7
  149. package/api/theme-edit/_edit.mjs +4426 -319
  150. package/api/theme-edit/_how-commands.d.mts +76 -1
  151. package/api/theme-edit/_how-commands.mjs +793 -9
  152. package/api/theme-edit/_how-question.d.mts +97 -6
  153. package/api/theme-edit/_how-question.mjs +9184 -747
  154. package/api/theme-edit/_how.d.mts +5 -2
  155. package/api/theme-edit/_how.mjs +255 -46
  156. package/api/theme-edit/_importers.d.mts +38 -0
  157. package/api/theme-edit/_importers.mjs +188 -0
  158. package/api/theme-edit/_marks.d.mts +31 -5
  159. package/api/theme-edit/_marks.mjs +57 -5
  160. package/api/theme-edit/_name-rule.d.mts +11 -0
  161. package/api/theme-edit/_name-rule.mjs +12 -0
  162. package/api/theme-edit/_normal.d.mts +322 -0
  163. package/api/theme-edit/_normal.mjs +1630 -0
  164. package/api/theme-edit/_palette.d.mts +49 -0
  165. package/api/theme-edit/_palette.mjs +180 -38
  166. package/api/theme-edit/_part-words.d.mts +39 -0
  167. package/api/theme-edit/_part-words.mjs +152 -0
  168. package/api/theme-edit/_parts.d.mts +55 -3
  169. package/api/theme-edit/_parts.mjs +421 -36
  170. package/api/theme-edit/_preview-app.d.mts +7 -13
  171. package/api/theme-edit/_preview-app.mjs +1108 -599
  172. package/api/theme-edit/_preview.d.mts +156 -19
  173. package/api/theme-edit/_preview.mjs +809 -180
  174. package/api/theme-edit/_project.d.mts +61 -1
  175. package/api/theme-edit/_project.mjs +177 -6
  176. package/api/theme-edit/_settings.d.mts +619 -48
  177. package/api/theme-edit/_settings.mjs +4910 -617
  178. package/api/theme-edit/_tables.d.mts +41 -0
  179. package/api/theme-edit/_tables.mjs +261 -41
  180. package/api/theme-edit/_vet.d.mts +31 -0
  181. package/api/theme-edit/_vet.mjs +114 -8
  182. package/api/theme-edit/theme-edit.type.d.mts +34 -2
  183. package/api/theme-edit/theme-edit.type.mjs +18 -3
  184. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  185. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  186. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  187. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  188. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  189. package/api/upgrade/run/run.mjs +4 -3
  190. package/api/upgrade/upgrade.mjs +16 -1
  191. package/assets/codemods/integration-discovery.mjs +2 -1
  192. package/assets/codemods/integration-runner.mjs +1 -1
  193. package/assets/codemods/jscodeshift.d.ts +1 -1
  194. package/assets/codemods/run-codemod.mjs +151 -18
  195. package/assets/codemods/runner.mjs +1 -4
  196. package/assets/codemods/transforms/next/index.mjs +11 -1
  197. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  198. package/assets/component-list.generated.json +1 -0
  199. package/assets/docs/author-a-theme.doc.mjs +2 -0
  200. package/assets/docs/theme.doc.dense.mjs +76 -7
  201. package/assets/docs/theme.doc.mjs +66 -2
  202. package/assets/docs/theme.doc.zh.mjs +51 -1
  203. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  204. package/assets/docs/tree/checks.doc.mjs +2 -2
  205. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  206. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  207. package/assets/docs/tree/font-setup.doc.mjs +1 -1
  208. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  209. package/assets/docs/tree/render-pages.doc.mjs +46 -5
  210. package/assets/docs/tree/share-a-page.doc.mjs +157 -0
  211. package/assets/docs/tree/single-component.doc.mjs +4 -0
  212. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  213. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  214. package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
  215. package/assets/docs/use-a-theme.doc.mjs +2 -2
  216. package/assets/docs-routes.generated.json +1 -0
  217. package/assets/docs.generated.json +2 -2
  218. package/assets/search-catalog.generated.json +2 -0
  219. package/assets/self-audit.generated.json +1 -1
  220. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  221. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  222. package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.doc.mjs +14 -0
  223. package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.tsx +43 -0
  224. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  225. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  226. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  227. package/assets/templates/components.generated.json +1 -1
  228. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  229. package/assets/templates/pages/ai-chat-landing/page.tsx +31 -4
  230. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
  231. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  232. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  233. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  234. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  235. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  236. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  237. package/assets/templates/pages/dashboard-alert-rail/page.tsx +1 -1
  238. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  239. package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +1 -1
  240. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  241. package/assets/templates/pages/dashboard-comparison/page.tsx +2 -2
  242. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  243. package/assets/templates/pages/dashboard-progress/page.tsx +1 -1
  244. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  245. package/assets/templates/pages/detail-page/page.tsx +60 -7
  246. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  247. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  248. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  249. package/assets/templates/pages/documentation-technical/page.tsx +13 -13
  250. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  251. package/assets/templates/pages/editor/page.tsx +14 -2
  252. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  253. package/assets/templates/pages/file-explorer/page.tsx +9 -0
  254. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  255. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  256. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  257. package/assets/templates/pages/form-wizard-vertical/page.tsx +23 -3
  258. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  259. package/assets/templates/pages/ide/page.tsx +33 -2
  260. package/assets/templates/pages/kanban-board/page.tsx +12 -2
  261. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  262. package/assets/templates/pages/library/template.doc.mjs +4 -1
  263. package/assets/templates/pages/login/template.doc.mjs +2 -1
  264. package/assets/templates/pages/login-card/page.tsx +16 -0
  265. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  266. package/assets/templates/pages/login-split/page.tsx +19 -6
  267. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  268. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  269. package/assets/templates/pages/messaging-shell/template.doc.mjs +6 -0
  270. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  271. package/assets/templates/pages/payment-form/page.tsx +30 -4
  272. package/assets/templates/pages/product-detail/page.tsx +26 -2
  273. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  274. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  275. package/assets/templates/pages/settings-dialog/page.tsx +162 -12
  276. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  277. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  278. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  279. package/assets/templates/pages/shell-side-nav/page.tsx +11 -3
  280. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  281. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  282. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  283. package/assets/templates/pages/table-filter/page.tsx +9 -0
  284. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  285. package/assets/templates/pages/table-grouped/page.tsx +161 -133
  286. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  287. package/assets/templates/pages/table-page/page.tsx +14 -1
  288. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  289. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  290. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  291. package/assets/templates/pages/work-item-detail/page.tsx +47 -7
  292. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  293. package/assets/theme.template.ts +9 -2
  294. package/authoring/debug/parse.d.mts +3 -3
  295. package/authoring/doctypes/_schema.d.mts +9 -9
  296. package/authoring/doctypes/command/command.doc.mjs +1 -1
  297. package/authoring/doctypes/component/categories.d.mts +37 -0
  298. package/authoring/doctypes/component/categories.mjs +54 -0
  299. package/authoring/doctypes/template/template.doc.mjs +1 -1
  300. package/authoring/doctypes/template/type.ts +9 -0
  301. package/authoring/example/example.doc.d.mts +12 -0
  302. package/authoring/example/example.doc.mjs +69 -0
  303. package/authoring/example/preview.d.mts +92 -0
  304. package/authoring/example/preview.mjs +994 -0
  305. package/authoring/example/type.ts +102 -0
  306. package/authoring/index.d.mts +1 -0
  307. package/authoring/index.d.ts +12 -0
  308. package/authoring/index.mjs +3 -1
  309. package/authoring/integration/integration.doc.mjs +8 -0
  310. package/authoring/integration/schema.d.mts +24 -1
  311. package/authoring/integration/schema.mjs +126 -4
  312. package/authoring/integration/type.ts +14 -0
  313. package/clients/cli/bin/astryx.mjs +6 -9
  314. package/clients/cli/build-id.generated.json +1 -1
  315. package/clients/cli/commands/component.doc.mjs +1 -1
  316. package/clients/cli/commands/component.mjs +22 -3
  317. package/clients/cli/commands/discover.mjs +70 -3
  318. package/clients/cli/commands/docs.doc.mjs +7 -1
  319. package/clients/cli/commands/docs.mjs +44 -6
  320. package/clients/cli/commands/doctor.mjs +84 -16
  321. package/clients/cli/commands/experimental/render.mjs +42 -1
  322. package/clients/cli/commands/experimental/theme.mjs +1032 -134
  323. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  324. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  325. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  326. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  327. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  328. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  329. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  330. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  331. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -2
  332. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  333. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  334. package/clients/cli/commands/experimental-theme-remove.doc.mjs +4 -4
  335. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  336. package/clients/cli/commands/search.doc.mjs +2 -1
  337. package/clients/cli/commands/search.mjs +6 -1
  338. package/clients/cli/commands/template.doc.mjs +1 -1
  339. package/clients/cli/commands/template.mjs +15 -2
  340. package/clients/cli/commands/theme-add.doc.mjs +1 -1
  341. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  342. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  343. package/clients/cli/commands/theme-remove.doc.mjs +13 -5
  344. package/clients/cli/commands/theme.doc.mjs +1 -1
  345. package/clients/cli/commands/theme.mjs +849 -441
  346. package/clients/cli/commands/upgrade.mjs +46 -8
  347. package/clients/cli/index.mjs +9 -19
  348. package/clients/cli/lib/cli-error.mjs +2 -1
  349. package/clients/cli/lib/component-format.mjs +205 -98
  350. package/clients/cli/lib/hook-format.mjs +9 -19
  351. package/clients/cli/lib/json-shim.mjs +265 -29
  352. package/clients/cli/lib/manifest.mjs +3 -2
  353. package/clients/cli/lib/stray-option.mjs +478 -0
  354. package/clients/cli/lib/unknown-command.mjs +353 -0
  355. package/clients/cli/manifest.generated.json +1 -1
  356. package/foundation/agent-docs/agent-docs.mjs +1 -1
  357. package/foundation/config/project.d.mts +8 -0
  358. package/foundation/config/project.mjs +26 -29
  359. package/foundation/config/theme-state.d.mts +31 -2
  360. package/foundation/config/theme-state.mjs +140 -8
  361. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  362. package/foundation/discovery/cli-self-doc-names.d.mts +13 -0
  363. package/foundation/discovery/cli-self-doc-names.mjs +51 -0
  364. package/foundation/discovery/cli-self-docs.d.mts +0 -2
  365. package/foundation/discovery/cli-self-docs.mjs +2 -15
  366. package/foundation/discovery/component-discovery.d.mts +11 -0
  367. package/foundation/discovery/component-discovery.mjs +59 -10
  368. package/foundation/discovery/component-replacement.mjs +130 -1
  369. package/foundation/discovery/copied-passages.mjs +2 -1
  370. package/foundation/discovery/core-component-docs.d.mts +29 -0
  371. package/foundation/discovery/core-component-docs.mjs +83 -0
  372. package/foundation/discovery/core-theme-facts.d.mts +70 -0
  373. package/foundation/discovery/core-theme-facts.mjs +384 -0
  374. package/foundation/discovery/doc-types.mjs +4 -3
  375. package/foundation/discovery/docs-discovery.d.mts +66 -9
  376. package/foundation/discovery/docs-discovery.mjs +126 -60
  377. package/foundation/discovery/entry-name-files.d.mts +106 -0
  378. package/foundation/discovery/entry-name-files.mjs +354 -0
  379. package/foundation/discovery/hook-discovery.d.mts +18 -2
  380. package/foundation/discovery/hook-discovery.mjs +93 -42
  381. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  382. package/foundation/discovery/icon-set-checks.mjs +2 -1
  383. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  384. package/foundation/discovery/integration-component-views.d.mts +15 -0
  385. package/foundation/discovery/integration-component-views.mjs +91 -0
  386. package/foundation/discovery/integration-doc-files.mjs +2 -1
  387. package/foundation/discovery/module-exports.d.mts +26 -1
  388. package/foundation/discovery/module-exports.mjs +114 -40
  389. package/foundation/discovery/name-roots.d.mts +38 -0
  390. package/foundation/discovery/name-roots.mjs +108 -0
  391. package/foundation/discovery/next-routes.d.mts +48 -0
  392. package/foundation/discovery/next-routes.mjs +181 -0
  393. package/foundation/discovery/package-exports.d.mts +10 -0
  394. package/foundation/discovery/package-exports.mjs +56 -3
  395. package/foundation/discovery/prop-drift.mjs +9 -9
  396. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  397. package/foundation/discovery/runner-allowlist.mjs +2 -0
  398. package/foundation/discovery/stored-component-list.d.mts +43 -0
  399. package/foundation/discovery/stored-component-list.mjs +90 -0
  400. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  401. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  402. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  403. package/foundation/discovery/stored-self-audit.mjs +40 -18
  404. package/foundation/discovery/template-adapter.d.mts +49 -29
  405. package/foundation/discovery/template-adapter.mjs +89 -99
  406. package/foundation/discovery/template-destination.d.mts +28 -0
  407. package/foundation/discovery/template-destination.mjs +104 -0
  408. package/foundation/discovery/template-icons.mjs +2 -1
  409. package/foundation/discovery/template-ids.d.mts +69 -0
  410. package/foundation/discovery/template-ids.mjs +199 -0
  411. package/foundation/discovery/theme-discovery.d.mts +12 -0
  412. package/foundation/discovery/theme-discovery.mjs +34 -4
  413. package/foundation/discovery/theme-imports.d.mts +24 -0
  414. package/foundation/discovery/theme-imports.mjs +61 -4
  415. package/foundation/discovery/theming-targets.d.mts +13 -5
  416. package/foundation/discovery/theming-targets.mjs +41 -47
  417. package/foundation/doc-compiler/generated-levels.d.mts +43 -0
  418. package/foundation/doc-compiler/generated-levels.mjs +72 -0
  419. package/foundation/doc-compiler/import.mjs +7 -1
  420. package/foundation/doc-compiler/inputs.mjs +3 -2
  421. package/foundation/doc-compiler/literal-doc.d.mts +12 -0
  422. package/foundation/doc-compiler/literal-doc.mjs +322 -0
  423. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  424. package/foundation/doc-compiler/stored-docs.d.mts +29 -0
  425. package/foundation/doc-compiler/stored-docs.mjs +63 -1
  426. package/foundation/doc-compiler/tree.d.mts +4 -84
  427. package/foundation/doc-compiler/tree.mjs +4 -62
  428. package/foundation/env/semver.mjs +3 -1
  429. package/foundation/fonts/font-stylesheet.d.mts +46 -0
  430. package/foundation/fonts/font-stylesheet.mjs +173 -0
  431. package/foundation/fs/cache-eviction.d.mts +21 -0
  432. package/foundation/fs/cache-eviction.mjs +73 -0
  433. package/foundation/fs/exact-codec.d.mts +12 -2
  434. package/foundation/fs/exact-codec.mjs +23 -6
  435. package/foundation/fs/file-protection.mjs +16 -5
  436. package/foundation/fs/gather-cache.d.mts +94 -4
  437. package/foundation/fs/gather-cache.mjs +671 -106
  438. package/foundation/fs/glob.d.mts +16 -0
  439. package/foundation/fs/glob.mjs +105 -0
  440. package/foundation/fs/jiti-cache.d.mts +19 -1
  441. package/foundation/fs/jiti-cache.mjs +130 -6
  442. package/foundation/fs/kept-tree.d.mts +80 -0
  443. package/foundation/fs/kept-tree.mjs +240 -0
  444. package/foundation/fs/listing-cache.d.mts +7 -0
  445. package/foundation/fs/listing-cache.mjs +10 -0
  446. package/foundation/fs/module-loader.d.mts +24 -2
  447. package/foundation/fs/module-loader.mjs +94 -21
  448. package/foundation/fs/path-safety.d.mts +11 -2
  449. package/foundation/fs/path-safety.mjs +108 -18
  450. package/foundation/fs/paths.d.mts +18 -0
  451. package/foundation/fs/paths.mjs +15 -2
  452. package/foundation/fs/read-record.d.mts +56 -7
  453. package/foundation/fs/read-record.mjs +280 -56
  454. package/foundation/fs/regular-file.d.mts +29 -0
  455. package/foundation/fs/regular-file.mjs +77 -0
  456. package/foundation/fs/stop-cleanup.d.mts +12 -0
  457. package/foundation/fs/stop-cleanup.mjs +66 -0
  458. package/foundation/identity/provider-identity.d.mts +6 -0
  459. package/foundation/identity/provider-identity.mjs +10 -1
  460. package/foundation/integrations/contribution-inventory.mjs +4 -3
  461. package/foundation/integrations/example-code.d.mts +63 -0
  462. package/foundation/integrations/example-code.mjs +416 -0
  463. package/foundation/integrations/integrations.d.mts +23 -1
  464. package/foundation/integrations/integrations.mjs +18 -1
  465. package/foundation/integrations/pack-state.d.mts +75 -0
  466. package/foundation/integrations/pack-state.mjs +314 -0
  467. package/foundation/integrations/public-imports.d.mts +9 -0
  468. package/foundation/integrations/public-imports.mjs +3 -2
  469. package/foundation/integrations/shipped-imports.d.mts +122 -0
  470. package/foundation/integrations/shipped-imports.mjs +497 -0
  471. package/foundation/integrations/validate-contributions.d.mts +0 -17
  472. package/foundation/integrations/validate-contributions.mjs +59 -333
  473. package/foundation/render/assets.mjs +52 -7
  474. package/foundation/render/charts.d.mts +78 -27
  475. package/foundation/render/charts.mjs +266 -90
  476. package/foundation/render/embedded-files.d.mts +6 -0
  477. package/foundation/render/embedded-files.mjs +25 -5
  478. package/foundation/render/embedded-imports.d.mts +70 -7
  479. package/foundation/render/embedded-imports.mjs +132 -41
  480. package/foundation/render/file-header.d.mts +66 -0
  481. package/foundation/render/file-header.mjs +118 -0
  482. package/foundation/render/host-answer.d.mts +18 -0
  483. package/foundation/render/host-answer.mjs +46 -0
  484. package/foundation/render/host-exit.d.mts +1 -0
  485. package/foundation/render/host-exit.mjs +6 -1
  486. package/foundation/render/html-reader.d.mts +55 -2
  487. package/foundation/render/html-reader.mjs +145 -26
  488. package/foundation/render/layers.d.mts +30 -0
  489. package/foundation/render/layers.mjs +158 -0
  490. package/foundation/render/markup-edits.d.mts +57 -0
  491. package/foundation/render/markup-edits.mjs +182 -0
  492. package/foundation/render/offline.d.mts +32 -0
  493. package/foundation/render/offline.mjs +56 -0
  494. package/foundation/render/page-host.mjs +29 -12
  495. package/foundation/render/page-worker.mjs +354 -21
  496. package/foundation/render/picture-chrome.d.mts +4 -0
  497. package/foundation/render/picture-chrome.mjs +192 -0
  498. package/foundation/render/picture-playwright.d.mts +4 -0
  499. package/foundation/render/picture-playwright.mjs +46 -0
  500. package/foundation/render/rebuild.mjs +2 -1
  501. package/foundation/render/render-page.d.mts +79 -5
  502. package/foundation/render/render-page.mjs +735 -109
  503. package/foundation/render/source-block.d.mts +85 -6
  504. package/foundation/render/source-block.mjs +211 -20
  505. package/foundation/render/ts-paths.d.mts +69 -6
  506. package/foundation/render/ts-paths.mjs +326 -40
  507. package/foundation/response/error-codes.d.mts +3 -1
  508. package/foundation/response/error-codes.d.ts +1 -0
  509. package/foundation/response/error-codes.doc.mjs +12 -1
  510. package/foundation/response/error-codes.mjs +11 -1
  511. package/foundation/response/response-types.doc.mjs +6 -6
  512. package/foundation/suggest/name-index.d.mts +148 -0
  513. package/foundation/suggest/name-index.mjs +317 -0
  514. package/foundation/suggest/other-command.d.mts +140 -0
  515. package/foundation/suggest/other-command.mjs +756 -0
  516. package/foundation/text/compare-text.d.mts +14 -0
  517. package/foundation/text/compare-text.mjs +68 -0
  518. package/foundation/text/css-escape.d.mts +18 -0
  519. package/foundation/text/css-escape.mjs +35 -0
  520. package/foundation/text/entry-names.d.mts +14 -0
  521. package/foundation/text/entry-names.mjs +14 -0
  522. package/foundation/text/string-utils.d.mts +46 -6
  523. package/foundation/text/string-utils.mjs +118 -20
  524. package/foundation/text/suggest-order.d.mts +47 -4
  525. package/foundation/text/suggest-order.mjs +174 -5
  526. package/foundation/xle/browser.d.mts +2 -2
  527. package/foundation/xle/expand.mjs +2 -1
  528. package/host/index.mjs +8 -6
  529. package/package.json +7 -6
@@ -31,6 +31,10 @@
31
31
 
32
32
  import * as fs from 'node:fs';
33
33
  import * as path from 'node:path';
34
+ import {
35
+ fontKey,
36
+ stylesheetFontFamilies,
37
+ } from '../../../foundation/fonts/font-stylesheet.mjs';
34
38
  import {fileURLToPath} from 'node:url';
35
39
  import {spawn} from 'node:child_process';
36
40
  import {
@@ -63,6 +67,7 @@ import {
63
67
  themeTemplate,
64
68
  } from '../../../api/theme/template/template.mjs';
65
69
  import {findPackageRoot} from '../../../foundation/fs/paths.mjs';
70
+ import {expandGlob} from '../../../foundation/fs/glob.mjs';
66
71
  import {
67
72
  themeListAvailable,
68
73
  themeListCopySources,
@@ -76,6 +81,7 @@ import {
76
81
  themePaletteGenerate,
77
82
  } from '../../../api/theme/palette/generate/generate.mjs';
78
83
  import {
84
+ GENERATED_MARKER,
79
85
  printBatchTrailer,
80
86
  printCompactTrailer,
81
87
  setEditorFolderListener,
@@ -85,6 +91,7 @@ import {
85
91
  themeSourceFiles,
86
92
  themeSourceGuesses,
87
93
  buildSuggestion,
94
+ generatedSourceCommand,
88
95
  writeDeferredBuildOutputs,
89
96
  } from '../../../api/theme/build/build.mjs';
90
97
  import {defineCommand} from '../lib/define-command.mjs';
@@ -119,13 +126,46 @@ import {doc as themePaletteGenerateFn} from '../../../api/theme/themePaletteGene
119
126
  * @property {string} build - The build subcommand's name: `build` or `compile`.
120
127
  * @property {(err: import('../../../api/error.mjs').AstryxError, cwd: string) => import('../../../api/error.mjs').AstryxError | null} [explain] - A clearer refusal for this group, or null.
121
128
  * @property {(files: string[], options: {cwd: string, check?: boolean, family?: boolean, iconsSpecifier?: string, out?: string}) => Promise<import('../../../api/error.mjs').AstryxError | null>} [preflight] - A refusal before a build starts, or null.
122
- * @property {(files: string[], options: {cwd: string}) => Promise<() => Promise<void>>} [hold] - Locks held while a build or check runs; resolves to their release.
129
+ * @property {(err: import('../../../api/error.mjs').AstryxError, cwd: string) => Promise<import('../../../api/error.mjs').AstryxError>} [follow] - The refusal with its first suggested build checked and repaired as the build would check it.
130
+ * @property {(file: string, cwd: string) => import('../../../api/theme/build/build.mjs').FontHelp | null} [fontHelp] - How a group says to load a theme's fonts when it loads them itself (the editor's app copy).
131
+ * @property {(file: string, cwd: string) => string | null} [install] - How the app takes a theme a group wires another way than importing the build's outputs (the editor's app copy), for the full report.
132
+ * @property {(file: string, cwd: string) => string | null} [sourcePath] - The path a source builds under, when not the typed one; null to keep it.
133
+ * @property {(files: string[], cwd: string) => Promise<Record<string, Record<string, unknown>>>} [afterBuild] - Writes a group makes once a build's outputs are written (the editor's app copy), with what each did, by file, for its result.
134
+ * @property {(files: string[], options: {cwd: string, check?: boolean, out?: string}) => Promise<() => Promise<void>>} [hold] - Locks held while a build or check runs; resolves to their release.
135
+ * @property {(file: string, cwd: string, opts: {check: boolean, upToDate?: boolean, out?: string, iconsSpecifier?: string}) => Record<string, unknown> | null | Promise<Record<string, unknown> | null>} [extraData] - Fields a group adds to a build's result data (the editor's `appCopyStale`); in a check, `upToDate: false` fails it.
136
+ * @property {(file: string, cwd: string) => (['light'] | ['dark'] | null)} [colorModes] - The one color mode a theme file has that the file itself cannot say, for the build to write into the built module.
137
+ * @property {(file: string, cwd: string) => ((family: string) => boolean) | null | Promise<((family: string) => boolean) | null>} [loadedFonts] - Font families the app loads for a theme file that the file itself cannot say, so the build does not name them as unloaded.
123
138
  * @property {(file: string, cwd: string) => {name: string, reason: string} | null} [missingSource] - For a source file that is not there, this group's way to write it again, or null.
124
139
  * @property {(options: {targetPath?: string, overwrite?: boolean, cwd?: string}) => import('../../../api/theme/theme.type.mjs').ThemeTemplateResponse} [template] - This group's template write, in place of `themeTemplate`.
125
140
  */
126
141
 
127
142
  /** @type {ThemeCommandWords} */
128
- const THEME_WORDS = {group: 'theme', build: 'build'};
143
+ const THEME_WORDS = {
144
+ group: 'theme',
145
+ build: 'build',
146
+ loadedFonts: fontsLoadedBeside,
147
+ };
148
+
149
+ /**
150
+ * The font families a local theme's font stylesheet loads: the
151
+ * `<slug>.fonts.css` beside its source, where the theme's folder is named
152
+ * for its slug (the one font stylesheet `theme add` imports for it), read
153
+ * with its imports (an @fontsource package by its name, a stylesheet by its
154
+ * @font-face rules or the `family=` it requests). A build of that source
155
+ * does not name those families as unloaded. Another stylesheet in the
156
+ * folder loads nothing for the app, so it counts for nothing. Null when the
157
+ * theme has no font stylesheet.
158
+ * @param {string} file the theme source, as given
159
+ * @param {string} cwd
160
+ * @returns {((family: string) => boolean) | null}
161
+ */
162
+ function fontsLoadedBeside(file, cwd) {
163
+ const dir = path.dirname(path.resolve(cwd, file));
164
+ const sheet = path.join(dir, `${path.basename(dir)}.fonts.css`);
165
+ if (!fs.existsSync(sheet)) return null;
166
+ const loaded = stylesheetFontFamilies(sheet);
167
+ return loaded.size ? family => loaded.has(fontKey(family)) : null;
168
+ }
129
169
 
130
170
  /**
131
171
  * Text as the group that ran the command words it: under `experimental
@@ -193,13 +233,16 @@ function inGroupNotes(result, words) {
193
233
  * group that works whatever went wrong.
194
234
  * @param {import('../../../api/error.mjs').AstryxError} err
195
235
  * @param {ThemeCommandWords} [words]
196
- * @param {Array<{name: string, reason: string}>} [fallback]
236
+ * @param {Array<{name: string, reason?: string}>} [fallback]
197
237
  */
198
238
  function themeError(err, words = THEME_WORDS, fallback = []) {
199
239
  err = words.explain?.(err, process.cwd()) ?? err;
200
240
  /** @param {string} text */
201
241
  const local = text => inGroupWords(text, words);
202
242
  const given = err.suggestions || [];
243
+ // Suggested commands stay bare (`astryx …`): the JSON envelope carries
244
+ // them so, and the text output starts them the way this project runs the
245
+ // CLI.
203
246
  return cliError(local(err.message), {
204
247
  suggestions: (given.length > 0 ? given : fallback).map(x => ({
205
248
  ...x,
@@ -210,6 +253,122 @@ function themeError(err, words = THEME_WORDS, fallback = []) {
210
253
  });
211
254
  }
212
255
 
256
+ /**
257
+ * Add a group's fields to a build's result data. Its warnings and notices
258
+ * join the build's own, and are printed as the build's are (`--json`
259
+ * prints none).
260
+ * @param {Record<string, any>} data
261
+ * @param {Record<string, unknown>} extra
262
+ */
263
+ function mergeResultData(data, extra) {
264
+ const {warnings, notices, ...rest} = /** @type {any} */ (extra);
265
+ Object.assign(data, rest);
266
+ if (Array.isArray(warnings) && warnings.length > 0) {
267
+ data.warnings = [...(data.warnings ?? []), ...warnings];
268
+ for (const w of warnings) logger.warn(`Warning: ${w}`);
269
+ }
270
+ if (Array.isArray(notices) && notices.length > 0) {
271
+ data.notices = [...(data.notices ?? []), ...notices];
272
+ for (const n of notices) logger.log(`[note] ${n}`);
273
+ }
274
+ }
275
+
276
+ /**
277
+ * The builds a quoted glob means: each theme source it matches, or for a
278
+ * family run the one family of them, in the caller's mode, each marked for
279
+ * the group's checks.
280
+ * @param {string} pattern
281
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string, family?: boolean, familyKey?: string}} options
282
+ * @param {ThemeCommandWords} words
283
+ */
284
+ function globSuggestions(pattern, options, words) {
285
+ const sources = globSources(pattern);
286
+ const reason = `${sources.length > 1 ? 'theme sources' : 'a theme source'} ${pattern} matches (globs are expanded by your shell, not in quotes)`;
287
+ const mode = {
288
+ check: Boolean(options.check),
289
+ iconsSpecifier: options.iconsSpecifier,
290
+ };
291
+ if (options.family)
292
+ return sources.length
293
+ ? [
294
+ buildRun(
295
+ {
296
+ name: buildSuggestion(sources, options, process.cwd(), words, {
297
+ family: true,
298
+ ...(options.familyKey
299
+ ? {familyKey: String(options.familyKey)}
300
+ : {}),
301
+ }),
302
+ reason,
303
+ },
304
+ sources,
305
+ {...mode, family: true},
306
+ ),
307
+ ]
308
+ : [];
309
+ return sources.map(source =>
310
+ buildRun(
311
+ {name: buildSuggestion(source, options, process.cwd(), words), reason},
312
+ [source],
313
+ {...mode, family: false, out: options.out},
314
+ ),
315
+ );
316
+ }
317
+
318
+ /**
319
+ * The theme sources a glob pattern matches, read from the working folder:
320
+ * the files of a theme module's kind that no build wrote (an output names
321
+ * its source in its header) and that are no type stub.
322
+ * @param {string} pattern
323
+ * @returns {string[]}
324
+ */
325
+ function globSources(pattern) {
326
+ return expandGlob(pattern, process.cwd())
327
+ .filter(
328
+ file =>
329
+ /\.(?:[cm]?[jt]sx?)$/.test(file) &&
330
+ !/\.d\.[cm]?ts$/.test(file) &&
331
+ !fileStartsWith(path.resolve(process.cwd(), file), GENERATED_MARKER),
332
+ )
333
+ .slice(0, 8);
334
+ }
335
+
336
+ /** @param {string} file @param {string} text */
337
+ function fileStartsWith(file, text) {
338
+ try {
339
+ const fd = fs.openSync(file, 'r');
340
+ try {
341
+ const head = Buffer.alloc(600);
342
+ const n = fs.readSync(fd, head, 0, head.length, 0);
343
+ return head.subarray(0, n).toString('utf8').includes(text);
344
+ } finally {
345
+ fs.closeSync(fd);
346
+ }
347
+ } catch {
348
+ return false;
349
+ }
350
+ }
351
+
352
+ /** Marks a suggested build with what it builds, for the group's checks. */
353
+ const BUILD_RUN = Symbol('build run');
354
+
355
+ /**
356
+ * A suggested build, marked with the files and mode it builds so the
357
+ * group's own checks can vet it before it is shown (the mark is not part of
358
+ * what is printed).
359
+ * @template {{name: string, reason: string}} S
360
+ * @param {S} suggestion
361
+ * @param {string[]} files
362
+ * @param {{check?: boolean, family?: boolean, iconsSpecifier?: string, out?: string}} mode
363
+ * @returns {S}
364
+ */
365
+ function buildRun(suggestion, files, mode) {
366
+ return Object.defineProperty(suggestion, BUILD_RUN, {
367
+ value: {files, mode},
368
+ enumerable: false,
369
+ });
370
+ }
371
+
213
372
  /**
214
373
  * A command of this CLI as this project runs it, each argument quoted for the
215
374
  * shell.
@@ -539,6 +698,19 @@ function themeNextSteps(run, words = THEME_WORDS) {
539
698
  : `Import one: ${run} ${words.group} add <slug> [--package <package>]\n${fork}`;
540
699
  }
541
700
 
701
+ /**
702
+ * The list's `wiredBy` line: the provider a theme's package wires it with.
703
+ * The list reads no app source; doctor checks where the app renders it.
704
+ * @param {import('../../../api/theme/theme.type.mjs').ThemeListEntry} theme
705
+ */
706
+ function wiredByLine(theme) {
707
+ if (!theme.wiredBy) return theme;
708
+ return {
709
+ ...theme,
710
+ wiredBy: `wired by ${theme.wiredBy.export} from ${theme.wiredBy.from} when the app renders it; \`${getCliInvocation()} doctor\` checks where`,
711
+ };
712
+ }
713
+
542
714
  /**
543
715
  * Print every field in the `theme.list` entries. Duplicate slugs stay separate
544
716
  * because each record names its owner.
@@ -562,7 +734,7 @@ function printThemeList(
562
734
  } else {
563
735
  emit(
564
736
  section('Themes', `${themes.length} available`),
565
- records(themes, {
737
+ records(themes.map(wiredByLine), {
566
738
  fields: [
567
739
  'slug',
568
740
  'displayName',
@@ -570,12 +742,16 @@ function printThemeList(
570
742
  'maintained',
571
743
  'package',
572
744
  'source',
745
+ 'owner',
746
+ 'installed',
747
+ 'wiredBy',
573
748
  'added',
574
749
  'default',
575
750
  ],
576
751
  layout: 'stacked',
577
752
  format: {
578
753
  maintained: (/** @type {boolean} */ value) => (value ? 'yes' : 'no'),
754
+ installed: (/** @type {boolean} */ value) => (value ? 'yes' : 'no'),
579
755
  added: (/** @type {boolean} */ value) => (value ? 'yes' : 'no'),
580
756
  default: (/** @type {boolean} */ value) => (value ? 'yes' : 'no'),
581
757
  },
@@ -612,8 +788,8 @@ function printThemeList(
612
788
  }
613
789
 
614
790
  /**
615
- * Print every `theme.app` receipt field and the one-time app wiring on the first
616
- * add.
791
+ * Print every `theme.app` receipt field, the one-time app wiring on the first
792
+ * add, and the wiring to drop when the last theme's module is deleted.
617
793
  * @param {import('../../../api/theme/theme.type.mjs').ThemeAppResponse} result
618
794
  */
619
795
  function printThemeApp(result) {
@@ -629,6 +805,7 @@ function printThemeApp(result) {
629
805
  'stylesheet',
630
806
  'fontStylesheet',
631
807
  'source',
808
+ 'mode',
632
809
  ],
633
810
  layout: 'stacked',
634
811
  }),
@@ -641,6 +818,9 @@ function printThemeApp(result) {
641
818
  slug: change.slug,
642
819
  changed: change.changed,
643
820
  firstAdd: change.firstAdd,
821
+ ...(change.wireModes ? {wireModes: true} : {}),
822
+ ...(change.moduleRemoved ? {moduleRemoved: true} : {}),
823
+ ...(change.themeModes ? {themeModes: true} : {}),
644
824
  },
645
825
  ],
646
826
  {
@@ -651,20 +831,88 @@ function printThemeApp(result) {
651
831
  'slug',
652
832
  'changed',
653
833
  'firstAdd',
834
+ 'wireModes',
835
+ 'moduleRemoved',
836
+ 'themeModes',
654
837
  ],
655
838
  layout: 'stacked',
656
839
  },
657
840
  ),
658
841
  );
659
842
  for (const note of result.data.notes ?? []) emit(text(`[note] ${note}`));
660
- if (!change.firstAdd) return;
661
843
  const stem = path.basename(modulePath, path.extname(modulePath));
844
+ const appProvider = result.data.appProvider;
845
+ // The one provider that takes the theme (its manifest's themeProp) is the
846
+ // app's wiring: each receipt shows that provider, with the module's theme
847
+ // passed to it, in place of a Theme wrap the app does not render.
848
+ const provider =
849
+ appProvider?.line && appProvider.wiredBy.length === 1
850
+ ? appProvider.wiredBy[0]
851
+ : null;
852
+ const providerCode = () =>
853
+ code(
854
+ `import {${provider?.export}} from '${provider?.from}';\n` +
855
+ `import {themes, defaultThemeSlug${/\bthemeModes\[/.test(String(appProvider?.line)) ? ', themeModes' : ''}} from './${stem}';\n\n` +
856
+ `${appProvider?.line}\n <App />\n</${provider?.export}>`,
857
+ );
858
+ if (change.moduleRemoved) {
859
+ if (appProvider && provider) {
860
+ emit(
861
+ text(
862
+ `Removed ${change.slug}, the only added theme, and deleted ${modulePath}. ${appProvider.wire}`,
863
+ ),
864
+ providerCode(),
865
+ );
866
+ return;
867
+ }
868
+ emit(
869
+ text(
870
+ `Removed ${change.slug}, the only added theme, and deleted ${modulePath}. Undo its wiring in the app root: delete the module's import (and the Theme import when nothing else uses Theme), and keep only the children of the Theme wrapper:`,
871
+ ),
872
+ code(
873
+ "import {Theme} from '@astryxdesign/core/theme';\n" +
874
+ `import {themes, defaultThemeSlug${change.themeModes ? ', themeModes' : ''}} from './${stem}';\n\n` +
875
+ `<Theme theme={themes[defaultThemeSlug]}${change.themeModes ? " mode={themeModes[defaultThemeSlug] ?? 'system'}" : ''}>\n <App />\n</Theme>`,
876
+ ),
877
+ );
878
+ return;
879
+ }
880
+ if (!change.firstAdd) {
881
+ // The module now lists one-mode themes' modes: the app's wiring, made
882
+ // without them, passes the selected theme's mode from now on.
883
+ if (change.wireModes) {
884
+ if (appProvider) {
885
+ emit(text(appProvider.wire), ...(provider ? [providerCode()] : []));
886
+ return;
887
+ }
888
+ emit(
889
+ text(
890
+ "The theme module now exports themeModes. Pass the selected theme's mode to Theme in the app root:",
891
+ ),
892
+ code(
893
+ "import {Theme} from '@astryxdesign/core/theme';\n" +
894
+ `import {themes, defaultThemeSlug, themeModes} from './${stem}';\n\n` +
895
+ "<Theme theme={themes[defaultThemeSlug]} mode={themeModes[defaultThemeSlug] ?? 'system'}>\n <App />\n</Theme>",
896
+ ),
897
+ );
898
+ }
899
+ return;
900
+ }
901
+ // With a theme of one color mode added, the generated module lists each
902
+ // such theme's mode in `themeModes`, and the wiring passes the selected
903
+ // theme's (none for a two-mode theme, which follows the system).
904
+ const modes = result.data.themes.some(t => t.mode);
905
+ if (appProvider && provider) {
906
+ emit(text(appProvider.wire), providerCode());
907
+ return;
908
+ }
662
909
  emit(
910
+ ...(appProvider ? [text(appProvider.wire)] : []),
663
911
  text('Wire the generated module once in the app root:'),
664
912
  code(
665
913
  "import {Theme} from '@astryxdesign/core/theme';\n" +
666
- `import {themes, defaultThemeSlug} from './${stem}';\n\n` +
667
- '<Theme theme={themes[defaultThemeSlug]}>\n <App />\n</Theme>',
914
+ `import {themes, defaultThemeSlug${modes ? ', themeModes' : ''}} from './${stem}';\n\n` +
915
+ `<Theme theme={themes[defaultThemeSlug]}${modes ? " mode={themeModes[defaultThemeSlug] ?? 'system'}" : ''}>\n <App />\n</Theme>`,
668
916
  ),
669
917
  );
670
918
  }
@@ -964,90 +1212,154 @@ function registerPaletteCommands(
964
1212
  * @param {ThemeCommandWords} words
965
1213
  */
966
1214
  function registerThemeCommands(theme, program, docs, words) {
967
- const buildCli = defineCommand(theme, docs.build, {
968
- fn: themeBuildFn,
969
- action: async (
970
- /** @type {string[]} */ files,
971
- /** @type {{out?: string, watch?: boolean, check?: boolean, iconsSpecifier?: string, family?: boolean, familyKey?: string}} */ options,
972
- ) => {
973
- const json = program.opts().json || false;
974
- // The report is one line per theme unless the user asks for
975
- // `--detail full`, which prints the install example and the font
976
- // guidance: once for one theme, as it always has, and once for the whole
977
- // batch rather than per theme.
978
- const detailChosen = program.getOptionValueSource('detail') !== 'default';
979
- const detail = detailChosen ? program.opts().detail : undefined;
980
- const compact = detail !== 'full';
981
- const entries = files.map(file => ({
982
- file,
983
- filePath: path.resolve(process.cwd(), file),
984
- }));
985
-
986
- for (const entry of entries) {
987
- if (fs.existsSync(entry.filePath)) continue;
988
- // A quoted glob reaches us unexpanded: say so rather than reporting a
989
- // literal `themes/*.ts` as a missing file.
990
- const looksGlobby = /[*?[\]{}]/.test(entry.file);
991
- const guesses = looksGlobby
992
- ? []
993
- : themeSourceGuesses(entry.file, process.cwd());
994
- // An editor theme's own source, deleted by hand: the editor writes
995
- // it again.
996
- const rewrite = looksGlobby
997
- ? null
998
- : (words.missingSource?.(entry.file, process.cwd()) ?? null);
999
- return cliError(`File not found: ${entry.filePath}`, {
1000
- code: ERROR_CODES.ERR_FILE_NOT_FOUND,
1001
- suggestions: rewrite
1002
- ? [rewrite]
1003
- : looksGlobby
1215
+ /** The locks the group holds for one build run (see words.hold below). */
1216
+ /** @type {(() => Promise<void>) | undefined} */
1217
+ let release;
1218
+ const buildAction = async (
1219
+ /** @type {string[]} */ typedFiles,
1220
+ /** @type {{out?: string, watch?: boolean, check?: boolean, iconsSpecifier?: string, family?: boolean, familyKey?: string}} */ options,
1221
+ ) => {
1222
+ // A group may name the path a source builds under (an editor theme
1223
+ // reached through a link builds under its own path, which its
1224
+ // outputs' headers name).
1225
+ const files = typedFiles.map(
1226
+ file => words.sourcePath?.(file, process.cwd()) ?? file,
1227
+ );
1228
+ // Every suggested build passes the group's own checks before it is
1229
+ // shown (from a subfolder an editor theme compiles from the app
1230
+ // root): a suggestion the group refuses gives way to the group's own
1231
+ // suggestion, which does.
1232
+ /** @param {Array<{name: string, reason?: string}> | undefined} list */
1233
+ const vet = async list => {
1234
+ /** @type {Array<{name: string, reason?: string}>} */
1235
+ const out = [];
1236
+ for (const s of list ?? []) {
1237
+ const run = /** @type {any} */ (s)[BUILD_RUN];
1238
+ const refused = run
1239
+ ? await words.preflight?.(run.files, {
1240
+ cwd: process.cwd(),
1241
+ ...run.mode,
1242
+ })
1243
+ : null;
1244
+ out.push(...(refused ? (refused.suggestions ?? []) : [s]));
1245
+ }
1246
+ return out;
1247
+ };
1248
+ /** @param {string} message @param {Parameters<typeof cliError>[1]} [opts] */
1249
+ const refuse = async (message, opts = {}) =>
1250
+ cliError(message, {
1251
+ ...opts,
1252
+ suggestions: await vet(opts.suggestions),
1253
+ });
1254
+ /**
1255
+ * @param {import('../../../api/error.mjs').AstryxError} err
1256
+ * @param {ThemeCommandWords} [w]
1257
+ * @param {Array<{name: string, reason?: string}>} [fallback]
1258
+ */
1259
+ const refuseTheme = async (err, w = words, fallback = []) => {
1260
+ err.suggestions = await vet(err.suggestions);
1261
+ return themeError(err, w, await vet(fallback));
1262
+ };
1263
+
1264
+ const json = program.opts().json || false;
1265
+ // The report is one line per theme unless the user asks for
1266
+ // `--detail full`, which prints the install example and the font
1267
+ // guidance: once for one theme, as it always has, and once for the whole
1268
+ // batch rather than per theme.
1269
+ const detailChosen = program.getOptionValueSource('detail') !== 'default';
1270
+ const detail = detailChosen ? program.opts().detail : undefined;
1271
+ const compact = detail !== 'full';
1272
+ const entries = files.map(file => ({
1273
+ file,
1274
+ filePath: path.resolve(process.cwd(), file),
1275
+ }));
1276
+
1277
+ for (const entry of entries) {
1278
+ if (fs.existsSync(entry.filePath)) continue;
1279
+ // A quoted glob reaches us unexpanded: say so rather than reporting a
1280
+ // literal `themes/*.ts` as a missing file.
1281
+ const looksGlobby = /[*?[\]{}]/.test(entry.file);
1282
+ const guesses = looksGlobby
1283
+ ? []
1284
+ : themeSourceGuesses(entry.file, process.cwd());
1285
+ // An editor theme's own source, deleted by hand: the editor writes
1286
+ // it again.
1287
+ const rewrite = looksGlobby
1288
+ ? null
1289
+ : (words.missingSource?.(entry.file, process.cwd()) ?? null);
1290
+ // A file another command generates, gone from a folder whose other
1291
+ // files carry that command's mark: that command writes it again; a
1292
+ // blank theme template is no way back.
1293
+ const by =
1294
+ rewrite || looksGlobby ? null : generatedSourceCommand(entry.filePath);
1295
+ if (by)
1296
+ return await refuse(
1297
+ `File not found: ${entry.filePath}. It is a generated file: the files beside it are written by ${by}, so rebuild it with the command that made it.`,
1298
+ {
1299
+ code: ERROR_CODES.ERR_FILE_NOT_FOUND,
1300
+ suggestions: /^astryx(\s|$)/.test(by)
1004
1301
  ? [
1005
1302
  {
1006
- // The pattern stays unquoted: the shell expands it.
1007
- // The caller's mode follows it, quoted, and a family
1008
- // run stays one.
1009
- name: buildSuggestion(
1010
- entry.file,
1011
- options,
1012
- process.cwd(),
1013
- words,
1014
- {
1015
- glob: true,
1016
- family: Boolean(options.family),
1017
- ...(options.family && options.familyKey
1018
- ? {familyKey: String(options.familyKey)}
1019
- : {}),
1020
- },
1021
- ),
1022
- reason:
1023
- 'globs are expanded by your shell; pass the pattern unquoted, or list the files',
1303
+ name: `${getCliInvocation(process.cwd())} ${by.replace(/^astryx\s*/, '')}`.trim(),
1304
+ reason: 'the command that writes these files',
1024
1305
  },
1025
1306
  ]
1026
- : guesses.length > 0
1027
- ? guesses.map(guess => ({
1028
- // The same build of that source: a --check stays a check.
1029
- name: buildSuggestion(guess, options, process.cwd(), words),
1030
- reason: 'a theme source that exists',
1031
- }))
1032
- : [
1033
- themeCommand(
1034
- words,
1035
- 'template',
1036
- ['theme.template.ts'],
1037
- 'start a theme source from the annotated template',
1038
- ),
1039
- ],
1040
- });
1041
- }
1307
+ : [],
1308
+ },
1309
+ );
1310
+ return await refuse(`File not found: ${entry.filePath}`, {
1311
+ code: ERROR_CODES.ERR_FILE_NOT_FOUND,
1312
+ suggestions: rewrite
1313
+ ? [rewrite]
1314
+ : looksGlobby
1315
+ ? // The pattern, expanded as the shell would: the theme
1316
+ // sources it matches, each a build the checks then vet (an
1317
+ // editor theme's own files give way to its source); a
1318
+ // family run, the one family of them.
1319
+ globSuggestions(entry.file, options, words)
1320
+ : guesses.length > 0
1321
+ ? guesses.map(guess =>
1322
+ buildRun(
1323
+ {
1324
+ // The same build of that source: a --check stays a
1325
+ // check.
1326
+ name: buildSuggestion(
1327
+ guess,
1328
+ options,
1329
+ process.cwd(),
1330
+ words,
1331
+ ),
1332
+ reason: 'a theme source that exists',
1333
+ },
1334
+ [guess],
1335
+ {
1336
+ check: Boolean(options.check),
1337
+ family: Boolean(options.family),
1338
+ iconsSpecifier: options.iconsSpecifier,
1339
+ out: options.out,
1340
+ },
1341
+ ),
1342
+ )
1343
+ : [
1344
+ themeCommand(
1345
+ words,
1346
+ 'template',
1347
+ ['theme.template.ts'],
1348
+ 'start a theme source from the annotated template',
1349
+ ),
1350
+ ],
1351
+ });
1352
+ }
1042
1353
 
1043
- /**
1044
- * This build again without some of its options, as the way out of a
1045
- * refusal about how they combine.
1046
- * @param {Array<'out' | 'watch' | 'check' | 'family'>} drop
1047
- * @param {string} reason
1048
- * @param {string[]} [only] the files to build, when not all of them
1049
- */
1050
- const buildWithout = (drop, reason, only = files) =>
1354
+ /**
1355
+ * This build again without some of its options, as the way out of a
1356
+ * refusal about how they combine.
1357
+ * @param {Array<'out' | 'watch' | 'check' | 'family'>} drop
1358
+ * @param {string} reason
1359
+ * @param {string[]} [only] the files to build, when not all of them
1360
+ */
1361
+ const buildWithout = (drop, reason, only = files) =>
1362
+ buildRun(
1051
1363
  themeCommand(
1052
1364
  words,
1053
1365
  words.build,
@@ -1065,407 +1377,503 @@ function registerThemeCommands(theme, program, docs, words) {
1065
1377
  : []),
1066
1378
  ],
1067
1379
  reason,
1068
- );
1069
-
1070
- // A refusal from the build that names no command: without --out the
1071
- // outputs go beside the source; otherwise the annotated template shows
1072
- // a theme source that builds.
1073
- const buildFallback = options.out
1074
- ? [buildWithout(['out'], 'write the outputs beside the source')]
1075
- : [
1076
- themeCommand(
1077
- words,
1078
- 'template',
1079
- ['theme.template.ts'],
1080
- 'an annotated theme source that builds, to compare with',
1081
- ),
1082
- ];
1083
-
1084
- // One file passed twice would build twice and report two themes.
1085
- const seenFiles = new Set();
1086
- for (const entry of entries) {
1087
- const key = fs.realpathSync(entry.filePath);
1088
- if (seenFiles.has(key)) {
1089
- const once = entries
1090
- .filter(
1091
- (other, index) =>
1092
- entries.findIndex(
1093
- first =>
1094
- fs.realpathSync(first.filePath) ===
1095
- fs.realpathSync(other.filePath),
1096
- ) === index,
1097
- )
1098
- .map(other => other.file);
1099
- return cliError(
1100
- `${entry.file} is given more than once. Select each theme file once.`,
1101
- {
1102
- code: ERROR_CODES.ERR_THEME_INVALID,
1103
- suggestions: [buildWithout([], 'each file once', once)],
1104
- },
1105
- );
1106
- }
1107
- seenFiles.add(key);
1108
- }
1380
+ ),
1381
+ only,
1382
+ {
1383
+ check: Boolean(options.check) && !drop.includes('check'),
1384
+ family: Boolean(options.family) && !drop.includes('family'),
1385
+ iconsSpecifier: options.iconsSpecifier,
1386
+ out: drop.includes('out') ? undefined : options.out,
1387
+ },
1388
+ );
1109
1389
 
1110
- // Family mode is a thin orchestration branch over the existing build API.
1111
- // Its key is required exactly with --family, and options that describe one
1112
- // standalone output or a long-running loop remain intentionally separate.
1113
- if (Boolean(options.family) !== Boolean(options.familyKey)) {
1114
- return cliError(
1115
- options.family
1116
- ? '--family requires --family-key <key>'
1117
- : '--family-key requires --family',
1390
+ // A refusal from the build that names no command: without --out the
1391
+ // outputs go beside the source; otherwise the annotated template shows
1392
+ // a theme source that builds.
1393
+ const buildFallback = options.out
1394
+ ? [buildWithout(['out'], 'write the outputs beside the source')]
1395
+ : [
1396
+ themeCommand(
1397
+ words,
1398
+ 'template',
1399
+ ['theme.template.ts'],
1400
+ 'an annotated theme source that builds, to compare with',
1401
+ ),
1402
+ ];
1403
+
1404
+ // One file passed twice would build twice and report two themes.
1405
+ const seenFiles = new Set();
1406
+ for (const entry of entries) {
1407
+ const key = fs.realpathSync(entry.filePath);
1408
+ if (seenFiles.has(key)) {
1409
+ const once = entries
1410
+ .filter(
1411
+ (other, index) =>
1412
+ entries.findIndex(
1413
+ first =>
1414
+ fs.realpathSync(first.filePath) ===
1415
+ fs.realpathSync(other.filePath),
1416
+ ) === index,
1417
+ )
1418
+ .map(other => other.file);
1419
+ return await refuse(
1420
+ `${entry.file} is given more than once. Select each theme file once.`,
1118
1421
  {
1119
1422
  code: ERROR_CODES.ERR_THEME_INVALID,
1120
- suggestions: [
1121
- {
1122
- ...themeCommand(
1123
- words,
1124
- words.build,
1125
- [
1126
- ...files,
1127
- // --out names one output, so it goes with one file only.
1128
- ...(options.out && files.length === 1
1129
- ? ['--out', options.out]
1130
- : []),
1131
- ...(options.iconsSpecifier
1132
- ? ['--icons-specifier', options.iconsSpecifier]
1133
- : []),
1134
- ...(options.check ? ['--check'] : []),
1135
- ],
1136
- 'build each theme on its own',
1137
- ),
1138
- },
1139
- ],
1423
+ suggestions: [buildWithout([], 'each file once', once)],
1140
1424
  },
1141
1425
  );
1142
1426
  }
1143
- if (options.family && options.out) {
1144
- return cliError('--family cannot be combined with --out', {
1427
+ seenFiles.add(key);
1428
+ }
1429
+
1430
+ // Family mode is a thin orchestration branch over the existing build API.
1431
+ // Its key is required exactly with --family, and options that describe one
1432
+ // standalone output or a long-running loop remain intentionally separate.
1433
+ if (Boolean(options.family) !== Boolean(options.familyKey)) {
1434
+ return await refuse(
1435
+ options.family
1436
+ ? '--family requires --family-key <key>'
1437
+ : '--family-key requires --family',
1438
+ {
1145
1439
  code: ERROR_CODES.ERR_THEME_INVALID,
1146
1440
  suggestions: [
1147
- buildWithout(['out'], 'family outputs go beside the family root'),
1441
+ buildRun(
1442
+ themeCommand(
1443
+ words,
1444
+ words.build,
1445
+ [
1446
+ ...files,
1447
+ // --out names one output, so it goes with one file only.
1448
+ ...(options.out && files.length === 1
1449
+ ? ['--out', options.out]
1450
+ : []),
1451
+ ...(options.iconsSpecifier
1452
+ ? ['--icons-specifier', options.iconsSpecifier]
1453
+ : []),
1454
+ ...(options.check ? ['--check'] : []),
1455
+ ],
1456
+ 'build each theme on its own',
1457
+ ),
1458
+ files,
1459
+ {
1460
+ check: Boolean(options.check),
1461
+ family: false,
1462
+ iconsSpecifier: options.iconsSpecifier,
1463
+ out: files.length === 1 ? options.out : undefined,
1464
+ },
1465
+ ),
1148
1466
  ],
1149
- });
1150
- }
1151
- if (options.family && options.watch) {
1152
- return cliError('--family cannot be combined with --watch', {
1467
+ },
1468
+ );
1469
+ }
1470
+ if (options.family && options.out) {
1471
+ return await refuse('--family cannot be combined with --out', {
1472
+ code: ERROR_CODES.ERR_THEME_INVALID,
1473
+ suggestions: [
1474
+ buildWithout(['out'], 'family outputs go beside the family root'),
1475
+ ],
1476
+ });
1477
+ }
1478
+ if (options.family && options.watch) {
1479
+ return await refuse('--family cannot be combined with --watch', {
1480
+ code: ERROR_CODES.ERR_THEME_INVALID,
1481
+ suggestions: [buildWithout(['watch'], 'build the family once')],
1482
+ });
1483
+ }
1484
+
1485
+ // --check and --watch are mutually exclusive: check is a one-shot,
1486
+ // exit-coded verification; watch is a long-running rebuild loop.
1487
+ if (options.check && options.watch) {
1488
+ return await refuse('--check cannot be combined with --watch', {
1489
+ code: ERROR_CODES.ERR_THEME_INVALID,
1490
+ suggestions: [buildWithout(['watch'], 'check once')],
1491
+ });
1492
+ }
1493
+
1494
+ // --out names one output file, so it cannot describe N themes. Without
1495
+ // it each theme writes `<theme name>.css` beside its source, which is
1496
+ // what a multi-theme build wants anyway.
1497
+ if (options.out && entries.length > 1) {
1498
+ return await refuse(
1499
+ `--out takes a single output path and ${entries.length} theme files were given. ` +
1500
+ 'Build them without --out (each theme writes <name>.css next to its source), ' +
1501
+ 'or run one invocation per theme.',
1502
+ {
1153
1503
  code: ERROR_CODES.ERR_THEME_INVALID,
1154
- suggestions: [buildWithout(['watch'], 'build the family once')],
1155
- });
1156
- }
1504
+ suggestions: [
1505
+ buildWithout(
1506
+ ['out'],
1507
+ 'each theme writes <name>.css next to its source',
1508
+ ),
1509
+ ],
1510
+ },
1511
+ );
1512
+ }
1157
1513
 
1158
- // --check and --watch are mutually exclusive: check is a one-shot,
1159
- // exit-coded verification; watch is a long-running rebuild loop.
1160
- if (options.check && options.watch) {
1161
- return cliError('--check cannot be combined with --watch', {
1514
+ // Watch mode: run an initial build, then rebuild on every change to the
1515
+ // theme file. Watch is a human-interactive, long-running mode — it is not
1516
+ // supported in --json (machine) mode, which expects a single envelope.
1517
+ if (options.watch) {
1518
+ if (json) {
1519
+ return await refuse('--watch is not supported with --json', {
1162
1520
  code: ERROR_CODES.ERR_THEME_INVALID,
1163
- suggestions: [buildWithout(['watch'], 'check once')],
1521
+ suggestions: [
1522
+ buildWithout(['watch'], 'build once, with a JSON result'),
1523
+ ],
1164
1524
  });
1165
1525
  }
1526
+ await runThemeBuildWatch(entries, {...options, detail}, words);
1527
+ return NO_RESULT_SET;
1528
+ }
1166
1529
 
1167
- // --out names one output file, so it cannot describe N themes. Without
1168
- // it each theme writes `<theme name>.css` beside its source, which is
1169
- // what a multi-theme build wants anyway.
1170
- if (options.out && entries.length > 1) {
1171
- return cliError(
1172
- `--out takes a single output path and ${entries.length} theme files were given. ` +
1173
- 'Build them without --out (each theme writes <name>.css next to its source), ' +
1174
- 'or run one invocation per theme.',
1530
+ // Non-watch: delegate to the API compiler, once per theme, in argument
1531
+ // order. Enable human output unless in --json mode (log → stdout via
1532
+ // humanLog, warn/error → stderr). The "Building theme from" line, the
1533
+ // [ok]/[warn] lines, and the install instructions are all emitted from
1534
+ // inside themeBuild via the shared logger.
1535
+ logger.setSilent(json);
1536
+ // Started by a watcher (runThemeBuildWatch): hand the editor-folder
1537
+ // warning to it, and let the channel not keep this build alive.
1538
+ const watchChild =
1539
+ typeof process.send === 'function' && process.argv0 === WATCH_CHILD_ARGV0;
1540
+ if (watchChild) {
1541
+ process.channel?.unref();
1542
+ setEditorFolderListener(warning => {
1543
+ // Held open until the message is out, then let go again.
1544
+ process.channel?.ref();
1545
+ process.send?.({type: WATCH_WARNING, text: warning}, () =>
1546
+ process.channel?.unref(),
1547
+ );
1548
+ });
1549
+ }
1550
+
1551
+ const refused = await words.preflight?.(files, {
1552
+ cwd: process.cwd(),
1553
+ check: options.check,
1554
+ family: Boolean(options.family),
1555
+ iconsSpecifier: options.iconsSpecifier,
1556
+ out: options.out,
1557
+ });
1558
+ if (refused)
1559
+ return await refuseTheme(
1560
+ (await words.follow?.(refused, process.cwd())) ?? refused,
1561
+ words,
1562
+ buildFallback,
1563
+ );
1564
+
1565
+ if (options.family) {
1566
+ try {
1567
+ const result = await themeBuildFamily(
1568
+ files,
1175
1569
  {
1176
- code: ERROR_CODES.ERR_THEME_INVALID,
1177
- suggestions: [
1178
- buildWithout(
1179
- ['out'],
1180
- 'each theme writes <name>.css next to its source',
1181
- ),
1182
- ],
1570
+ familyKey: /** @type {string} */ (options.familyKey),
1571
+ check: options.check,
1572
+ iconsSpecifier: options.iconsSpecifier,
1183
1573
  },
1574
+ {cwd: process.cwd()},
1575
+ {commandWords: words},
1184
1576
  );
1185
- }
1186
-
1187
- // Watch mode: run an initial build, then rebuild on every change to the
1188
- // theme file. Watch is a human-interactive, long-running mode — it is not
1189
- // supported in --json (machine) mode, which expects a single envelope.
1190
- if (options.watch) {
1191
- if (json) {
1192
- return cliError('--watch is not supported with --json', {
1193
- code: ERROR_CODES.ERR_THEME_INVALID,
1194
- suggestions: [
1195
- buildWithout(['watch'], 'build once, with a JSON result'),
1196
- ],
1197
- });
1577
+ if (json) jsonOut(result);
1578
+ if (
1579
+ result.type === 'theme.build.check' &&
1580
+ !(
1581
+ /** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse} */ (
1582
+ result
1583
+ ).data.upToDate
1584
+ )
1585
+ ) {
1586
+ process.exitCode = 1;
1198
1587
  }
1199
- await runThemeBuildWatch(entries, {...options, detail}, words);
1200
1588
  return NO_RESULT_SET;
1589
+ } catch (e) {
1590
+ const err =
1591
+ /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1592
+ return await refuseTheme(err, words, [
1593
+ buildWithout(['family'], 'build each theme on its own'),
1594
+ ]);
1201
1595
  }
1596
+ }
1202
1597
 
1203
- // Non-watch: delegate to the API compiler, once per theme, in argument
1204
- // order. Enable human output unless in --json mode (log → stdout via
1205
- // humanLog, warn/error → stderr). The "Building theme from" line, the
1206
- // [ok]/[warn] lines, and the install instructions are all emitted from
1207
- // inside themeBuild via the shared logger.
1208
- logger.setSilent(json);
1209
- // Started by a watcher (runThemeBuildWatch): hand the editor-folder
1210
- // warning to it, and let the channel not keep this build alive.
1211
- const watchChild =
1212
- typeof process.send === 'function' &&
1213
- process.argv0 === WATCH_CHILD_ARGV0;
1214
- if (watchChild) {
1215
- process.channel?.unref();
1216
- setEditorFolderListener(warning => {
1217
- // Held open until the message is out, then let go again.
1218
- process.channel?.ref();
1219
- process.send?.({type: WATCH_WARNING, text: warning}, () =>
1220
- process.channel?.unref(),
1221
- );
1222
- });
1598
+ // --json and --check keep their own output at every detail level.
1599
+ const report = !json && !options.check && (entries.length > 1 || compact);
1600
+ /** @type {import('../../../api/theme/build/build.mjs').ThemeBuildTrailer[]} */
1601
+ const trailers = [];
1602
+
1603
+ /** @type {Array<{file: string, receipt: import('../../../api/theme/theme.type.mjs').ThemeBuildResponse | import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse | null}>} */
1604
+ const results = [];
1605
+ let stale = false;
1606
+ // A batch builds every theme first and then writes them in order, so
1607
+ // two themes that build the same files are refused before either
1608
+ // writes. Any other failure writes the themes built before it, as a
1609
+ // shell loop under `set -e` would have, and stops.
1610
+ const deferred = !options.check && entries.length > 1;
1611
+ // Each built theme keeps its writes and what it prints together; what
1612
+ // it prints waits until its outputs are written, so no `[ok]` line
1613
+ // names a file that is never written.
1614
+ /** @type {Array<{writes: Array<Array<{dest: string, content: string}>>, lines: Array<() => void>}>} */
1615
+ const built = [];
1616
+ const publish = () => {
1617
+ for (const theme of built.splice(0)) {
1618
+ writeDeferredBuildOutputs(theme.writes);
1619
+ for (const show of theme.lines) show();
1223
1620
  }
1224
-
1225
- const refused = await words.preflight?.(files, {
1226
- cwd: process.cwd(),
1227
- check: options.check,
1228
- family: Boolean(options.family),
1229
- iconsSpecifier: options.iconsSpecifier,
1230
- out: options.out,
1231
- });
1232
- if (refused) return themeError(refused, words, buildFallback);
1233
-
1234
- if (options.family) {
1235
- try {
1236
- const result = await themeBuildFamily(
1237
- files,
1238
- {
1239
- familyKey: /** @type {string} */ (options.familyKey),
1240
- check: options.check,
1241
- iconsSpecifier: options.iconsSpecifier,
1242
- },
1621
+ };
1622
+ const writeFailed = async (/** @type {unknown} */ error) =>
1623
+ refuseTheme(
1624
+ /** @type {import('../../../api/error.mjs').AstryxError} */ (error),
1625
+ words,
1626
+ [
1627
+ buildWithout(
1628
+ [],
1629
+ 'run the same build again once the files can be written',
1630
+ ),
1631
+ ],
1632
+ );
1633
+ /** @type {Map<string, string>} */
1634
+ const claimedOutputs = new Map();
1635
+ for (const entry of entries) {
1636
+ /** @type {Array<() => void>} */
1637
+ const lines = [];
1638
+ /** @type {Array<Array<{dest: string, content: string}>>} */
1639
+ const writes = [];
1640
+ const log = logger.log;
1641
+ const warn = logger.warn;
1642
+ // A group may know fonts the app loads that the theme file cannot
1643
+ // say (the editor's app copy stylesheet): the build leaves them out
1644
+ // of every "not loaded" note, family by family.
1645
+ const loads =
1646
+ (await words.loadedFonts?.(entry.file, process.cwd())) ?? null;
1647
+ // A check whose result a group may still fail holds its lines
1648
+ // until the group has looked.
1649
+ /** @type {Array<string | undefined> | null} */
1650
+ let held = null;
1651
+ if (options.check && words.extraData && !deferred) {
1652
+ held = [];
1653
+ logger.log = (/** @type {string | undefined} */ message) => {
1654
+ held?.push(message);
1655
+ };
1656
+ }
1657
+ if (deferred) {
1658
+ logger.log = (/** @type {string | undefined} */ message) => {
1659
+ lines.push(() => log.call(logger, message));
1660
+ };
1661
+ logger.warn = (/** @type {string | undefined} */ message) => {
1662
+ lines.push(() => warn.call(logger, message));
1663
+ };
1664
+ }
1665
+ try {
1666
+ const buildOptions = {
1667
+ out: options.out,
1668
+ check: options.check,
1669
+ iconsSpecifier: options.iconsSpecifier,
1670
+ };
1671
+ /** @type {import('../../../api/theme/build/build.mjs').ThemeBuildHandOff} */
1672
+ const handOff = {
1673
+ claimedOutputs,
1674
+ deferredWrites: deferred ? writes : undefined,
1675
+ commandWords: words,
1676
+ colorModes: words.colorModes?.(entry.file, process.cwd()) ?? null,
1677
+ fontHelp: words.fontHelp?.(entry.file, process.cwd()) ?? null,
1678
+ install: words.install?.(entry.file, process.cwd()) ?? null,
1679
+ loadedFonts: loads,
1680
+ };
1681
+ let result;
1682
+ if (report) {
1683
+ const built = await themeBuildForReport(
1684
+ entry.file,
1685
+ buildOptions,
1243
1686
  {cwd: process.cwd()},
1244
- {commandWords: words},
1687
+ {compact},
1688
+ handOff,
1245
1689
  );
1246
- if (json) jsonOut(result);
1247
- if (
1248
- result.type === 'theme.build.check' &&
1249
- !(
1250
- /** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse} */ (
1251
- result
1252
- ).data.upToDate
1253
- )
1254
- ) {
1255
- process.exitCode = 1;
1690
+ result = built.receipt;
1691
+ if (built.trailer) trailers.push(built.trailer);
1692
+ if (compact && result?.type === 'theme.build') {
1693
+ const {outputs, sizeKB, tokenCount, componentCount} = result.data;
1694
+ const show = () =>
1695
+ emit(
1696
+ text(
1697
+ `[ok] ${outputs.css} (${sizeKB} KB, ${tokenCount} token overrides, ${componentCount} component overrides)`,
1698
+ ),
1699
+ );
1700
+ if (deferred) lines.push(show);
1701
+ else show();
1256
1702
  }
1257
- return NO_RESULT_SET;
1258
- } catch (e) {
1259
- const err =
1260
- /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1261
- return themeError(err, words, [
1262
- buildWithout(['family'], 'build each theme on its own'),
1263
- ]);
1703
+ } else {
1704
+ result = await themeBuildWithHandOff(
1705
+ entry.file,
1706
+ buildOptions,
1707
+ {cwd: process.cwd()},
1708
+ handOff,
1709
+ );
1264
1710
  }
1265
- }
1266
-
1267
- // --json and --check keep their own output at every detail level.
1268
- const report = !json && !options.check && (entries.length > 1 || compact);
1269
- /** @type {import('../../../api/theme/build/build.mjs').ThemeBuildTrailer[]} */
1270
- const trailers = [];
1271
-
1272
- /** @type {Array<{file: string, receipt: import('../../../api/theme/theme.type.mjs').ThemeBuildResponse | import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse | null}>} */
1273
- const results = [];
1274
- let stale = false;
1275
- // A batch builds every theme first and then writes them in order, so
1276
- // two themes that build the same files are refused before either
1277
- // writes. Any other failure writes the themes built before it, as a
1278
- // shell loop under `set -e` would have, and stops.
1279
- const deferred = !options.check && entries.length > 1;
1280
- // Each built theme keeps its writes and what it prints together; what
1281
- // it prints waits until its outputs are written, so no `[ok]` line
1282
- // names a file that is never written.
1283
- /** @type {Array<{writes: Array<Array<{dest: string, content: string}>>, lines: Array<() => void>}>} */
1284
- const built = [];
1285
- const publish = () => {
1286
- for (const theme of built.splice(0)) {
1287
- writeDeferredBuildOutputs(theme.writes);
1288
- for (const show of theme.lines) show();
1711
+ logger.log = log;
1712
+ logger.warn = warn;
1713
+ // A group may add to a build's result (the editor's app copy:
1714
+ // what keeps it behind, and in a check whether it is current).
1715
+ const extra = await words.extraData?.(entry.file, process.cwd(), {
1716
+ check: Boolean(options.check),
1717
+ upToDate: /** @type {any} */ (result)?.data?.upToDate,
1718
+ out: options.out,
1719
+ iconsSpecifier: options.iconsSpecifier,
1720
+ });
1721
+ if (extra && result?.data) mergeResultData(result.data, extra);
1722
+ // A check the group failed says so where the check said ok.
1723
+ if (held) {
1724
+ logger.log = log;
1725
+ for (const line of held)
1726
+ log.call(
1727
+ logger,
1728
+ extra?.upToDate === false &&
1729
+ typeof line === 'string' &&
1730
+ /^\s*\[ok\]/.test(line)
1731
+ ? `[fail] ${String(extra.appCopyStale ?? 'not up to date')}`
1732
+ : line,
1733
+ );
1734
+ held = null;
1289
1735
  }
1290
- };
1291
- const writeFailed = (/** @type {unknown} */ error) =>
1292
- themeError(
1293
- /** @type {import('../../../api/error.mjs').AstryxError} */ (error),
1294
- words,
1295
- [
1296
- buildWithout(
1297
- [],
1298
- 'run the same build again once the files can be written',
1299
- ),
1300
- ],
1301
- );
1302
- /** @type {Map<string, string>} */
1303
- const claimedOutputs = new Map();
1304
- for (const entry of entries) {
1305
- /** @type {Array<() => void>} */
1306
- const lines = [];
1307
- /** @type {Array<Array<{dest: string, content: string}>>} */
1308
- const writes = [];
1309
- const log = logger.log;
1310
- const warn = logger.warn;
1311
- if (deferred) {
1312
- logger.log = (/** @type {string | undefined} */ message) => {
1313
- lines.push(() => log.call(logger, message));
1314
- };
1315
- logger.warn = (/** @type {string | undefined} */ message) => {
1316
- lines.push(() => warn.call(logger, message));
1317
- };
1736
+ results.push({file: entry.file, receipt: result ?? null});
1737
+ if (deferred) built.push({writes, lines});
1738
+ if (
1739
+ options.check &&
1740
+ result &&
1741
+ result.type === 'theme.build.check' &&
1742
+ !result.data.upToDate
1743
+ ) {
1744
+ stale = true;
1318
1745
  }
1319
- try {
1320
- const buildOptions = {
1321
- out: options.out,
1322
- check: options.check,
1323
- iconsSpecifier: options.iconsSpecifier,
1324
- };
1325
- /** @type {import('../../../api/theme/build/build.mjs').ThemeBuildHandOff} */
1326
- const handOff = {
1327
- claimedOutputs,
1328
- deferredWrites: deferred ? writes : undefined,
1329
- commandWords: words,
1330
- };
1331
- let result;
1332
- if (report) {
1333
- const built = await themeBuildForReport(
1334
- entry.file,
1335
- buildOptions,
1336
- {cwd: process.cwd()},
1337
- {compact},
1338
- handOff,
1339
- );
1340
- result = built.receipt;
1341
- if (built.trailer) trailers.push(built.trailer);
1342
- if (compact && result?.type === 'theme.build') {
1343
- const {outputs, sizeKB, tokenCount, componentCount} = result.data;
1344
- const show = () =>
1345
- emit(
1346
- text(
1347
- `[ok] ${outputs.css} (${sizeKB} KB, ${tokenCount} token overrides, ${componentCount} component overrides)`,
1348
- ),
1349
- );
1350
- if (deferred) lines.push(show);
1351
- else show();
1352
- }
1353
- } else {
1354
- result = await themeBuildWithHandOff(
1355
- entry.file,
1356
- buildOptions,
1357
- {cwd: process.cwd()},
1358
- handOff,
1359
- );
1360
- }
1361
- logger.log = log;
1362
- logger.warn = warn;
1363
- results.push({file: entry.file, receipt: result ?? null});
1364
- if (deferred) built.push({writes, lines});
1365
- if (
1366
- options.check &&
1367
- result &&
1368
- result.type === 'theme.build.check' &&
1369
- !result.data.upToDate
1370
- ) {
1371
- stale = true;
1372
- }
1373
- } catch (e) {
1374
- logger.log = log;
1375
- logger.warn = warn;
1376
- const err =
1377
- /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1378
- // Stop at the first failure, as a shell loop under `set -e` does.
1379
- // With several themes in flight the message alone rarely says which
1380
- // one broke, so name it. Themes already written keep their install
1381
- // and font guidance.
1382
- if (/** @type {any} */ (err).outputCollision) {
1383
- // Nothing is written, so only this theme's warnings are shown.
1384
- for (const show of lines) show();
1385
- return themeError(err, words, [
1386
- buildWithout([], 'build the first theme on its own', [
1387
- entries[0].file,
1388
- ]),
1389
- ]);
1390
- }
1391
- if (deferred) {
1392
- try {
1393
- publish();
1394
- } catch (writeError) {
1395
- return writeFailed(writeError);
1396
- }
1397
- // The failing theme's warnings, such as a missing package, say
1398
- // why it failed.
1399
- for (const show of lines) show();
1746
+ } catch (e) {
1747
+ logger.log = log;
1748
+ logger.warn = warn;
1749
+ for (const line of held ?? []) log.call(logger, line);
1750
+ held = null;
1751
+ const err =
1752
+ /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1753
+ // Stop at the first failure, as a shell loop under `set -e` does.
1754
+ // With several themes in flight the message alone rarely says which
1755
+ // one broke, so name it. Themes already written keep their install
1756
+ // and font guidance.
1757
+ if (/** @type {any} */ (err).outputCollision) {
1758
+ // Nothing is written, so only this theme's warnings are shown.
1759
+ for (const show of lines) show();
1760
+ return await refuseTheme(err, words, [
1761
+ buildWithout([], 'build the first theme on its own', [
1762
+ entries[0].file,
1763
+ ]),
1764
+ ]);
1765
+ }
1766
+ if (deferred) {
1767
+ try {
1768
+ publish();
1769
+ } catch (writeError) {
1770
+ return writeFailed(writeError);
1400
1771
  }
1401
- if (report && compact) printCompactTrailer(trailers);
1402
- else if (report) printBatchTrailer(trailers);
1403
- if (entries.length > 1) err.message = `${entry.file}: ${err.message}`;
1404
- return themeError(err, words, buildFallback);
1772
+ // The failing theme's warnings, such as a missing package, say
1773
+ // why it failed.
1774
+ for (const show of lines) show();
1405
1775
  }
1776
+ if (report && compact) printCompactTrailer(trailers);
1777
+ else if (report) printBatchTrailer(trailers);
1778
+ if (entries.length > 1) err.message = `${entry.file}: ${err.message}`;
1779
+ return await refuseTheme(
1780
+ entries.length === 1
1781
+ ? ((await words.follow?.(err, process.cwd())) ?? err)
1782
+ : err,
1783
+ words,
1784
+ buildFallback,
1785
+ );
1406
1786
  }
1407
- if (deferred) {
1408
- try {
1409
- publish();
1410
- } catch (e) {
1411
- return writeFailed(e);
1412
- }
1787
+ }
1788
+ if (deferred) {
1789
+ try {
1790
+ publish();
1791
+ } catch (e) {
1792
+ return writeFailed(e);
1793
+ }
1794
+ }
1795
+ // A group follows the written outputs with writes of its own (the
1796
+ // editor's app copy), and each result says what they did.
1797
+ if (words.afterBuild && !options.check) {
1798
+ const more = await words.afterBuild(
1799
+ results.map(r => r.file),
1800
+ process.cwd(),
1801
+ );
1802
+ for (const r of results) {
1803
+ const data = /** @type {any} */ (r.receipt)?.data;
1804
+ if (data && more[r.file]) mergeResultData(data, more[r.file]);
1413
1805
  }
1806
+ }
1414
1807
 
1415
- if (json) {
1416
- // One theme keeps the single-envelope contract it has always had; a
1417
- // batch gets its own discriminant rather than N envelopes on stdout.
1418
- if (entries.length === 1) {
1419
- if (results[0].receipt) jsonOut(results[0].receipt);
1420
- } else {
1421
- /** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildBatchResponse} */
1422
- const batch = {
1423
- type: 'theme.build.batch',
1424
- data: {count: results.length, results},
1425
- };
1426
- jsonOut(batch);
1427
- }
1808
+ if (json) {
1809
+ // One theme keeps the single-envelope contract it has always had; a
1810
+ // batch gets its own discriminant rather than N envelopes on stdout.
1811
+ if (entries.length === 1) {
1812
+ if (results[0].receipt) jsonOut(results[0].receipt);
1428
1813
  } else {
1429
- if (report && compact) {
1430
- printCompactTrailer(trailers, {hint: !detailChosen});
1431
- } else if (report) {
1432
- printBatchTrailer(trailers);
1433
- }
1814
+ /** @type {import('../../../api/theme/theme.type.mjs').ThemeBuildBatchResponse} */
1815
+ const batch = {
1816
+ type: 'theme.build.batch',
1817
+ data: {count: results.length, results},
1818
+ };
1819
+ jsonOut(batch);
1434
1820
  }
1435
- if (!json && entries.length > 1) {
1436
- emit(
1437
- text(
1438
- options.check
1439
- ? `\n${stale ? '[fail]' : '[ok]'} Checked ${entries.length} themes.`
1440
- : `\n[ok] Built ${entries.length} themes.`,
1441
- ),
1442
- );
1821
+ } else {
1822
+ if (report && compact) {
1823
+ printCompactTrailer(trailers, {hint: !detailChosen});
1824
+ } else if (report) {
1825
+ printBatchTrailer(trailers);
1443
1826
  }
1827
+ }
1828
+ if (!json && entries.length > 1) {
1829
+ emit(
1830
+ text(
1831
+ options.check
1832
+ ? `\n${stale ? '[fail]' : '[ok]'} Checked ${entries.length} themes.`
1833
+ : `\n[ok] Built ${entries.length} themes.`,
1834
+ ),
1835
+ );
1836
+ }
1444
1837
 
1445
- // Stale --check output is a failure after its receipt has been emitted.
1446
- if (options.check && stale) {
1447
- process.exitCode = 1;
1448
- }
1838
+ // Stale --check output is a failure after its receipt has been emitted.
1839
+ if (options.check && stale) {
1840
+ process.exitCode = 1;
1841
+ }
1449
1842
 
1450
- // Compiling a theme writes CSS; `--check` compares what is on disk. Both
1451
- // are effects — the receipt (and the exit code) carry the outcome.
1452
- return NO_RESULT_SET;
1843
+ // Compiling a theme writes CSS; `--check` compares what is on disk. Both
1844
+ // are effects — the receipt (and the exit code) carry the outcome.
1845
+ return NO_RESULT_SET;
1846
+ };
1847
+ const buildCli = defineCommand(theme, docs.build, {
1848
+ fn: themeBuildFn,
1849
+ // The locks taken for the run go when the action ends, however it ends:
1850
+ // a refusal that exits releases them on exit, and a run in process
1851
+ // (which has no exit) here.
1852
+ action: async (
1853
+ /** @type {string[]} */ typedFiles,
1854
+ /** @type {any} */ options,
1855
+ ) => {
1856
+ try {
1857
+ return await buildAction(typedFiles, options);
1858
+ } finally {
1859
+ await release?.();
1860
+ release = undefined;
1861
+ }
1453
1862
  },
1454
1863
  });
1455
1864
  // A group may hold locks while a build or check runs (the editor's theme
1456
1865
  // lock), so it never reads a change half written.
1457
1866
  if (words.hold) {
1458
- /** @type {(() => Promise<void>) | undefined} */
1459
- let release;
1460
1867
  buildCli.hook('preAction', async (_, cmd) => {
1461
1868
  // Under --watch each rebuild runs on its own and takes the locks
1462
1869
  // itself; holding them for the whole watch would block every one.
1463
1870
  if (cmd.opts().watch) return;
1464
- release = await words.hold?.(cmd.args, {cwd: process.cwd()});
1465
- });
1466
- buildCli.hook('postAction', async () => {
1467
- await release?.();
1468
- release = undefined;
1871
+ const o = cmd.opts();
1872
+ release = await words.hold?.(cmd.args, {
1873
+ cwd: process.cwd(),
1874
+ check: Boolean(o.check),
1875
+ out: o.out,
1876
+ });
1469
1877
  });
1470
1878
  }
1471
1879