@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0135e03

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 (369) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +12 -0
  3. package/api/build/_adapter.mjs +51 -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 +4 -3
  7. package/api/build/build.type.d.mts +2 -2
  8. package/api/build/build.type.mjs +3 -3
  9. package/api/build/kit/kind.d.mts +2 -1
  10. package/api/build/kit/kind.mjs +199 -10
  11. package/api/build/kit/kit.mjs +6 -4
  12. package/api/build/kit/rank.d.mts +4 -2
  13. package/api/build/kit/rank.mjs +125 -24
  14. package/api/build/kit/start.d.mts +5 -4
  15. package/api/build/kit/start.mjs +12 -8
  16. package/api/build/kit/weights.d.mts +39 -3
  17. package/api/build/kit/weights.json +1 -1
  18. package/api/build/kit/weights.mjs +340 -43
  19. package/api/build/kit/word-model.d.mts +23 -0
  20. package/api/build/kit/word-model.mjs +46 -0
  21. package/api/build/kit/words.d.mts +48 -0
  22. package/api/build/kit/words.mjs +90 -1
  23. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  24. package/api/component/list/list.d.mts +1 -1
  25. package/api/component/list/list.mjs +48 -6
  26. package/api/discover/_adapter.d.mts +1 -1
  27. package/api/discover/search/search.mjs +3 -2
  28. package/api/docs/_adapter.d.mts +26 -2
  29. package/api/docs/_adapter.mjs +219 -6
  30. package/api/docs/docs.d.mts +3 -0
  31. package/api/docs/docs.doc.mjs +7 -1
  32. package/api/docs/docs.mjs +12 -0
  33. package/api/docs/docs.type.d.mts +5 -0
  34. package/api/docs/docs.type.mjs +2 -0
  35. package/api/docs/node/node.mjs +1 -1
  36. package/api/doctor/_adapter.d.mts +27 -5
  37. package/api/doctor/_adapter.mjs +83 -10
  38. package/api/doctor/built-checks.mjs +40 -14
  39. package/api/doctor/doctor.d.mts +4 -3
  40. package/api/doctor/doctor.mjs +14 -7
  41. package/api/doctor/theme-checks.mjs +121 -17
  42. package/api/icon/_records.mjs +2 -1
  43. package/api/index.d.mts +2 -0
  44. package/api/index.mjs +2 -0
  45. package/api/integration/_adapter.d.mts +44 -0
  46. package/api/integration/_adapter.mjs +77 -1
  47. package/api/integration/authoring-checks.mjs +6 -6
  48. package/api/integration/example-scope.d.mts +14 -0
  49. package/api/integration/example-scope.mjs +44 -0
  50. package/api/integration/example-scope.type.d.mts +29 -0
  51. package/api/integration/example-scope.type.mjs +25 -0
  52. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  53. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  54. package/api/integration/validate-integration.mjs +19 -1
  55. package/api/integration/validate-integration.type.d.mts +9 -0
  56. package/api/integration/validate-integration.type.mjs +1 -1
  57. package/api/integration/validateIntegration.doc.mjs +1 -1
  58. package/api/render/_adapter.mjs +591 -195
  59. package/api/render/render.doc.mjs +11 -3
  60. package/api/render/render.type.d.mts +52 -0
  61. package/api/render/render.type.mjs +31 -1
  62. package/api/search/ORDERING.md +1 -1
  63. package/api/search/_adapter.d.mts +9 -0
  64. package/api/search/_adapter.mjs +85 -0
  65. package/api/search/_candidate-score.mjs +51 -32
  66. package/api/search/_fit-order.mjs +3 -3
  67. package/api/search/_gather-components.d.mts +3 -2
  68. package/api/search/_gather-components.mjs +12 -3
  69. package/api/search/_lexical.d.mts +5 -0
  70. package/api/search/_lexical.mjs +8 -2
  71. package/api/search/_result.d.mts +11 -9
  72. package/api/search/_result.mjs +4 -4
  73. package/api/search/_score.d.mts +6 -1
  74. package/api/search/_score.mjs +15 -3
  75. package/api/search/search-index.mjs +7 -1
  76. package/api/search/search.d.mts +1 -1
  77. package/api/theme/_adapter.mjs +12 -1
  78. package/api/theme/build/build.d.mts +122 -1
  79. package/api/theme/build/build.mjs +412 -84
  80. package/api/theme/build/core-interception.d.mts +10 -0
  81. package/api/theme/build/core-interception.mjs +10 -0
  82. package/api/theme/build/font-warning.d.mts +23 -3
  83. package/api/theme/build/font-warning.mjs +54 -5
  84. package/api/theme/build/icon-imports.mjs +25 -2
  85. package/api/theme/theme.type.d.mts +10 -0
  86. package/api/theme/theme.type.mjs +7 -1
  87. package/api/theme-edit/_adapter.d.mts +103 -3
  88. package/api/theme-edit/_adapter.mjs +961 -82
  89. package/api/theme-edit/_catalog.mjs +19 -4
  90. package/api/theme-edit/_check.d.mts +63 -24
  91. package/api/theme-edit/_check.mjs +2467 -362
  92. package/api/theme-edit/_color.d.mts +10 -0
  93. package/api/theme-edit/_color.mjs +49 -1
  94. package/api/theme-edit/_compiler.mjs +89 -6
  95. package/api/theme-edit/_context.d.mts +3 -3
  96. package/api/theme-edit/_context.mjs +165 -54
  97. package/api/theme-edit/_css.d.mts +14 -0
  98. package/api/theme-edit/_css.mjs +46 -1
  99. package/api/theme-edit/_edit.d.mts +31 -4
  100. package/api/theme-edit/_edit.mjs +2433 -204
  101. package/api/theme-edit/_how-commands.d.mts +72 -1
  102. package/api/theme-edit/_how-commands.mjs +759 -9
  103. package/api/theme-edit/_how-question.d.mts +82 -5
  104. package/api/theme-edit/_how-question.mjs +6473 -553
  105. package/api/theme-edit/_how.d.mts +2 -1
  106. package/api/theme-edit/_how.mjs +237 -41
  107. package/api/theme-edit/_marks.d.mts +31 -5
  108. package/api/theme-edit/_marks.mjs +57 -5
  109. package/api/theme-edit/_name-rule.d.mts +11 -0
  110. package/api/theme-edit/_name-rule.mjs +12 -0
  111. package/api/theme-edit/_normal.d.mts +292 -0
  112. package/api/theme-edit/_normal.mjs +1454 -0
  113. package/api/theme-edit/_palette.mjs +10 -4
  114. package/api/theme-edit/_part-words.d.mts +31 -0
  115. package/api/theme-edit/_part-words.mjs +126 -0
  116. package/api/theme-edit/_parts.d.mts +18 -1
  117. package/api/theme-edit/_parts.mjs +246 -23
  118. package/api/theme-edit/_preview-app.d.mts +7 -1
  119. package/api/theme-edit/_preview-app.mjs +776 -187
  120. package/api/theme-edit/_preview.d.mts +100 -14
  121. package/api/theme-edit/_preview.mjs +582 -139
  122. package/api/theme-edit/_project.d.mts +4 -0
  123. package/api/theme-edit/_project.mjs +3 -1
  124. package/api/theme-edit/_settings.d.mts +417 -42
  125. package/api/theme-edit/_settings.mjs +3262 -424
  126. package/api/theme-edit/_tables.d.mts +15 -0
  127. package/api/theme-edit/_tables.mjs +63 -1
  128. package/api/theme-edit/_vet.d.mts +20 -0
  129. package/api/theme-edit/_vet.mjs +47 -2
  130. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  131. package/api/theme-edit/theme-edit.type.mjs +4 -1
  132. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  133. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  134. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  135. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  136. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  137. package/api/upgrade/run/run.mjs +4 -3
  138. package/assets/codemods/integration-discovery.mjs +2 -1
  139. package/assets/codemods/run-codemod.mjs +87 -7
  140. package/assets/codemods/transforms/next/index.mjs +11 -1
  141. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  142. package/assets/component-list.generated.json +1 -0
  143. package/assets/docs/author-a-theme.doc.mjs +1 -0
  144. package/assets/docs/theme.doc.dense.mjs +2 -2
  145. package/assets/docs/theme.doc.mjs +1 -1
  146. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  147. package/assets/docs/tree/checks.doc.mjs +1 -1
  148. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  149. package/assets/docs/tree/render-pages.doc.mjs +44 -3
  150. package/assets/docs/tree/single-component.doc.mjs +4 -0
  151. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  152. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  153. package/assets/docs/use-a-theme.doc.mjs +1 -1
  154. package/assets/docs.generated.json +2 -2
  155. package/assets/search-catalog.generated.json +2 -0
  156. package/assets/self-audit.generated.json +1 -1
  157. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  158. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  159. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  160. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  161. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  162. package/assets/templates/components.generated.json +1 -1
  163. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  164. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
  165. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  166. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  167. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  168. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  169. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  170. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  171. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  172. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  173. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  174. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  175. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  176. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  177. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  178. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  179. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  180. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  181. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  182. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  183. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  184. package/assets/templates/pages/ide/page.tsx +24 -2
  185. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  186. package/assets/templates/pages/library/template.doc.mjs +4 -1
  187. package/assets/templates/pages/login/template.doc.mjs +2 -1
  188. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  189. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  190. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  191. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  192. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  193. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  194. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  195. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  196. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  197. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  198. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  199. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  200. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  201. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  202. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  203. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  204. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  205. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  206. package/assets/theme.template.ts +6 -0
  207. package/authoring/debug/parse.d.mts +3 -3
  208. package/authoring/doctypes/_schema.d.mts +3 -3
  209. package/authoring/doctypes/command/command.doc.mjs +1 -1
  210. package/authoring/doctypes/component/categories.d.mts +37 -0
  211. package/authoring/doctypes/component/categories.mjs +54 -0
  212. package/authoring/doctypes/template/template.doc.mjs +1 -1
  213. package/authoring/doctypes/template/type.ts +9 -0
  214. package/authoring/example/example.doc.d.mts +12 -0
  215. package/authoring/example/example.doc.mjs +69 -0
  216. package/authoring/example/preview.d.mts +92 -0
  217. package/authoring/example/preview.mjs +994 -0
  218. package/authoring/example/type.ts +102 -0
  219. package/authoring/index.d.mts +1 -0
  220. package/authoring/index.d.ts +12 -0
  221. package/authoring/index.mjs +3 -1
  222. package/clients/cli/bin/astryx.mjs +6 -9
  223. package/clients/cli/build-id.generated.json +1 -1
  224. package/clients/cli/commands/component.doc.mjs +1 -1
  225. package/clients/cli/commands/component.mjs +22 -3
  226. package/clients/cli/commands/docs.doc.mjs +7 -1
  227. package/clients/cli/commands/docs.mjs +3 -1
  228. package/clients/cli/commands/doctor.mjs +32 -14
  229. package/clients/cli/commands/experimental/render.mjs +42 -1
  230. package/clients/cli/commands/experimental/theme.mjs +358 -63
  231. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  232. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  233. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  234. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  235. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  236. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  237. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  238. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  239. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  240. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  241. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  242. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  243. package/clients/cli/commands/search.doc.mjs +2 -1
  244. package/clients/cli/commands/search.mjs +6 -1
  245. package/clients/cli/commands/template.mjs +4 -2
  246. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  247. package/clients/cli/commands/theme.doc.mjs +1 -1
  248. package/clients/cli/commands/theme.mjs +317 -47
  249. package/clients/cli/commands/upgrade.mjs +42 -7
  250. package/clients/cli/index.mjs +1 -1
  251. package/clients/cli/lib/cli-error.mjs +2 -1
  252. package/clients/cli/lib/component-format.mjs +205 -98
  253. package/clients/cli/lib/hook-format.mjs +9 -19
  254. package/clients/cli/lib/json-shim.mjs +92 -21
  255. package/clients/cli/lib/manifest.mjs +3 -2
  256. package/clients/cli/manifest.generated.json +1 -1
  257. package/foundation/agent-docs/agent-docs.mjs +1 -1
  258. package/foundation/config/theme-state.d.mts +13 -1
  259. package/foundation/config/theme-state.mjs +47 -7
  260. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  261. package/foundation/discovery/component-discovery.d.mts +11 -0
  262. package/foundation/discovery/component-discovery.mjs +56 -8
  263. package/foundation/discovery/component-replacement.mjs +130 -1
  264. package/foundation/discovery/copied-passages.mjs +2 -1
  265. package/foundation/discovery/doc-types.mjs +4 -3
  266. package/foundation/discovery/entry-name-files.d.mts +43 -0
  267. package/foundation/discovery/entry-name-files.mjs +264 -0
  268. package/foundation/discovery/hook-discovery.d.mts +8 -2
  269. package/foundation/discovery/hook-discovery.mjs +22 -8
  270. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  271. package/foundation/discovery/icon-set-checks.mjs +2 -1
  272. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  273. package/foundation/discovery/integration-doc-files.mjs +2 -1
  274. package/foundation/discovery/package-exports.d.mts +10 -0
  275. package/foundation/discovery/package-exports.mjs +56 -3
  276. package/foundation/discovery/prop-drift.mjs +9 -9
  277. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  278. package/foundation/discovery/runner-allowlist.mjs +2 -0
  279. package/foundation/discovery/stored-component-list.d.mts +43 -0
  280. package/foundation/discovery/stored-component-list.mjs +90 -0
  281. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  282. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  283. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  284. package/foundation/discovery/stored-self-audit.mjs +38 -18
  285. package/foundation/discovery/template-adapter.d.mts +53 -1
  286. package/foundation/discovery/template-adapter.mjs +176 -12
  287. package/foundation/discovery/template-icons.mjs +2 -1
  288. package/foundation/discovery/theme-discovery.mjs +31 -4
  289. package/foundation/discovery/theme-imports.d.mts +14 -0
  290. package/foundation/discovery/theme-imports.mjs +43 -1
  291. package/foundation/discovery/theming-targets.mjs +3 -2
  292. package/foundation/doc-compiler/import.mjs +7 -1
  293. package/foundation/doc-compiler/inputs.mjs +3 -2
  294. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  295. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  296. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  297. package/foundation/env/semver.mjs +3 -1
  298. package/foundation/fonts/font-stylesheet.d.mts +31 -0
  299. package/foundation/fonts/font-stylesheet.mjs +115 -0
  300. package/foundation/fs/cache-eviction.d.mts +21 -0
  301. package/foundation/fs/cache-eviction.mjs +73 -0
  302. package/foundation/fs/exact-codec.d.mts +12 -2
  303. package/foundation/fs/exact-codec.mjs +23 -6
  304. package/foundation/fs/file-protection.mjs +4 -3
  305. package/foundation/fs/gather-cache.d.mts +62 -4
  306. package/foundation/fs/gather-cache.mjs +512 -91
  307. package/foundation/fs/jiti-cache.d.mts +19 -1
  308. package/foundation/fs/jiti-cache.mjs +130 -6
  309. package/foundation/fs/kept-tree.d.mts +60 -0
  310. package/foundation/fs/kept-tree.mjs +154 -0
  311. package/foundation/fs/listing-cache.d.mts +7 -0
  312. package/foundation/fs/listing-cache.mjs +10 -0
  313. package/foundation/fs/module-loader.d.mts +24 -2
  314. package/foundation/fs/module-loader.mjs +94 -21
  315. package/foundation/fs/paths.d.mts +18 -0
  316. package/foundation/fs/paths.mjs +15 -2
  317. package/foundation/fs/read-record.d.mts +9 -0
  318. package/foundation/fs/read-record.mjs +19 -11
  319. package/foundation/fs/stop-cleanup.d.mts +12 -0
  320. package/foundation/fs/stop-cleanup.mjs +66 -0
  321. package/foundation/identity/provider-identity.d.mts +6 -0
  322. package/foundation/identity/provider-identity.mjs +10 -1
  323. package/foundation/integrations/contribution-inventory.mjs +4 -3
  324. package/foundation/integrations/example-code.d.mts +63 -0
  325. package/foundation/integrations/example-code.mjs +416 -0
  326. package/foundation/integrations/public-imports.d.mts +9 -0
  327. package/foundation/integrations/public-imports.mjs +3 -2
  328. package/foundation/integrations/validate-contributions.mjs +17 -45
  329. package/foundation/render/embedded-files.d.mts +6 -0
  330. package/foundation/render/embedded-files.mjs +25 -5
  331. package/foundation/render/embedded-imports.d.mts +39 -7
  332. package/foundation/render/embedded-imports.mjs +66 -27
  333. package/foundation/render/file-header.d.mts +66 -0
  334. package/foundation/render/file-header.mjs +118 -0
  335. package/foundation/render/host-answer.d.mts +18 -0
  336. package/foundation/render/host-answer.mjs +46 -0
  337. package/foundation/render/host-exit.d.mts +1 -0
  338. package/foundation/render/host-exit.mjs +6 -1
  339. package/foundation/render/html-reader.d.mts +55 -2
  340. package/foundation/render/html-reader.mjs +145 -26
  341. package/foundation/render/markup-edits.d.mts +57 -0
  342. package/foundation/render/markup-edits.mjs +182 -0
  343. package/foundation/render/page-host.mjs +29 -12
  344. package/foundation/render/page-worker.mjs +121 -13
  345. package/foundation/render/picture-chrome.d.mts +4 -0
  346. package/foundation/render/picture-chrome.mjs +185 -0
  347. package/foundation/render/picture-playwright.d.mts +4 -0
  348. package/foundation/render/picture-playwright.mjs +34 -0
  349. package/foundation/render/rebuild.mjs +2 -1
  350. package/foundation/render/render-page.d.mts +35 -3
  351. package/foundation/render/render-page.mjs +641 -96
  352. package/foundation/render/source-block.d.mts +85 -6
  353. package/foundation/render/source-block.mjs +211 -20
  354. package/foundation/render/ts-paths.d.mts +69 -6
  355. package/foundation/render/ts-paths.mjs +326 -40
  356. package/foundation/response/error-codes.d.mts +3 -1
  357. package/foundation/response/error-codes.d.ts +1 -0
  358. package/foundation/response/error-codes.doc.mjs +12 -1
  359. package/foundation/response/error-codes.mjs +11 -1
  360. package/foundation/response/response-types.doc.mjs +2 -2
  361. package/foundation/text/compare-text.d.mts +14 -0
  362. package/foundation/text/compare-text.mjs +68 -0
  363. package/foundation/text/string-utils.d.mts +3 -2
  364. package/foundation/text/string-utils.mjs +18 -4
  365. package/foundation/text/suggest-order.d.mts +9 -0
  366. package/foundation/text/suggest-order.mjs +15 -1
  367. package/foundation/xle/expand.mjs +2 -1
  368. package/host/index.mjs +8 -6
  369. package/package.json +7 -6
@@ -32,17 +32,28 @@
32
32
  */
33
33
 
34
34
  import {writeThemeTemplate} from '../theme/template/template.mjs';
35
- import {buildSuggestion} from '../theme/build/build.mjs';
35
+ import {
36
+ buildInputProblem,
37
+ buildSuggestion,
38
+ realLocation,
39
+ refusedOutput,
40
+ } from '../theme/build/build.mjs';
36
41
  import {createHash} from 'node:crypto';
37
42
  import * as fs from 'node:fs';
43
+ import {createRequire} from 'node:module';
38
44
  import * as path from 'node:path';
39
45
  import * as edit from './_edit.mjs';
40
- import {baseInstalled, themeCacheRoot} from './_project.mjs';
46
+ import {baseInstalled, installLine, themeCacheRoot} from './_project.mjs';
41
47
  import * as preview from './_preview-app.mjs';
42
48
  import {AstryxError} from '../error.mjs';
43
49
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
44
50
  import {findPackageRoot} from '../../foundation/fs/paths.mjs';
45
- import {coreApp} from './_context.mjs';
51
+ import {context, coreApp} from './_context.mjs';
52
+ import {APP_COPY_MARK} from './_marks.mjs';
53
+ import {
54
+ fontKey,
55
+ importedFontFamilies,
56
+ } from '../../foundation/fonts/font-stylesheet.mjs';
46
57
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
47
58
  import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
48
59
  import {
@@ -50,22 +61,40 @@ import {
50
61
  quoteCommandArgument,
51
62
  } from '../../foundation/env/package-manager.mjs';
52
63
  import {LIKE, P} from './_tables.mjs';
64
+
65
+ /** The preview command, as a person runs it. */
66
+ const PREVIEW_WORDS = P.replace(/ editor$/, ' preview');
53
67
  import {setLine} from './_check.mjs';
68
+ import {followLine, splitCommand} from './_vet.mjs';
54
69
  import {
55
70
  SHOWCASE_GROUPS,
71
+ appCopyBehind,
72
+ appCopyStale,
73
+ copyFontsCss,
56
74
  takeFirstAppCopy,
57
75
  writeAppCopy,
58
76
  writeAppCopyAt,
59
77
  } from './_preview.mjs';
60
78
  import {humanWarn} from '../../foundation/response/json.mjs';
61
- import {folderIsEmpty, setAfterBuild, typedThemeName} from './_settings.mjs';
79
+ import {
80
+ buildColorModes,
81
+ camel,
82
+ folderIsEmpty,
83
+ loadTheme,
84
+ setAfterBuild,
85
+ editedThemes,
86
+ themeFiles,
87
+ fontsourcePackageOf,
88
+ themeSourceRefusal,
89
+ typedThemeName,
90
+ } from './_settings.mjs';
62
91
 
63
92
  // Every build of a theme writes its app copy (src/themes/<theme>/).
64
93
  setAfterBuild(writeAppCopy);
65
94
  import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
66
95
 
67
96
  export {parsePoints} from './_how.mjs';
68
- export {newFlagList} from './_edit.mjs';
97
+ export {newFlagList, checkedChangeLine as editorCheckedLine} from './_edit.mjs';
69
98
  import {themeEditHow as howAt} from './_how.mjs';
70
99
 
71
100
  /**
@@ -367,16 +396,43 @@ const lockName = name =>
367
396
  */
368
397
  function absolute(result, root, from) {
369
398
  if (path.resolve(from) === root) return result;
370
- /** @param {any} v @returns {any} */
371
- const map = v =>
399
+ /**
400
+ * Lines that name project files inside them: `see`, a picture note, the
401
+ * in-app preview's stale entries. Every project path in them (a theme
402
+ * file, an in-app preview folder) is made absolute, one style per line.
403
+ */
404
+ const PROSE = new Set(['see', 'pictureProblem', 'previewStale', 'wiring']);
405
+ /** A project-relative path that names a file or folder there. @param {string} p */
406
+ const inRoot = p => {
407
+ const bare = p.replace(/\/+$/, '');
408
+ return (
409
+ Boolean(bare) &&
410
+ !path.isAbsolute(bare) &&
411
+ !bare.startsWith('.') &&
412
+ fs.existsSync(path.join(root, bare))
413
+ );
414
+ };
415
+ /** @param {any} v @param {string} [key] @returns {any} */
416
+ const map = (v, key) =>
372
417
  typeof v === 'string'
373
- ? /^themes\//.test(v)
418
+ ? // A path alone; a line that starts with one is read as prose below.
419
+ /^themes\/\S*$/.test(v) && !(key && PROSE.has(key))
374
420
  ? path.join(root, v)
375
- : v
421
+ : key && PROSE.has(key)
422
+ ? previewCommandsFrom(v, root, from).replace(
423
+ /(^|[\s(,])((?:themes|src|app)\/[^\s,;)]*)/g,
424
+ (all, before, file) =>
425
+ /^themes\//.test(file) || inRoot(file)
426
+ ? `${before}${path.join(root, file)}`
427
+ : all,
428
+ )
429
+ : previewCommandsFrom(v, root, from)
376
430
  : Array.isArray(v)
377
- ? v.map(map)
431
+ ? v.map(x => map(x, key))
378
432
  : v && typeof v === 'object'
379
- ? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, map(x)]))
433
+ ? Object.fromEntries(
434
+ Object.entries(v).map(([k, x]) => [k, map(x, k)]),
435
+ )
380
436
  : v;
381
437
  return map(result);
382
438
  }
@@ -425,6 +481,23 @@ async function inProject(options, lock, fn, bestEffort = false, again = null) {
425
481
  */
426
482
  function fromCaller(e, root, from) {
427
483
  if (path.resolve(from) === root || !Array.isArray(e?.suggestions)) return e;
484
+ for (const s of e.suggestions)
485
+ if (typeof s?.name === 'string')
486
+ s.name = previewCommandsFrom(s.name, root, from);
487
+ return e;
488
+ }
489
+
490
+ /**
491
+ * The preview commands in a line, rebased from the project root onto the
492
+ * folder the command ran in: each `--path` and each `preview app` folder,
493
+ * so a pointer works where it is printed (in a refusal, a `see` line, a
494
+ * note). A folder that comes out starting with `-` goes after `--`.
495
+ * @param {string} line
496
+ * @param {string} root
497
+ * @param {string} from
498
+ */
499
+ export function previewCommandsFrom(line, root, from) {
500
+ if (path.resolve(from) === root) return line;
428
501
  const ARG = String.raw`('(?:[^']|'\\'')*'|"[^"]*"|[^\s'"]+)`;
429
502
  /** @param {string} v */
430
503
  const unquote = v =>
@@ -437,32 +510,40 @@ function fromCaller(e, root, from) {
437
510
  const rel = v =>
438
511
  /^<.*>$/.test(v)
439
512
  ? v
440
- : quoteCommandArgument(
441
- path.relative(path.resolve(from), path.resolve(root, unquote(v))) ||
442
- '.',
443
- );
444
- for (const s of e.suggestions) {
445
- if (typeof s?.name !== 'string') continue;
446
- if (!s.name.startsWith('astryx experimental theme preview ')) continue;
447
- s.name = s.name
448
- .replace(
513
+ : path.relative(path.resolve(from), path.resolve(root, unquote(v))) ||
514
+ '.';
515
+ const CMD = 'astryx experimental theme preview ';
516
+ const parts = line.split(CMD);
517
+ return parts
518
+ .map((part, i) => {
519
+ // A command after a `cd … &&` runs in the folder it names: as given.
520
+ if (i === 0 || /\bcd [^&]*&& (?:npx \S+ )?$/.test(parts[i - 1]))
521
+ return part;
522
+ let out = part.replace(
449
523
  new RegExp(`(--path )${ARG}`, 'g'),
450
524
  (
451
525
  /** @type {string} */ _m,
452
526
  /** @type {string} */ flag,
453
527
  /** @type {string} */ v,
454
- ) => flag + rel(v),
455
- )
456
- .replace(
457
- new RegExp(`^(astryx experimental theme preview app )${ARG}`),
528
+ ) => flag + quoteCommandArgument(rel(v)),
529
+ );
530
+ out = out.replace(
531
+ new RegExp(`^app ((?:--theme ${ARG} )?)(-- )?${ARG}`),
458
532
  (
459
- /** @type {string} */ _m,
460
- /** @type {string} */ cmd,
533
+ /** @type {string} */ m,
534
+ /** @type {string} */ flags,
535
+ /** @type {string} */ _t,
536
+ /** @type {string | undefined} */ dash,
461
537
  /** @type {string} */ v,
462
- ) => cmd + rel(v),
538
+ ) => {
539
+ if (!dash && v.startsWith('-')) return m;
540
+ const r = rel(v);
541
+ return `app ${flags}${r.startsWith('-') ? '-- ' : ''}${quoteCommandArgument(r)}`;
542
+ },
463
543
  );
464
- }
465
- return e;
544
+ return out;
545
+ })
546
+ .join(CMD);
466
547
  }
467
548
 
468
549
  /**
@@ -550,37 +631,134 @@ export const themeEditShow = (theme, options = {}) =>
550
631
  );
551
632
  /** @type {typeof preview.themeEditPreviewAdd} */
552
633
  export const themeEditPreviewAdd = (description, options = {}) =>
553
- inProject(options, 'preview', o =>
554
- preview.themeEditPreviewAdd(description, withThemeLock(o)),
634
+ stopTold(
635
+ `a preview change stopped part way is finished by the next ${PREVIEW_WORDS} add, and one written in full stands (${PREVIEW_WORDS} list says which)`,
636
+ () =>
637
+ inProject(options, 'preview', o =>
638
+ preview.themeEditPreviewAdd(description, withThemeLock(o)),
639
+ ),
555
640
  );
641
+
642
+ /**
643
+ * Run a preview command with a stop (Ctrl-C, SIGTERM) heard for its whole
644
+ * run, and after it: the stop ends the process as stopped, with one line
645
+ * saying where the change stands (a change stopped part way is finished by
646
+ * the next preview command), never an ok with exit 0.
647
+ * @template T
648
+ * @param {string | (() => string)} where where the change stands, and what
649
+ * finishes it; a function is asked when the stop lands, so it can look
650
+ * @param {() => Promise<T>} fn
651
+ * @returns {Promise<T>}
652
+ */
653
+ async function stopTold(where, fn) {
654
+ const on = (/** @type {NodeJS.Signals} */ sig) => {
655
+ process.removeListener('SIGINT', on);
656
+ process.removeListener('SIGTERM', on);
657
+ process.stderr.write(
658
+ `Stopped: ${typeof where === 'function' ? where() : where}.\n`,
659
+ );
660
+ // With no other listener (a lock's, which ends the process itself),
661
+ // the stop ends it here.
662
+ if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
663
+ };
664
+ process.on('SIGINT', on);
665
+ process.on('SIGTERM', on);
666
+ try {
667
+ const r = await fn();
668
+ // A turn of the event loop, so a stop that came while the work ran
669
+ // without a pause is heard now, before the result is printed.
670
+ await new Promise(resolve => setImmediate(resolve));
671
+ // Every listener added here is removed on return: the caller's process
672
+ // keeps its own stop handling. The CLI client, which owns its process,
673
+ // holds a stop that lands while it prints the result.
674
+ return r;
675
+ } finally {
676
+ process.removeListener('SIGINT', on);
677
+ process.removeListener('SIGTERM', on);
678
+ }
679
+ }
556
680
  /**
557
681
  * `preview app` runs from the project root, with `dir` kept pointing where
558
682
  * it was given. With a theme it holds that theme's lock, since it may build
559
683
  * the theme and copies its files: a `set` beside it waits.
560
684
  * @type {typeof preview.themeEditPreviewApp}
561
685
  */
562
- export const themeEditPreviewApp = (dir, options = {}) => {
686
+ export const themeEditPreviewApp = async (dir, options = {}) => {
563
687
  const from = options.cwd ?? process.cwd();
564
- return inProject(
565
- options,
566
- options.theme == null ? null : lockName(options.theme),
567
- o =>
568
- preview.themeEditPreviewApp(
569
- typeof dir === 'string' && dir.trim() && dir === dir.trim()
570
- ? path.relative(o.cwd, path.resolve(from, dir)) || '.'
571
- : dir,
572
- o,
573
- ),
574
- true,
688
+ // The app is written into a temp folder and moved into place in one step,
689
+ // with no pause on the way: when a stop lands, the folder holds the whole
690
+ // app or is as it was. Which one is told.
691
+ const target =
692
+ typeof dir === 'string' && dir.trim() ? path.resolve(from, dir) : null;
693
+ /** @param {string} d */
694
+ const holdsApp = d => fs.existsSync(path.join(d, 'package.json'));
695
+ const hadApp = target != null && holdsApp(target);
696
+ const shownTarget = target
697
+ ? path.relative(from, target).split(path.sep).join('/') || '.'
698
+ : null;
699
+ return fromHere(
700
+ await stopTold(
701
+ () =>
702
+ target && !hadApp && holdsApp(target)
703
+ ? `the new app in ${shownTarget}/ is written whole (it is moved into place in one step); cd ${quoteCommandArgument(shownTarget?.startsWith('-') ? `./${shownTarget}` : (shownTarget ?? '.'))} && npm install && npm run dev opens it`
704
+ : `nothing was written${shownTarget ? ` (${shownTarget}/ is as it was)` : ''}; run the same command again`,
705
+ () =>
706
+ inProject(
707
+ options,
708
+ options.theme == null ? null : lockName(options.theme),
709
+ o =>
710
+ preview.themeEditPreviewApp(
711
+ typeof dir === 'string' && dir.trim() && dir === dir.trim()
712
+ ? path.relative(o.cwd, path.resolve(from, dir)) || '.'
713
+ : dir,
714
+ o,
715
+ ),
716
+ true,
717
+ ),
718
+ ),
719
+ from,
575
720
  );
576
721
  };
722
+ /**
723
+ * A new app's folder and its open line, as they work from where the command
724
+ * ran (`cd ../../theme-app` from src/app), not from the project root.
725
+ * @template T
726
+ * @param {T} r
727
+ * @param {string} from
728
+ * @returns {T}
729
+ */
730
+ function fromHere(r, from) {
731
+ const d = /** @type {any} */ (r)?.data;
732
+ if (!d || typeof d.folder !== 'string') return r;
733
+ const root = projectRoot(from);
734
+ if (!root || path.resolve(from) === root) return r;
735
+ const here = path.relative(from, path.join(root, d.folder)) || '.';
736
+ const shown = here.split(path.sep).join('/');
737
+ const cdArg = quoteCommandArgument(
738
+ shown.startsWith('-') ? `./${shown}` : shown,
739
+ );
740
+ return /** @type {T} */ ({
741
+ ...r,
742
+ data: {
743
+ ...d,
744
+ folder: shown,
745
+ ...(typeof d.open === 'string'
746
+ ? {open: d.open.replace(/^cd \S+ &&/, `cd ${cdArg} &&`)}
747
+ : {}),
748
+ },
749
+ });
750
+ }
577
751
  /** @type {typeof preview.themeEditPreviewList} */
578
752
  export const themeEditPreviewList = (options = {}) =>
579
753
  inProject(options, null, async o => preview.themeEditPreviewList(o));
580
754
  /** @type {typeof preview.themeEditPreviewRemove} */
581
755
  export const themeEditPreviewRemove = (page, options = {}) =>
582
- inProject(options, 'preview', o =>
583
- preview.themeEditPreviewRemove(page, withThemeLock(o)),
756
+ stopTold(
757
+ `a removal stopped part way is finished by the next ${PREVIEW_WORDS} remove, and one made in full stands (${PREVIEW_WORDS} list says which)`,
758
+ () =>
759
+ inProject(options, 'preview', o =>
760
+ preview.themeEditPreviewRemove(page, withThemeLock(o)),
761
+ ),
584
762
  );
585
763
 
586
764
  /**
@@ -669,8 +847,9 @@ function runLine(cwd, rest) {
669
847
  * @returns {AstryxError | null}
670
848
  */
671
849
  export function editorThemeRefusal(err, cwd) {
672
- // A refused compile ends here: its theme locks go now, not at exit.
673
- void releaseCompileHold?.();
850
+ // A refused compile ends here: its theme locks go now, not at exit, and
851
+ // it writes no app copy (from build files it refused).
852
+ void releaseCompileHold?.(true);
674
853
  if (
675
854
  err.code !== ERROR_CODES.ERR_UNKNOWN_THEME &&
676
855
  !/unknown theme|is not added|not a theme package/i.test(err.message)
@@ -683,10 +862,43 @@ export function editorThemeRefusal(err, cwd) {
683
862
  const word = named ? typedThemeName(named[1] ?? named[2]) : '';
684
863
  const slug = word ? editorThemeOf(root, word) : null;
685
864
  if (!slug) return null;
865
+ // The command that refused: list, add, use, remove or eject.
866
+ const verb =
867
+ process.argv
868
+ .slice(2)
869
+ .find(a => ['list', 'add', 'use', 'remove', 'eject'].includes(a)) ?? null;
870
+ // eject copies a theme package's source into the app; an editor theme's
871
+ // source is the app's already.
872
+ if (verb === 'eject')
873
+ return new AstryxError(
874
+ `${slug} is a theme the editor made: its source is yours already, themes/${slug}/${slug}.theme.ts (your edits there survive every change), and the editor changes the rest. eject copies a theme package's source into the app, so it has nothing to do for ${slug}.`,
875
+ [
876
+ {
877
+ name: runLine(cwd, `experimental theme editor show ${slug}`),
878
+ reason: 'the theme as it is now',
879
+ },
880
+ ],
881
+ ERROR_CODES.ERR_UNKNOWN_THEME,
882
+ );
883
+ const copyThere = !folderIsEmpty(path.join(root, LOCAL_THEME_ROOT, slug));
884
+ // A path to the theme ("themes/d", "src/themes/d"): the commands take its
885
+ // name.
886
+ const typed = named ? (named[1] ?? named[2]) : '';
887
+ if (copyThere && verb && typed !== slug)
888
+ return new AstryxError(
889
+ `"${typed}" is ${/[\\/]|\.[a-z]+$/i.test(typed) ? 'a path' : "not the theme's name"}; the theme commands take the theme's name: ${slug}.`,
890
+ [
891
+ {
892
+ name: runLine(cwd, `theme ${verb} ${slug}`),
893
+ reason: 'the same, by name',
894
+ },
895
+ ],
896
+ ERROR_CODES.ERR_UNKNOWN_THEME,
897
+ );
686
898
  // A local theme of that name (a fork in the app's own themes folder) is
687
899
  // one the stable commands take: their own message stands.
688
900
  // A folder of only system files (or empty) holds no theme: as absent.
689
- if (!folderIsEmpty(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
901
+ if (copyThere) return null;
690
902
  // No app copy yet (a theme made before the editor wrote one, or the
691
903
  // copy removed): the next build writes it, then the same steps every
692
904
  // place gives (`wiring` of new and show).
@@ -722,6 +934,112 @@ export function editorThemeRefusal(err, cwd) {
722
934
  );
723
935
  }
724
936
 
937
+ /** The shared typo rule, for a typed subcommand. */
938
+ export {booleanWord, typoNear, typoOf} from './_normal.mjs';
939
+
940
+ /**
941
+ * The editor themes of the app the folder `cwd` is in, by name; none when
942
+ * the folder is in no app or its themes cannot be read.
943
+ * @param {string} cwd
944
+ * @returns {string[]}
945
+ */
946
+ export function editorThemesAt(cwd) {
947
+ try {
948
+ return editedThemes(projectRoot(cwd));
949
+ } catch {
950
+ return [];
951
+ }
952
+ }
953
+
954
+ /**
955
+ * A refused compile whose first suggestion is another compile: that compile
956
+ * is run through compile's own checks before it is offered (in memory,
957
+ * nothing built), and each repair a refusal of it offers is folded into the
958
+ * one line. An --out outside the working folder is dropped, and the reason
959
+ * says why; when the rest cannot be repaired, the reason says so. A line
960
+ * that starts with `cd` runs elsewhere, so it is not checked from here.
961
+ * @param {AstryxError} err
962
+ * @param {string} cwd
963
+ * @returns {Promise<AstryxError>}
964
+ */
965
+ export async function editorFollowCompile(err, cwd) {
966
+ const list = err.suggestions ?? [];
967
+ const first = list[0];
968
+ // The build's own refusals name `theme build`; the group's words replace
969
+ // those words when the refusal is shown.
970
+ const wordsIn = (/** @type {string} */ line) =>
971
+ [' experimental theme compile ', ' theme build '].find(w =>
972
+ line.includes(w),
973
+ );
974
+ const isCompile = (/** @type {string} */ line) =>
975
+ /^cd /.test(line) || Boolean(wordsIn(line));
976
+ if (!first || /^cd /.test(first.name) || !wordsIn(first.name)) return err;
977
+ /** @param {string} line */
978
+ const read = line => {
979
+ const words = wordsIn(line);
980
+ if (!words) return null;
981
+ const args = splitCommand(line.slice(line.indexOf(words) + words.length));
982
+ if (!args) return null;
983
+ /** @type {{source?: string, out?: string, iconsSpecifier?: string, check?: boolean}} */
984
+ const r = {};
985
+ for (let i = 0; i < args.length; i += 1) {
986
+ const a = args[i];
987
+ if (a === '--check') r.check = true;
988
+ else if (a === '--out') r.out = args[(i += 1)];
989
+ else if (a === '--icons-specifier') r.iconsSpecifier = args[(i += 1)];
990
+ else if (a.startsWith('-') || r.source) return null;
991
+ else r.source = a;
992
+ }
993
+ return r.source ? r : null;
994
+ };
995
+ const COMPILE = {group: 'experimental theme', build: 'compile'};
996
+ /** @type {string | null} */
997
+ let outDropped = null;
998
+ const followed = await followLine(
999
+ first.name,
1000
+ async line => {
1001
+ // A line that runs elsewhere is not checked from here.
1002
+ if (/^cd /.test(line)) return null;
1003
+ const r = read(line);
1004
+ if (!r?.source) return null;
1005
+ const refused =
1006
+ (await editorCompileProblem([r.source], {cwd, ...r})) ??
1007
+ buildInputProblem(r.source, r, cwd);
1008
+ if (refused) return refused;
1009
+ // A build writes only inside the working folder: the same build
1010
+ // without --out writes beside the source.
1011
+ if (r.out && refusedOutput(path.resolve(cwd, r.out), cwd)) {
1012
+ outDropped = r.out;
1013
+ return new AstryxError(`--out ${r.out} is outside the working folder`, [
1014
+ {
1015
+ name: buildSuggestion(
1016
+ r.source,
1017
+ {check: r.check, iconsSpecifier: r.iconsSpecifier},
1018
+ cwd,
1019
+ COMPILE,
1020
+ ),
1021
+ reason: 'do this instead',
1022
+ },
1023
+ ]);
1024
+ }
1025
+ return null;
1026
+ },
1027
+ isCompile,
1028
+ );
1029
+ if (followed.line === first.name) return err;
1030
+ const reason = [
1031
+ outDropped && !/ --out /.test(followed.line)
1032
+ ? `do this instead, without --out: ${outDropped} is outside the working folder, where a build may not write, so the outputs go beside the source`
1033
+ : first.reason,
1034
+ ...(followed.why ? [`it is still refused: ${followed.why}`] : []),
1035
+ ].join('; ');
1036
+ err.suggestions = [
1037
+ {...first, name: followed.line, reason},
1038
+ ...list.slice(1).filter(x => x.name !== followed.line),
1039
+ ];
1040
+ return err;
1041
+ }
1042
+
725
1043
  /**
726
1044
  * A refusal before `compile` runs on an editor theme's files, or null: the
727
1045
  * editor's generated settings are not a theme source, `--family` does not
@@ -757,25 +1075,173 @@ export async function editorCompileProblem(
757
1075
  from,
758
1076
  COMPILE,
759
1077
  );
1078
+ /**
1079
+ * The compile of `source` from the app root, after a cd there: --out
1080
+ * names the same file from the root while it stays inside it (a build
1081
+ * writes only inside its working folder); one outside is left off, and
1082
+ * `why` says so.
1083
+ * @param {string} source @param {string} root
1084
+ */
1085
+ const fromRootLine = (source, root) => {
1086
+ const rebased = out
1087
+ ? path.relative(root, path.resolve(cwd, slashed(out)))
1088
+ : '';
1089
+ const escapes =
1090
+ !check &&
1091
+ !!rebased &&
1092
+ (rebased.startsWith('..') || path.isAbsolute(rebased));
1093
+ return {
1094
+ name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${
1095
+ escapes
1096
+ ? buildSuggestion(source, {check, iconsSpecifier}, root, COMPILE)
1097
+ : compileLine(source, root)
1098
+ }`,
1099
+ why: escapes
1100
+ ? ` --out ${out} is outside the app root, where a build may not write, so the compile below writes beside the source.`
1101
+ : '',
1102
+ };
1103
+ };
1104
+ // An --out into an editor theme's app copy folder: the copy refresh would
1105
+ // write the theme's own build over it. One into the theme's own editor
1106
+ // folder that is not its default output would leave that folder half
1107
+ // built (the module rewritten, the stylesheet not) and the copy made from
1108
+ // it.
1109
+ if (out) {
1110
+ // Any --out in the copy folder, the folder itself too, written with
1111
+ // backslashes, through a link or (on a case-insensitive disk) in
1112
+ // another case, as the build reads it: real paths name the folder as
1113
+ // the disk does.
1114
+ const rel = path
1115
+ .relative(
1116
+ realLocation(cwdRoot),
1117
+ realLocation(path.resolve(cwd, slashed(out))),
1118
+ )
1119
+ .split(path.sep)
1120
+ .filter(Boolean);
1121
+ const inCopy =
1122
+ rel[0] === 'src' &&
1123
+ rel[1] === 'themes' &&
1124
+ rel.length >= 3 &&
1125
+ fs.existsSync(themeFiles(cwdRoot, rel[2]).settings);
1126
+ // Only for a compile of that theme: another source written there is
1127
+ // the build's own case (it warns).
1128
+ const inEditor =
1129
+ rel[0] === 'themes' &&
1130
+ rel.length >= 3 &&
1131
+ fs.existsSync(themeFiles(cwdRoot, rel[1]).settings) &&
1132
+ files.some(
1133
+ file =>
1134
+ editorThemeAt(cwdRoot, path.resolve(cwd, file))?.slug === rel[1],
1135
+ ) &&
1136
+ !outIsDefault(cwdRoot, rel[1], cwd, out);
1137
+ if (inCopy || inEditor) {
1138
+ const t = inCopy ? rel[2] : rel[1];
1139
+ return new AstryxError(
1140
+ inCopy
1141
+ ? `--out ${out} is in ${t}'s app copy (src/themes/${t}/), which the editor writes after every build of themes/${t}/; write the build somewhere else.`
1142
+ : `--out ${out} is in ${t}'s own folder (themes/${t}/), where the theme's build writes its module and stylesheet together; compile without --out to build there, or write the build outside themes/${t}/.`,
1143
+ [
1144
+ {
1145
+ // The same compile without --out: it builds into themes/<t>/,
1146
+ // and the copy follows.
1147
+ // From a subfolder, with the cd to the app root, where an
1148
+ // editor theme compiles.
1149
+ name:
1150
+ path.resolve(cwd) === path.resolve(cwdRoot)
1151
+ ? buildSuggestion(
1152
+ files.length === 1 ? files[0] : `themes/${t}/${t}.theme.ts`,
1153
+ {check, iconsSpecifier},
1154
+ cwd,
1155
+ COMPILE,
1156
+ )
1157
+ : `cd ${quoteCommandArgument(path.relative(cwd, cwdRoot) || '.')} && ${buildSuggestion(
1158
+ files.length === 1
1159
+ ? path.relative(cwdRoot, path.resolve(cwd, files[0])) ||
1160
+ files[0]
1161
+ : `themes/${t}/${t}.theme.ts`,
1162
+ {check, iconsSpecifier},
1163
+ cwdRoot,
1164
+ COMPILE,
1165
+ )}`,
1166
+ reason: 'do this instead',
1167
+ },
1168
+ ],
1169
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
1170
+ );
1171
+ }
1172
+ }
760
1173
  for (const file of files) {
761
- const at = editorThemeAt(cwdRoot, path.resolve(cwd, file));
1174
+ const abs = path.resolve(cwd, file);
1175
+ const relParts = path
1176
+ .relative(
1177
+ realLocation(cwdRoot),
1178
+ realLocation(path.resolve(cwd, slashed(file))),
1179
+ )
1180
+ .split(path.sep);
1181
+ // The app's theme module `theme add` writes: not a theme source.
1182
+ if (relParts.join('/') === 'src/astryx-themes.ts')
1183
+ return new AstryxError(
1184
+ `${file} is the app's theme module (\`theme add\` writes it), not a theme source; compile the editor theme instead.`,
1185
+ editedThemes(cwdRoot)
1186
+ .slice(0, 3)
1187
+ .map(t => ({
1188
+ name: compileLine(`themes/${t}/${t}.theme.ts`, cwdRoot),
1189
+ reason: 'do this instead',
1190
+ })),
1191
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
1192
+ );
1193
+ // A file of an editor theme's app copy (src/themes/<t>/): the copy
1194
+ // is written from themes/<t>/, so that is what compiles.
1195
+ if (
1196
+ relParts[0] === 'src' &&
1197
+ relParts[1] === 'themes' &&
1198
+ (relParts.length === 3 || relParts.length === 4) &&
1199
+ fs.existsSync(themeFiles(cwdRoot, relParts[2]).settings) &&
1200
+ // A file of yours there (no editor mark, no build header) compiles
1201
+ // like any theme source.
1202
+ (relParts.length === 3 ||
1203
+ isCopyFile(path.join(cwdRoot, ...relParts)) ||
1204
+ relParts[3] === `${camel(relParts[2])}Theme.ts`)
1205
+ ) {
1206
+ const t = relParts[2];
1207
+ const own = `themes/${t}/${t}.theme.ts`;
1208
+ if (path.resolve(cwd) !== path.resolve(cwdRoot)) {
1209
+ const line = fromRootLine(own, cwdRoot);
1210
+ return new AstryxError(
1211
+ `${t} is a theme the editor made; compile it from the app root (${path.relative(cwd, cwdRoot) || '.'}), where the editor builds it.${line.why}`,
1212
+ [{name: line.name, reason: 'do this instead'}],
1213
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
1214
+ );
1215
+ }
1216
+ // Its source too: a compile of the copy builds neither the theme
1217
+ // nor a current copy.
1218
+ return new AstryxError(
1219
+ `${file} is ${relParts.length === 3 ? '' : 'part of '}${t}'s app copy, which the editor writes from themes/${t}/ after every build; compile the theme itself.`,
1220
+ [
1221
+ {name: compileLine(own, cwd), reason: 'do this instead'},
1222
+ {
1223
+ name: runLine(cwdRoot, `experimental theme editor show ${t}`),
1224
+ reason: 'writes the app copy again from the theme',
1225
+ },
1226
+ ],
1227
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
1228
+ );
1229
+ }
1230
+ const at = editorThemeAt(cwdRoot, abs);
762
1231
  if (!at || !editorOwnFile(at.slug, file)) continue;
763
1232
  const {root, slug} = at;
764
1233
  const source = `themes/${slug}/${slug}.theme.ts`;
765
1234
  // An editor theme is built from its project's root, as every editor
766
1235
  // command runs there: from a subfolder the build would write outside
767
1236
  // its working folder. The run names the root.
768
- if (path.resolve(cwd) !== path.resolve(root))
1237
+ if (path.resolve(cwd) !== path.resolve(root)) {
1238
+ const line = fromRootLine(source, root);
769
1239
  return new AstryxError(
770
- `${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it.`,
771
- [
772
- {
773
- name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${compileLine(source, root)}`,
774
- reason: 'do this instead',
775
- },
776
- ],
1240
+ `${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it.${line.why}`,
1241
+ [{name: line.name, reason: 'do this instead'}],
777
1242
  ERROR_CODES.ERR_INVALID_ARGUMENT,
778
1243
  );
1244
+ }
779
1245
  if (/\.settings\.(ts|json)$/.test(file))
780
1246
  return new AstryxError(
781
1247
  `${file} is the editor's own settings for ${slug}, not a theme source; compile the theme source.`,
@@ -790,6 +1256,13 @@ export async function editorCompileProblem(
790
1256
  ],
791
1257
  ERROR_CODES.ERR_INVALID_ARGUMENT,
792
1258
  );
1259
+ // A source that no longer carries the settings (another theme's name,
1260
+ // or no extends of them) is refused as set refuses it: a build would
1261
+ // write another theme's files, or drop every setting.
1262
+ {
1263
+ const refusal = await themeSourceRefusal(root, slug);
1264
+ if (refusal) return refusal;
1265
+ }
793
1266
  if (family)
794
1267
  return new AstryxError(
795
1268
  `${slug} is a theme the editor made; --family builds package theme families, not editor themes. Compile it on its own.`,
@@ -868,12 +1341,11 @@ export async function editorCompileProblem(
868
1341
  ],
869
1342
  ERROR_CODES.ERR_THEME_INVALID,
870
1343
  );
871
- // A [light, dark] pair on a token that is not a color, however the
872
- // file writes it: what the theme builds now is read (never written
873
- // beside it), as the editor's own build reads it.
1344
+ // The file's own token values, judged as a build of it writes them
1345
+ // (never written beside it), by the check the editor's build runs.
874
1346
  if (path.basename(file) === `${slug}.theme.ts`) {
875
- const pairs = await edit.editorPairRefusal(root, slug);
876
- if (pairs) return pairs;
1347
+ const values = await edit.editorOwnTokenRefusal(root, slug);
1348
+ if (values) return values;
877
1349
  }
878
1350
  }
879
1351
  }
@@ -883,18 +1355,48 @@ export async function editorCompileProblem(
883
1355
  /** The editor themes a running `compile` holds the lock of, by project and name. */
884
1356
  const COMPILE_HELD = new Set();
885
1357
 
886
- /** @type {(() => Promise<void>) | null} The release of the running compile's hold. */
1358
+ /** @type {((refused?: boolean) => Promise<void>) | null} The release of the running compile's hold; `refused`: it wrote nothing, so no app copy either. */
887
1359
  let releaseCompileHold = null;
888
1360
 
1361
+ /** @type {Array<{root: string, slug: string, copy: (refused: boolean) => boolean, report: () => Record<string, unknown> | null}>} The running compile's held themes. */
1362
+ let compileHoldItems = [];
1363
+
1364
+ /**
1365
+ * For `compile`, once its outputs are written: write each held editor
1366
+ * theme's app copy now, and say per file what the write did (`appCopy` on
1367
+ * a first write, `appCopyStale` when something keeps the copy behind), so
1368
+ * the JSON result carries what the text says.
1369
+ * @param {string[]} files
1370
+ * @param {string} cwd
1371
+ * @returns {Promise<Record<string, Record<string, unknown>>>}
1372
+ */
1373
+ export async function editorAfterBuild(files, cwd) {
1374
+ const root = projectRoot(cwd);
1375
+ /** @type {Record<string, Record<string, unknown>>} */
1376
+ const out = {};
1377
+ for (const item of compileHoldItems) {
1378
+ item.copy(false);
1379
+ const report = item.report();
1380
+ if (!report) continue;
1381
+ for (const file of files) {
1382
+ const abs = path.resolve(cwd, file);
1383
+ const own = editorThemeAt(root, abs);
1384
+ if (own?.slug === item.slug && editorOwnFile(own.slug, file))
1385
+ out[file] = report;
1386
+ }
1387
+ }
1388
+ return out;
1389
+ }
1390
+
889
1391
  /**
890
1392
  * Hold the theme lock of every editor theme among the files while
891
1393
  * `compile` builds or checks them, so it never reads a change half
892
1394
  * written. Resolves to the release.
893
1395
  * @param {string[]} files
894
- * @param {{cwd: string}} options
1396
+ * @param {{cwd: string, check?: boolean, out?: string}} options
895
1397
  * @returns {Promise<() => Promise<void>>}
896
1398
  */
897
- export async function editorThemeHold(files, {cwd}) {
1399
+ export async function editorThemeHold(files, {cwd, check = false, out}) {
898
1400
  // Two compiles of one theme in one process: the second waits for the
899
1401
  // lock like any other command.
900
1402
  const cwdRoot = projectRoot(cwd);
@@ -903,13 +1405,24 @@ export async function editorThemeHold(files, {cwd}) {
903
1405
  const at = editorThemeAt(cwdRoot, path.resolve(cwd, f));
904
1406
  if (at && editorOwnFile(at.slug, f))
905
1407
  found.set(`${at.root}\0${at.slug}`, at);
1408
+ // The app copy's source (src/themes/<t>/<t>Theme.ts) of an editor
1409
+ // theme: built under the theme's lock, so it never lands between a
1410
+ // change's two writes.
1411
+ const copy = appCopyTheme(cwdRoot, path.resolve(cwd, f));
1412
+ if (copy) found.set(`${copy.root}\0${copy.slug}`, copy);
906
1413
  }
907
1414
  const themes = [...found.keys()].sort().map(k => found.get(k));
908
- /** @type {Array<() => Promise<void>>} */
1415
+ /** @type {Array<{root: string, slug: string, copy: (refused: boolean) => boolean, report: () => Record<string, unknown> | null, finish: (later: boolean) => Promise<void>}>} */
909
1416
  const releases = [];
910
- const releaseAll = async () => {
1417
+ compileHoldItems = releases;
1418
+ // Every theme's copy is written first, at once (a refusal ends the run
1419
+ // without waiting), then each lock goes.
1420
+ const releaseAll = async (refused = false) => {
911
1421
  if (releaseCompileHold === releaseAll) releaseCompileHold = null;
912
- for (const r of releases.splice(0).reverse()) await r();
1422
+ const items = releases.splice(0);
1423
+ const later = items.map(x => x.copy(refused));
1424
+ for (const [i, x] of [...items.entries()].reverse())
1425
+ await x.finish(later[i]);
913
1426
  };
914
1427
  releaseCompileHold = releaseAll;
915
1428
  for (const {
@@ -927,6 +1440,25 @@ export async function editorThemeHold(files, {cwd}) {
927
1440
  ready = r;
928
1441
  });
929
1442
  const key = `${root}\0${slug}`;
1443
+ // When the lock was taken, and the context a copy write needs (its
1444
+ // font stylesheets), ready before the build so the copy is written at
1445
+ // once when the run ends.
1446
+ const heldAt = Date.now() - 1;
1447
+ // An --out elsewhere builds neither themes/<theme>/ nor its copy.
1448
+ const skipped = outSkipsCopy(root, slug, cwd, {check, out});
1449
+ let ran = false;
1450
+ let copied = false;
1451
+ /** @type {string[] | null} */
1452
+ let firstWrite = null;
1453
+ /** @type {string | null} */
1454
+ let keptBack = null;
1455
+ /** @type {any} */
1456
+ let copyCtx = null;
1457
+ try {
1458
+ copyCtx = await context(root);
1459
+ } catch {
1460
+ copyCtx = null;
1461
+ }
930
1462
  const done = withLock(root, lockName(slug), async () => {
931
1463
  COMPILE_HELD.add(key);
932
1464
  ready();
@@ -941,30 +1473,346 @@ export async function editorThemeHold(files, {cwd}) {
941
1473
  await releaseAll();
942
1474
  throw err;
943
1475
  }
944
- releases.push(async () => {
1476
+ releases.push({
945
1477
  // A compile that wrote the build refreshes the app's copy too
946
- // (src/themes/<theme>/), under the same lock; a check writes nothing.
947
- if (!process.argv.includes('--check')) {
1478
+ // (src/themes/<theme>/), under the same lock; a check writes
1479
+ // nothing. Each theme's copy follows its own build: a theme this run
1480
+ // built (its build now matches its settings) gets its copy, whatever
1481
+ // a later theme did; one that was refused or failed keeps its copy.
1482
+ // True when the copy still needs its font stylesheet from the
1483
+ // theme's settings (written in finish).
1484
+ root,
1485
+ slug,
1486
+ copy: (/** @type {boolean} */ refused) => {
1487
+ // Once per run: after the build's writes when the command asks
1488
+ // (its result then says what the copy write did), else at release.
1489
+ if (copied) return false;
1490
+ copied = true;
1491
+ ran = !refused && (process.exitCode ?? 0) === 0;
1492
+ if (check || skipped) return false;
1493
+ // This run built the theme: its module and stylesheet, one unit,
1494
+ // were written since the lock was taken, or the run ended well. A
1495
+ // refused or failed compile writes no copy.
1496
+ const f = themeFiles(root, slug);
1497
+ const written = [f.css, f.js].every(x => {
1498
+ try {
1499
+ return fs.statSync(x).mtimeMs >= heldAt;
1500
+ } catch {
1501
+ return false;
1502
+ }
1503
+ });
1504
+ if (!written && (refused || (process.exitCode ?? 0) !== 0))
1505
+ return false;
948
1506
  try {
949
- writeAppCopyAt(root, slug, null);
950
- // The first write of the app copy is named once (the compile's
951
- // own JSON envelope is the stable command's).
952
- const wrote = takeFirstAppCopy(root, slug);
953
- if (wrote)
1507
+ // From what was just built, its font stylesheets from the fonts
1508
+ // the theme loads now.
1509
+ if (copyCtx) writeAppCopy(copyCtx, slug, loadTheme(root, slug));
1510
+ else writeAppCopyAt(root, slug, null);
1511
+ } catch {
1512
+ try {
1513
+ writeAppCopyAt(root, slug, null);
1514
+ } catch {
1515
+ // A theme that does not load keeps its copy as it was.
1516
+ }
1517
+ }
1518
+ // What the write did, for the result and the text alike: the
1519
+ // files of a first write, or what keeps the copy behind.
1520
+ firstWrite = takeFirstAppCopy(root, slug);
1521
+ keptBack = appCopyStale(root, slug).appCopyStale ?? null;
1522
+ return false;
1523
+ },
1524
+ report: () =>
1525
+ firstWrite || keptBack
1526
+ ? {
1527
+ ...(firstWrite ? {appCopy: {wrote: firstWrite}} : {}),
1528
+ ...(keptBack ? {appCopyStale: keptBack} : {}),
1529
+ }
1530
+ : null,
1531
+ finish: async () => {
1532
+ // Said only after a build or check that ran: a refused one wrote
1533
+ // and checked nothing.
1534
+ if (skipped) {
1535
+ if (ran) humanWarn(skipped);
1536
+ } else if (!check) {
1537
+ // The first write of the app copy is named once.
1538
+ if (firstWrite)
954
1539
  humanWarn(
955
- `wrote ${slug}'s app copy, a local theme \`theme add ${slug}\` takes, written again after every build: ${wrote.join(', ')}`,
1540
+ `wrote ${slug}'s app copy, a local theme \`theme add ${slug}\` takes, written again after every build: ${firstWrite.join(', ')}`,
956
1541
  );
957
- } catch {
958
- // A theme that does not load keeps its copy as it was.
1542
+ // A copy a file or a link keeps behind, or one that could not be
1543
+ // written, is said, as set and show say it.
1544
+ if (keptBack) humanWarn(keptBack);
959
1545
  }
960
- }
961
- release();
962
- await done;
1546
+ release();
1547
+ await done;
1548
+ },
963
1549
  });
964
1550
  }
965
1551
  return releaseAll;
966
1552
  }
967
1553
 
1554
+ /**
1555
+ * For `compile` of an editor theme's own source: how to load a family the
1556
+ * build names, as the editor says it (the app copy imports a family's
1557
+ * installed Fontsource package); null for any other file.
1558
+ * @param {string} file the path as given
1559
+ * @param {string} cwd
1560
+ * @returns {import('../theme/build/build.mjs').FontHelp | null}
1561
+ */
1562
+ export function editorFontHelp(file, cwd) {
1563
+ const root = projectRoot(cwd);
1564
+ const at = editorThemeAt(root, path.resolve(cwd, file));
1565
+ if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
1566
+ const copy = `src/themes/${at.slug}/${at.slug}.fonts.css`;
1567
+ return {
1568
+ notice: family =>
1569
+ `Font "${family}" is named by this theme but not loaded; if Fontsource publishes it, ${installLine(root, [fontsourcePackageOf(family)])} installs its package, which ${copy} then imports`,
1570
+ recipe:
1571
+ families => ` The built CSS only sets font-family. ${at.slug}'s app copy loads a family
1572
+ once its package is installed (if Fontsource publishes it), importing it in
1573
+ ${copy} on the next compile, set or show:
1574
+
1575
+ ${installLine(root, families.map(fontsourcePackageOf))}
1576
+
1577
+ Recipe and fallback-stack guidance: ${runLine(root, 'docs typography')}
1578
+ `,
1579
+ };
1580
+ }
1581
+
1582
+ /**
1583
+ * For `compile`: the path an editor theme's own file builds under when it
1584
+ * was named through a link (its real path, which every output's header
1585
+ * names and `--check` compares); null for any other file.
1586
+ * @param {string} file the path as given
1587
+ * @param {string} cwd
1588
+ * @returns {string | null}
1589
+ */
1590
+ export function editorSourcePath(file, cwd) {
1591
+ const abs = path.resolve(cwd, slashed(file));
1592
+ const realCwd = realLocation(cwd);
1593
+ const real = realLocation(abs);
1594
+ if (real === path.join(realCwd, path.relative(cwd, abs))) return null;
1595
+ const at = editorThemeAt(projectRoot(cwd), real);
1596
+ if (!at || !editorOwnFile(at.slug, real)) return null;
1597
+ return path.relative(realCwd, real) || null;
1598
+ }
1599
+
1600
+ /** @param {string} p a path as typed, with Windows separators read as `/` */
1601
+ const slashed = p => String(p).replace(/\\/g, '/');
1602
+
1603
+ /**
1604
+ * Whether --out names an editor theme's default output, where the build
1605
+ * writes without --out: its folder, or its stylesheet file there (the same
1606
+ * file, as the file system tells files apart: a name that differs only in
1607
+ * case is another file on a case-sensitive disk). A folder form (a
1608
+ * trailing slash) names a folder, so it is the default only as the theme's
1609
+ * folder. No --out counts.
1610
+ * @param {string} root the app root
1611
+ * @param {string} slug
1612
+ * @param {string} cwd
1613
+ * @param {string | undefined} out
1614
+ */
1615
+ function outIsDefault(root, slug, cwd, out) {
1616
+ if (!out) return true;
1617
+ const typed = slashed(out);
1618
+ const at = path.resolve(cwd, typed);
1619
+ const f = themeFiles(root, slug);
1620
+ if (sameFile(at, f.dir)) return true;
1621
+ return !typed.endsWith('/') && sameFile(at, f.css);
1622
+ }
1623
+
1624
+ /**
1625
+ * Whether two paths name one file: the same file on disk when both are
1626
+ * there, else the same real path.
1627
+ * @param {string} a
1628
+ * @param {string} b
1629
+ */
1630
+ function sameFile(a, b) {
1631
+ try {
1632
+ const x = fs.statSync(a);
1633
+ const y = fs.statSync(b);
1634
+ return x.dev === y.dev && x.ino === y.ino;
1635
+ } catch {
1636
+ return realLocation(a) === realLocation(b);
1637
+ }
1638
+ }
1639
+
1640
+ /**
1641
+ * Why an editor theme's app copy was not written, or checked, by a build
1642
+ * with --out elsewhere; null without one.
1643
+ * @param {string} root
1644
+ * @param {string} slug
1645
+ * @param {string} cwd
1646
+ * @param {{check?: boolean, out?: string}} opts
1647
+ */
1648
+ function outSkipsCopy(root, slug, cwd, {check, out}) {
1649
+ if (outIsDefault(root, slug, cwd, out)) return null;
1650
+ return check
1651
+ ? `--check with --out checks only the files --out names: themes/${slug}/ and ${slug}'s app copy in src/themes/${slug}/ are not checked. Check without --out to check them.`
1652
+ : `--out builds only the files it names: themes/${slug}/ and ${slug}'s app copy in src/themes/${slug}/ were not written. Compile without --out to write them.`;
1653
+ }
1654
+
1655
+ /**
1656
+ * Whether a file in an app copy folder is the editor's: its mark, or the
1657
+ * header the build writes. A missing file counts (it would be the copy's).
1658
+ * @param {string} file
1659
+ */
1660
+ function isCopyFile(file) {
1661
+ try {
1662
+ const head = fs.readFileSync(file, 'utf8').slice(0, 600);
1663
+ return (
1664
+ head.includes(APP_COPY_MARK) ||
1665
+ /@generated by `astryx theme build`/.test(head)
1666
+ );
1667
+ } catch {
1668
+ return true;
1669
+ }
1670
+ }
1671
+
1672
+ /**
1673
+ * The editor theme whose app copy source a file is
1674
+ * (`src/themes/<t>/<t>Theme.ts`, with themes/<t>/ an editor theme), or
1675
+ * null.
1676
+ * @param {string} root the project root
1677
+ * @param {string} file absolute
1678
+ * @returns {{root: string, slug: string} | null}
1679
+ */
1680
+ function appCopyTheme(root, file) {
1681
+ const rel = path.relative(root, file).split(path.sep);
1682
+ if (rel.length !== 4 || rel[0] !== 'src' || rel[1] !== 'themes') return null;
1683
+ const slug = rel[2];
1684
+ if (rel[3] !== `${camel(slug)}Theme.ts`) return null;
1685
+ return fs.existsSync(themeFiles(root, slug).settings) ? {root, slug} : null;
1686
+ }
1687
+
1688
+ /**
1689
+ * For `compile` of an editor theme: `appCopyStale` for its result data when
1690
+ * the app copy is behind (the same line set and show give), or
1691
+ * `appCopySkipped` when --out builds elsewhere (neither themes/<theme>/ nor
1692
+ * the copy is written or checked); null for any other file or a current
1693
+ * copy.
1694
+ * @param {string} file the path as given
1695
+ * @param {string} cwd
1696
+ * @param {{check: boolean, upToDate?: boolean, out?: string, iconsSpecifier?: string}} opts
1697
+ * `upToDate`: the check's own verdict on the theme's outputs
1698
+ * @returns {Promise<Record<string, unknown> | null>}
1699
+ */
1700
+ export async function editorBuildExtra(file, cwd, opts) {
1701
+ const root = projectRoot(cwd);
1702
+ const abs = path.resolve(cwd, file);
1703
+ const own = editorThemeAt(root, abs);
1704
+ const slug =
1705
+ appCopyTheme(root, abs)?.slug ??
1706
+ (own && editorOwnFile(own.slug, file) ? own.slug : null);
1707
+ if (!slug) return null;
1708
+ {
1709
+ const skipped = outSkipsCopy(root, slug, cwd, opts);
1710
+ if (skipped) return {appCopySkipped: skipped};
1711
+ }
1712
+ // Every set and show builds the theme again from its source, without
1713
+ // --icons-specifier: said, with the change that keeps it.
1714
+ if (opts.iconsSpecifier && !opts.check)
1715
+ return {
1716
+ warnings: [
1717
+ `${slug} is a theme the editor made: every set and show builds it again from themes/${slug}/${slug}.theme.ts without --icons-specifier, which puts the theme's own import of the registry back. To keep this one, import the registry from its package in ${slug}.theme.ts.`,
1718
+ ],
1719
+ };
1720
+ if (opts.check) {
1721
+ // A theme output that is stale is the check's own finding (it names
1722
+ // the file); the copy is compared only with a current build.
1723
+ if (opts.upToDate === false) return null;
1724
+ /** @type {string[] | null} */
1725
+ let fonts;
1726
+ try {
1727
+ fonts = copyFontsCss(await context(root), slug, loadTheme(root, slug));
1728
+ } catch {
1729
+ fonts = null;
1730
+ }
1731
+ const behind = appCopyBehind(root, slug, fonts);
1732
+ return behind
1733
+ ? {
1734
+ upToDate: false,
1735
+ code: 'ERR_THEME_STALE',
1736
+ // Something of yours in the way: its own line says what to move;
1737
+ // no editor command writes over it.
1738
+ appCopyStale: appCopyStale(root, slug).appCopyStale
1739
+ ? `${slug}'s app copy in src/themes/${slug}/ is not up to date: ${behind}`
1740
+ : `${slug}'s app copy in src/themes/${slug}/ is not up to date: ${behind}. ${runLine(root, `experimental theme editor show ${slug}`)} writes it again`,
1741
+ }
1742
+ : null;
1743
+ }
1744
+ // A build's copy write is reported once it has run (editorAfterBuild).
1745
+ return null;
1746
+ }
1747
+
1748
+ /**
1749
+ * For `compile` of an editor theme's own source (themes/<t>/<t>.theme.ts):
1750
+ * the one color mode a light-only or dark-only theme has, which its source
1751
+ * cannot say, for the build to write into the built module. Null for any
1752
+ * other file (the app copy's source re-exports it from its build).
1753
+ * @param {string} file the path as given
1754
+ * @param {string} cwd
1755
+ * @returns {['light'] | ['dark'] | null}
1756
+ */
1757
+ export function editorColorModes(file, cwd) {
1758
+ const root = projectRoot(cwd);
1759
+ const at = editorThemeAt(root, path.resolve(cwd, file));
1760
+ if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
1761
+ return buildColorModes(at.root, at.slug);
1762
+ }
1763
+
1764
+ /**
1765
+ * For `compile` of an editor theme (themes/<t>/ or its app copy's source):
1766
+ * whether a font family is loaded by the app copy's font stylesheet as
1767
+ * this compile writes it (src/themes/<t>/<t>.fonts.css, from the fonts the
1768
+ * theme loads now: an @fontsource package by its name, a stylesheet by the
1769
+ * `family=` it requests), so the build's "named but not loaded" notice
1770
+ * leaves it out. Null for any other file.
1771
+ * @param {string} file the path as given
1772
+ * @param {string} cwd
1773
+ * @returns {Promise<((family: string) => boolean) | null>}
1774
+ */
1775
+ export async function editorLoadedFonts(file, cwd) {
1776
+ const root = projectRoot(cwd);
1777
+ const abs = path.resolve(cwd, file);
1778
+ const slug =
1779
+ appCopyTheme(root, abs)?.slug ??
1780
+ (editorThemeAt(root, abs) &&
1781
+ editorOwnFile(editorThemeAt(root, abs)?.slug ?? '', file)
1782
+ ? editorThemeAt(root, abs)?.slug
1783
+ : null);
1784
+ if (!slug) return null;
1785
+ // The stylesheets the copy's font file imports once this compile has
1786
+ // written it: from the fonts the theme loads now, as the copy write
1787
+ // computes them.
1788
+ /** @type {string[]} */
1789
+ let specs;
1790
+ try {
1791
+ specs = copyFontsCss(await context(root), slug, loadTheme(root, slug));
1792
+ } catch {
1793
+ return null;
1794
+ }
1795
+ const copyDir = path.join(root, 'src', 'themes', slug);
1796
+ const from = fs.existsSync(copyDir) ? copyDir : root;
1797
+ /** @type {Set<string>} */
1798
+ const loaded = new Set();
1799
+ for (const spec of specs)
1800
+ for (const f of importedFontFamilies(spec, from)) loaded.add(f);
1801
+ // A family the build names whose @fontsource package is installed: the
1802
+ // copy written after this build imports that package (copyFontsCss).
1803
+ const req = createRequire(path.join(root, 'package.json'));
1804
+ /** @param {string} family */
1805
+ const installed = family => {
1806
+ try {
1807
+ req.resolve(`${fontsourcePackageOf(family)}/package.json`);
1808
+ return true;
1809
+ } catch {
1810
+ return false;
1811
+ }
1812
+ };
1813
+ return family => loaded.has(fontKey(family)) || installed(family);
1814
+ }
1815
+
968
1816
  /**
969
1817
  * For `compile` of a file that is not there: when it is an editor theme's
970
1818
  * own source (`themes/<t>/<t>.theme.ts` beside its settings), the command
@@ -974,6 +1822,37 @@ export async function editorThemeHold(files, {cwd}) {
974
1822
  * @returns {{name: string, reason: string} | null}
975
1823
  */
976
1824
  export function editorMissingSource(file, cwd) {
1825
+ // The app copy's source of an editor theme, its folder gone: the editor
1826
+ // writes it again.
1827
+ const copy = appCopyTheme(projectRoot(cwd), path.resolve(cwd, slashed(file)));
1828
+ if (copy)
1829
+ // A copy file named with Windows separators: the theme is what
1830
+ // compiles (the copy follows); with the copy gone, show writes it.
1831
+ return fs.existsSync(path.join(copy.root, 'src', 'themes', copy.slug))
1832
+ ? {
1833
+ name: runLine(
1834
+ cwd,
1835
+ `experimental theme compile ${
1836
+ path
1837
+ .relative(
1838
+ cwd,
1839
+ path.join(
1840
+ copy.root,
1841
+ 'themes',
1842
+ copy.slug,
1843
+ `${copy.slug}.theme.ts`,
1844
+ ),
1845
+ )
1846
+ .split(path.sep)
1847
+ .join('/') || `themes/${copy.slug}/${copy.slug}.theme.ts`
1848
+ }`,
1849
+ ),
1850
+ reason: `${copy.slug}'s app copy follows every compile of the theme`,
1851
+ }
1852
+ : {
1853
+ name: runLine(cwd, `experimental theme editor show ${copy.slug}`),
1854
+ reason: `the editor writes ${copy.slug}'s app copy in src/themes/${copy.slug}/ again`,
1855
+ };
977
1856
  const at = editorThemeAt(projectRoot(cwd), path.resolve(cwd, file));
978
1857
  if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
979
1858
  return {