@astryxdesign/cli 0.7.16 → 0.7.17-canary.gb36275e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/README.md +13 -23
  2. package/api/build/_adapter.d.mts +5 -0
  3. package/api/build/_adapter.mjs +49 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +2 -1
  7. package/api/build/kit/rank.mjs +59 -12
  8. package/api/build/kit/weights.d.mts +16 -3
  9. package/api/build/kit/weights.json +1 -1
  10. package/api/build/kit/weights.mjs +238 -31
  11. package/api/build/kit/word-model.d.mts +23 -0
  12. package/api/build/kit/word-model.mjs +46 -0
  13. package/api/build/kit/words.d.mts +42 -0
  14. package/api/build/kit/words.mjs +82 -1
  15. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  16. package/api/component/list/list.d.mts +1 -1
  17. package/api/component/list/list.mjs +46 -5
  18. package/api/discover/_adapter.d.mts +1 -1
  19. package/api/docs/_adapter.d.mts +26 -2
  20. package/api/docs/_adapter.mjs +217 -5
  21. package/api/docs/docs.d.mts +3 -0
  22. package/api/docs/docs.doc.mjs +7 -1
  23. package/api/docs/docs.mjs +12 -0
  24. package/api/docs/docs.type.d.mts +5 -0
  25. package/api/docs/docs.type.mjs +2 -0
  26. package/api/docs/node/node.mjs +1 -1
  27. package/api/doctor/_adapter.d.mts +27 -5
  28. package/api/doctor/_adapter.mjs +77 -6
  29. package/api/doctor/built-checks.mjs +38 -13
  30. package/api/doctor/doctor.d.mts +4 -3
  31. package/api/doctor/doctor.mjs +14 -7
  32. package/api/doctor/theme-checks.mjs +121 -17
  33. package/api/render/_adapter.mjs +531 -192
  34. package/api/render/render.doc.mjs +11 -3
  35. package/api/render/render.type.d.mts +30 -0
  36. package/api/render/render.type.mjs +19 -0
  37. package/api/search/ORDERING.md +1 -1
  38. package/api/search/_candidate-score.mjs +51 -32
  39. package/api/search/_fit-order.mjs +3 -3
  40. package/api/search/_result.d.mts +5 -5
  41. package/api/search/_score.d.mts +6 -1
  42. package/api/search/_score.mjs +15 -3
  43. package/api/search/search.d.mts +1 -1
  44. package/api/theme/_adapter.mjs +10 -0
  45. package/api/theme/build/build.d.mts +47 -0
  46. package/api/theme/build/build.mjs +147 -25
  47. package/api/theme/theme.type.d.mts +10 -0
  48. package/api/theme/theme.type.mjs +7 -1
  49. package/api/theme-edit/_adapter.d.mts +48 -0
  50. package/api/theme-edit/_adapter.mjs +675 -42
  51. package/api/theme-edit/_check.d.mts +28 -22
  52. package/api/theme-edit/_check.mjs +1481 -252
  53. package/api/theme-edit/_color.d.mts +9 -0
  54. package/api/theme-edit/_color.mjs +41 -1
  55. package/api/theme-edit/_compiler.mjs +9 -0
  56. package/api/theme-edit/_context.mjs +60 -3
  57. package/api/theme-edit/_css.mjs +21 -1
  58. package/api/theme-edit/_edit.d.mts +22 -0
  59. package/api/theme-edit/_edit.mjs +1196 -88
  60. package/api/theme-edit/_how-commands.d.mts +57 -0
  61. package/api/theme-edit/_how-commands.mjs +536 -1
  62. package/api/theme-edit/_how-question.d.mts +65 -0
  63. package/api/theme-edit/_how-question.mjs +4401 -225
  64. package/api/theme-edit/_how.mjs +104 -4
  65. package/api/theme-edit/_marks.d.mts +31 -5
  66. package/api/theme-edit/_marks.mjs +57 -5
  67. package/api/theme-edit/_normal.d.mts +153 -0
  68. package/api/theme-edit/_normal.mjs +661 -0
  69. package/api/theme-edit/_palette.mjs +10 -4
  70. package/api/theme-edit/_parts.d.mts +8 -0
  71. package/api/theme-edit/_parts.mjs +103 -2
  72. package/api/theme-edit/_preview-app.d.mts +7 -1
  73. package/api/theme-edit/_preview-app.mjs +205 -17
  74. package/api/theme-edit/_preview.d.mts +64 -8
  75. package/api/theme-edit/_preview.mjs +447 -89
  76. package/api/theme-edit/_settings.d.mts +176 -5
  77. package/api/theme-edit/_settings.mjs +1936 -128
  78. package/api/theme-edit/_tables.d.mts +6 -0
  79. package/api/theme-edit/_tables.mjs +32 -1
  80. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  81. package/api/theme-edit/theme-edit.type.mjs +4 -1
  82. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  83. package/assets/codemods/run-codemod.mjs +73 -6
  84. package/assets/codemods/transforms/next/index.mjs +11 -1
  85. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  86. package/assets/docs/author-a-theme.doc.mjs +1 -0
  87. package/assets/docs/theme.doc.dense.mjs +2 -2
  88. package/assets/docs/theme.doc.mjs +1 -1
  89. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  90. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  91. package/assets/docs/tree/render-pages.doc.mjs +43 -2
  92. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  93. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  94. package/assets/docs/use-a-theme.doc.mjs +1 -1
  95. package/assets/docs.generated.json +2 -2
  96. package/assets/self-audit.generated.json +1 -1
  97. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  98. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  99. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  100. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  101. package/assets/templates/components.generated.json +1 -1
  102. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  103. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  104. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  105. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  106. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  107. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  108. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  109. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  110. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  111. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  112. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  113. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  114. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  115. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  116. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  117. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  118. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  119. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  120. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  121. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  122. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  123. package/assets/templates/pages/ide/page.tsx +24 -2
  124. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  125. package/assets/templates/pages/library/template.doc.mjs +4 -1
  126. package/assets/templates/pages/login/template.doc.mjs +2 -1
  127. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  128. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  129. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  130. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  131. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  132. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  133. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  134. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  135. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  136. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  137. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  138. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  139. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  140. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  141. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  142. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  143. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  144. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  145. package/authoring/debug/parse.d.mts +3 -3
  146. package/authoring/doctypes/_schema.d.mts +3 -3
  147. package/authoring/doctypes/command/command.doc.mjs +1 -1
  148. package/authoring/doctypes/template/template.doc.mjs +1 -1
  149. package/authoring/doctypes/template/type.ts +9 -0
  150. package/clients/cli/bin/astryx.mjs +6 -9
  151. package/clients/cli/build-id.generated.json +1 -1
  152. package/clients/cli/commands/component.doc.mjs +1 -1
  153. package/clients/cli/commands/component.mjs +20 -2
  154. package/clients/cli/commands/docs.doc.mjs +7 -1
  155. package/clients/cli/commands/docs.mjs +3 -1
  156. package/clients/cli/commands/doctor.mjs +22 -14
  157. package/clients/cli/commands/experimental/render.mjs +32 -1
  158. package/clients/cli/commands/experimental/theme.mjs +65 -14
  159. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  160. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  161. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  162. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  163. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  164. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  165. package/clients/cli/commands/search.doc.mjs +2 -1
  166. package/clients/cli/commands/search.mjs +6 -1
  167. package/clients/cli/commands/template.mjs +4 -2
  168. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  169. package/clients/cli/commands/theme.doc.mjs +1 -1
  170. package/clients/cli/commands/theme.mjs +153 -5
  171. package/clients/cli/commands/upgrade.mjs +42 -7
  172. package/clients/cli/index.mjs +1 -1
  173. package/clients/cli/lib/component-format.mjs +205 -98
  174. package/clients/cli/lib/hook-format.mjs +9 -19
  175. package/clients/cli/manifest.generated.json +1 -1
  176. package/foundation/agent-docs/agent-docs.mjs +1 -1
  177. package/foundation/config/theme-state.d.mts +13 -1
  178. package/foundation/config/theme-state.mjs +47 -7
  179. package/foundation/discovery/component-discovery.d.mts +11 -0
  180. package/foundation/discovery/component-discovery.mjs +27 -2
  181. package/foundation/discovery/component-replacement.mjs +130 -1
  182. package/foundation/discovery/entry-name-files.d.mts +43 -0
  183. package/foundation/discovery/entry-name-files.mjs +264 -0
  184. package/foundation/discovery/hook-discovery.d.mts +8 -2
  185. package/foundation/discovery/hook-discovery.mjs +20 -7
  186. package/foundation/discovery/package-exports.d.mts +10 -0
  187. package/foundation/discovery/package-exports.mjs +56 -3
  188. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  189. package/foundation/discovery/runner-allowlist.mjs +2 -0
  190. package/foundation/discovery/template-adapter.d.mts +52 -0
  191. package/foundation/discovery/template-adapter.mjs +173 -10
  192. package/foundation/discovery/theme-imports.d.mts +14 -0
  193. package/foundation/discovery/theme-imports.mjs +43 -1
  194. package/foundation/doc-compiler/import.mjs +7 -1
  195. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  196. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  197. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  198. package/foundation/fs/cache-eviction.d.mts +21 -0
  199. package/foundation/fs/cache-eviction.mjs +73 -0
  200. package/foundation/fs/gather-cache.d.mts +25 -4
  201. package/foundation/fs/gather-cache.mjs +163 -53
  202. package/foundation/fs/jiti-cache.d.mts +19 -1
  203. package/foundation/fs/jiti-cache.mjs +130 -6
  204. package/foundation/fs/kept-tree.d.mts +60 -0
  205. package/foundation/fs/kept-tree.mjs +154 -0
  206. package/foundation/fs/module-loader.d.mts +18 -2
  207. package/foundation/fs/module-loader.mjs +92 -20
  208. package/foundation/identity/provider-identity.d.mts +6 -0
  209. package/foundation/identity/provider-identity.mjs +10 -1
  210. package/foundation/render/embedded-imports.d.mts +5 -4
  211. package/foundation/render/embedded-imports.mjs +7 -16
  212. package/foundation/render/file-header.d.mts +66 -0
  213. package/foundation/render/file-header.mjs +118 -0
  214. package/foundation/render/host-answer.d.mts +18 -0
  215. package/foundation/render/host-answer.mjs +46 -0
  216. package/foundation/render/host-exit.d.mts +1 -0
  217. package/foundation/render/host-exit.mjs +6 -1
  218. package/foundation/render/html-reader.d.mts +55 -2
  219. package/foundation/render/html-reader.mjs +145 -26
  220. package/foundation/render/markup-edits.d.mts +57 -0
  221. package/foundation/render/markup-edits.mjs +182 -0
  222. package/foundation/render/page-host.mjs +29 -12
  223. package/foundation/render/page-worker.mjs +83 -13
  224. package/foundation/render/render-page.d.mts +34 -2
  225. package/foundation/render/render-page.mjs +210 -29
  226. package/foundation/render/source-block.d.mts +73 -6
  227. package/foundation/render/source-block.mjs +170 -19
  228. package/foundation/render/ts-paths.d.mts +53 -6
  229. package/foundation/render/ts-paths.mjs +286 -41
  230. package/foundation/response/error-codes.d.mts +3 -1
  231. package/foundation/response/error-codes.d.ts +1 -0
  232. package/foundation/response/error-codes.doc.mjs +12 -1
  233. package/foundation/response/error-codes.mjs +10 -0
  234. package/foundation/text/string-utils.d.mts +3 -2
  235. package/foundation/text/string-utils.mjs +16 -3
  236. package/foundation/text/suggest-order.d.mts +9 -0
  237. package/foundation/text/suggest-order.mjs +13 -0
  238. package/host/index.mjs +8 -6
  239. package/package.json +6 -6
@@ -64,6 +64,7 @@ import {createRequire, isBuiltin} from 'node:module';
64
64
  import {fileURLToPath, pathToFileURL} from 'node:url';
65
65
  import {babelParse as parse} from '../../../foundation/runtime/lazy-dependencies.mjs';
66
66
  import {createJiti} from 'jiti';
67
+ import {jitiCacheOptions} from '../../../foundation/fs/jiti-cache.mjs';
67
68
  import {
68
69
  formatCliCommand,
69
70
  getCliInvocation,
@@ -92,6 +93,7 @@ import {applyWrites} from '../../integration/add-helpers.mjs';
92
93
  import {logger} from '../../logger.mjs';
93
94
  import {loadComponentDoc} from '../../../foundation/discovery/component-loader.mjs';
94
95
  import {THEME_SOURCE_EXTENSIONS} from '../../../foundation/discovery/theme-module-extensions.mjs';
96
+ import {withEmptyStylesheets} from '../../../foundation/fs/module-loader.mjs';
95
97
  import {
96
98
  collectThemingTargets,
97
99
  targetsByKey,
@@ -108,6 +110,7 @@ import {
108
110
  } from '../../../foundation/discovery/template-needs.mjs';
109
111
  import {generateFamilyCSS, resolveThemeFamily} from './family.mjs';
110
112
  import {resolveIconImports} from './icon-imports.mjs';
113
+ import {generatedMark} from '../../theme-edit/_marks.mjs';
111
114
 
112
115
  // Import shared theme processing from core. `astryx theme build` MUST produce the
113
116
  // exact same CSS as the `<Theme>` runtime, so it has exactly one generation
@@ -333,10 +336,12 @@ function realOrSelf(file) {
333
336
  /**
334
337
  * `target` spelled through real directories: the deepest ancestor that exists
335
338
  * is resolved through its symlinks, and the missing rest is appended as given.
339
+ * The build confines its outputs by it, and the theme editor's compile guard
340
+ * reads paths through it too, so both read a path the same way.
336
341
  * @param {string} target absolute path
337
342
  * @returns {string}
338
343
  */
339
- function realLocation(target) {
344
+ export function realLocation(target) {
340
345
  /** @type {string[]} */
341
346
  const missing = [];
342
347
  let existing = target;
@@ -925,6 +930,82 @@ function isDirectorySync(file) {
925
930
  }
926
931
  }
927
932
 
933
+ /**
934
+ * The marks a file's leading comment carries (see `generatedMark`): a theme
935
+ * build's output, or a file the theme editor writes, with the command it
936
+ * names. The one reader build and doctor share.
937
+ * @param {string} source the start of the file
938
+ * @param {string} [file] its path, for a mark that names no exact command
939
+ */
940
+ export function fileMark(source, file) {
941
+ return generatedMark(source, GENERATED_MARKER, file);
942
+ }
943
+
944
+ /**
945
+ * The command a file's leading comment says writes it, when another CLI
946
+ * command generates it (the theme editor's settings module or app copy):
947
+ * the exact command its mark names. Null for a theme build's own output and
948
+ * a file without a mark, such as a theme source of one's own.
949
+ * @param {string} file
950
+ * @returns {string | null}
951
+ */
952
+ export function generatedFileCommand(file) {
953
+ const mark = fileMark(fileHead(file), file);
954
+ return mark?.kind === 'editor' ? mark.command : null;
955
+ }
956
+
957
+ /**
958
+ * The command that writes a missing `file`: a file beside it carries
959
+ * another command's mark, and a file there names `file` (a build output's
960
+ * header names its source), so it is one that command writes. Null for any
961
+ * other name, such as a typo.
962
+ * @param {string} file
963
+ * @returns {string | null}
964
+ */
965
+ function missingGeneratedCommand(file) {
966
+ const dir = path.dirname(file);
967
+ const base = path.basename(file);
968
+ let names;
969
+ try {
970
+ names = fs.readdirSync(dir).sort();
971
+ } catch {
972
+ return null;
973
+ }
974
+ /** @type {string | null} */
975
+ let by = null;
976
+ let named = false;
977
+ for (const n of names) {
978
+ const f = path.join(dir, n);
979
+ try {
980
+ if (!fs.statSync(f).isFile()) continue;
981
+ } catch {
982
+ continue;
983
+ }
984
+ by ??= generatedFileCommand(f);
985
+ if (!named)
986
+ try {
987
+ named = fs.readFileSync(f, 'utf8').slice(0, 4000).includes(base);
988
+ } catch {
989
+ // A file that does not read names nothing.
990
+ }
991
+ if (by && named) return by;
992
+ }
993
+ return null;
994
+ }
995
+
996
+ /**
997
+ * The command that writes `file`: from its own mark, or, when it is
998
+ * missing, from the files beside it (see `missingGeneratedCommand`); null
999
+ * otherwise.
1000
+ * @param {string} file
1001
+ * @returns {string | null}
1002
+ */
1003
+ export function generatedSourceCommand(file) {
1004
+ return fs.existsSync(file)
1005
+ ? generatedFileCommand(file)
1006
+ : missingGeneratedCommand(file);
1007
+ }
1008
+
928
1009
  /** @param {string} file @returns {string} the start of a file, or '' when it cannot be read */
929
1010
  function fileHead(file) {
930
1011
  try {
@@ -1121,7 +1202,9 @@ function assertThemeSourceFile(filePath, cwd, mode = {}) {
1121
1202
  * output must stay inside, for a scratch build; `commandWords` names the
1122
1203
  * command in the rebuild hint; `prepareFamily`, `familyLoader`, and
1123
1204
  * `familyInterception` make the build a family member's plan.
1124
- * @typedef {{prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}}} ThemeBuildHandOff
1205
+ * `colorModes` is the one color mode a calling command knows the theme has
1206
+ * (the theme editor, from its settings), written into the built module.
1207
+ * @typedef {{prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}, colorModes?: ['light'] | ['dark'] | null}} ThemeBuildHandOff
1125
1208
  */
1126
1209
 
1127
1210
  /**
@@ -2630,9 +2713,13 @@ function isSyncLoaderLimitation(error) {
2630
2713
  * source export and old-Core adaptation checks keep treating that path as
2631
2714
  * degraded/fail-closed.
2632
2715
  *
2716
+ * On Node 22.15 and later, on every path, a stylesheet that a module in the
2717
+ * theme's graph imports loads as an empty module (`withEmptyStylesheets`): a
2718
+ * base theme's module can import its own stylesheet for the app's bundler.
2719
+ *
2633
2720
  * @param {string} filePath
2634
2721
  * @param {import('./core-interception.mjs').CoreInterception} [interception]
2635
- * @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
2722
+ * @returns {Promise<{theme: any, exportName: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes: ["light"] | ["dark"] | null}>}
2636
2723
  */
2637
2724
  // prettier-ignore
2638
2725
  async function importThemeModule(filePath, interception, /** @type {any} */ loader = undefined) {
@@ -2640,9 +2727,9 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2640
2727
  loader ??
2641
2728
  createJiti(import.meta.url, {
2642
2729
  moduleCache: false,
2643
- // No transpile cache: it is written to the system temp folder, named
2644
- // for the theme, and never removed, so every edit added files there.
2645
- fsCache: false,
2730
+ // The per-user transpile cache: an edited theme is transpiled again,
2731
+ // and the folder stays within its size limit.
2732
+ ...jitiCacheOptions(),
2646
2733
  jsx: true,
2647
2734
  extensions: THEME_MODULE_EXTENSIONS,
2648
2735
  ...(interception ? {virtualModules: interception.modules} : {}),
@@ -2659,7 +2746,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2659
2746
  const commonJsPatch = interception.patchCommonJs(filePath);
2660
2747
  try {
2661
2748
  try {
2662
- mod = jiti(filePath);
2749
+ mod = await withEmptyStylesheets(async () => jiti(filePath));
2663
2750
  } catch (error) {
2664
2751
  // Only a sync-loader limitation may fall back. Anything else is the
2665
2752
  // theme's own failure and belongs to the caller unchanged.
@@ -2668,14 +2755,16 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2668
2755
  // Force asynchronous transformation instead of native import: this
2669
2756
  // keeps virtual Core interception active even when the module uses
2670
2757
  // top-level await.
2671
- mod = await jiti.evalModule(fs.readFileSync(filePath, 'utf8'), {
2672
- id: filePath,
2673
- filename: filePath,
2674
- ext: path.extname(filePath),
2675
- cache: jiti.cache,
2676
- async: true,
2677
- forceTranspile: true,
2678
- });
2758
+ mod = await withEmptyStylesheets(() =>
2759
+ jiti.evalModule(fs.readFileSync(filePath, 'utf8'), {
2760
+ id: filePath,
2761
+ filename: filePath,
2762
+ ext: path.extname(filePath),
2763
+ cache: jiti.cache,
2764
+ async: true,
2765
+ forceTranspile: true,
2766
+ }),
2767
+ );
2679
2768
  }
2680
2769
  } finally {
2681
2770
  // Read after the load: the root is wrapped when the load requires it.
@@ -2683,7 +2772,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2683
2772
  commonJsPatch.undo();
2684
2773
  }
2685
2774
  } else {
2686
- mod = await jiti.import(filePath);
2775
+ mod = await withEmptyStylesheets(() => jiti.import(filePath));
2687
2776
  }
2688
2777
 
2689
2778
  // Both loads hand back the module. The theme is read from the module's own
@@ -2692,15 +2781,22 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2692
2781
  // `default` with the module), so the module can pass for the theme while
2693
2782
  // its own keys hide the theme's fields.
2694
2783
  const isModule = mod != null && typeof mod === 'object';
2784
+ // A theme with one color mode says so with a `colorModes` export beside
2785
+ // the theme (`['light']` or `['dark']`); the build carries it into the
2786
+ // built module.
2787
+ const colorModes = oneColorMode(
2788
+ isModule && Object.hasOwn(mod, 'colorModes') ? mod.colorModes : undefined,
2789
+ );
2695
2790
  const hasDefault = isModule && Object.hasOwn(mod, 'default');
2696
2791
  const defaultExport = hasDefault ? mod.default : undefined;
2697
2792
  if (isThemeObject(defaultExport)) {
2698
- return {theme: defaultExport, exportName: 'default', degraded};
2793
+ return {theme: defaultExport, exportName: 'default', degraded, colorModes};
2699
2794
  }
2700
2795
  if (isModule) {
2701
2796
  for (const [exportName, value] of Object.entries(mod)) {
2702
2797
  if (exportName === 'default' || exportName === 'module.exports') continue;
2703
- if (isThemeObject(value)) return {theme: value, exportName, degraded};
2798
+ if (isThemeObject(value))
2799
+ return {theme: value, exportName, degraded, colorModes};
2704
2800
  }
2705
2801
  }
2706
2802
  // The loader's interop answers a null default with the module itself, so
@@ -2722,7 +2818,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2722
2818
  // be all it defines), or no name: the build's validation says what it
2723
2819
  // lacks.
2724
2820
  if (isPlainObject(defaultExport)) {
2725
- return {theme: defaultExport, exportName: 'default', degraded};
2821
+ return {theme: defaultExport, exportName: 'default', degraded, colorModes};
2726
2822
  }
2727
2823
  // A CommonJS module whose exports are the theme (`module.exports =
2728
2824
  // theme`) has no default of its own: interop answers `default` with
@@ -2731,7 +2827,7 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
2731
2827
  if (isModule && !hasDefault) {
2732
2828
  const exportsObject = mod.default ?? mod;
2733
2829
  if (isThemeObject(exportsObject)) {
2734
- return {theme: exportsObject, exportName: 'default', degraded};
2830
+ return {theme: exportsObject, exportName: 'default', degraded, colorModes};
2735
2831
  }
2736
2832
  }
2737
2833
 
@@ -2800,7 +2896,7 @@ function isThemeObject(value) {
2800
2896
  *
2801
2897
  * @param {string} filePath
2802
2898
  * @param {import('./core-interception.mjs').CoreInterception} [interception]
2803
- * @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}}>}
2899
+ * @returns {Promise<{theme: any, exportName?: string, degraded: {topLevelAwait: boolean, commonJs: boolean}, colorModes?: ['light'] | ['dark'] | null}>}
2804
2900
  */
2805
2901
  // prettier-ignore
2806
2902
  async function extractThemeDefinition(filePath, interception, /** @type {any} */ loader = undefined) {
@@ -2815,6 +2911,20 @@ async function extractThemeDefinition(filePath, interception, /** @type {any} */
2815
2911
  }
2816
2912
  }
2817
2913
 
2914
+ /**
2915
+ * A one-mode `colorModes` value (`['light']` or `['dark']`), or null for
2916
+ * anything else: a theme with both modes needs no export.
2917
+ * @param {unknown} value
2918
+ * @returns {['light'] | ['dark'] | null}
2919
+ */
2920
+ export function oneColorMode(value) {
2921
+ return Array.isArray(value) &&
2922
+ value.length === 1 &&
2923
+ (value[0] === 'light' || value[0] === 'dark')
2924
+ ? /** @type {['light'] | ['dark']} */ ([value[0]])
2925
+ : null;
2926
+ }
2927
+
2818
2928
  /** Names a theme module's exports must take; ends a shape failure. */
2819
2929
  const THEME_EXPORT_FIX =
2820
2930
  "Export the theme object: `export default defineTheme({name: 'my-theme', tokens: {...}})`, or a plain `export default {name: 'my-theme', tokens: {...}}`.";
@@ -3825,6 +3935,9 @@ async function themeBuildInternal(
3825
3935
  let themeExportName;
3826
3936
  /** Paths through the load that interception could not fully observe. */
3827
3937
  let loadDegradation;
3938
+ /** The one color mode the theme module exports, or null for both. */
3939
+ /** @type {['light'] | ['dark'] | null} */
3940
+ let colorModes;
3828
3941
  /**
3829
3942
  * The theme file's bytes as loaded: read before and after the load, and the
3830
3943
  * registry scan below reads these rather than the file again. An editor's
@@ -3851,6 +3964,7 @@ async function themeBuildInternal(
3851
3964
  themeDef = loaded.theme;
3852
3965
  themeExportName = loaded.exportName;
3853
3966
  loadDegradation = loaded.degraded;
3967
+ colorModes = handOff.colorModes ?? loaded.colorModes ?? null;
3854
3968
  } catch (e) {
3855
3969
  const err = /** @type {Error} */ (e);
3856
3970
  const shown = path.relative(cwd, filePath) || filePath;
@@ -4482,10 +4596,18 @@ async function themeBuildInternal(
4482
4596
  ? {}
4483
4597
  : {cssFileName: path.basename(outPath)}),
4484
4598
  },
4485
- );
4599
+ ) +
4600
+ // The one color mode, beside the theme export (a two-mode theme
4601
+ // exports none, so its module is unchanged).
4602
+ (colorModes
4603
+ ? `export const colorModes = [${JSON.stringify(colorModes[0])}];\n`
4604
+ : '');
4486
4605
  const dtsContent =
4487
4606
  generatedHeader(headerSource, 'ts', buildCommand, versions) +
4488
- generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName);
4607
+ generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName) +
4608
+ (colorModes
4609
+ ? `export declare const colorModes: readonly [${JSON.stringify(colorModes[0])}];\n`
4610
+ : '');
4489
4611
 
4490
4612
  const unloadedFonts = [
4491
4613
  ...new Set([
@@ -4998,7 +5120,7 @@ function planFamilySources(files, cwd) {
4998
5120
  // prettier-ignore
4999
5121
  async function preloadFamilySource(filePath, loader, interception) {
5000
5122
  const patch = interception.patchCommonJs(filePath);
5001
- try { try { loader(filePath); } catch (error) { if (!isSyncLoaderLimitation(error)) throw error; await loader.evalModule(fs.readFileSync(filePath, 'utf8'), {id: filePath, filename: filePath, ext: path.extname(filePath), cache: loader.cache, async: true, forceTranspile: true}); } }
5123
+ try { try { await withEmptyStylesheets(async () => loader(filePath)); } catch (error) { if (!isSyncLoaderLimitation(error)) throw error; await withEmptyStylesheets(() => loader.evalModule(fs.readFileSync(filePath, 'utf8'), {id: filePath, filename: filePath, ext: path.extname(filePath), cache: loader.cache, async: true, forceTranspile: true})); } }
5002
5124
  finally { patch.undo(); }
5003
5125
  }
5004
5126
 
@@ -5026,7 +5148,7 @@ export async function themeBuildFamily(
5026
5148
  await selectCore(cwd);
5027
5149
  const familyInterception = interceptCore(_coreThemeModule, _coreRootModule);
5028
5150
  // prettier-ignore
5029
- const familyLoader = createJiti(import.meta.url, {moduleCache: true, fsCache: false, interopDefault: false, jsx: true, extensions: THEME_MODULE_EXTENSIONS, virtualModules: familyInterception.modules});
5151
+ const familyLoader = createJiti(import.meta.url, {moduleCache: true, ...jitiCacheOptions(), interopDefault: false, jsx: true, extensions: THEME_MODULE_EXTENSIONS, virtualModules: familyInterception.modules});
5030
5152
  /** @type {any[]} */
5031
5153
  const prepared = [];
5032
5154
  for (const source of planFamilySources(files, cwd)) {
@@ -137,6 +137,12 @@ export type ThemeAppEntry = {
137
137
  */
138
138
  fontStylesheet?: string | undefined;
139
139
  source: "bundled" | "package" | "local";
140
+ /**
141
+ * the one color mode the theme has, when its
142
+ * built module exports one (`colorModes`); the generated module then lists
143
+ * it in `themeModes`. Absent for a theme with both modes.
144
+ */
145
+ mode?: "light" | "dark" | undefined;
140
146
  };
141
147
  /**
142
148
  * astryx --json theme add <slug> [--import] / remove / use
@@ -149,6 +155,9 @@ export type ThemeAppResponse = {
149
155
  * `notes` is present only when the command did more than its change says:
150
156
  * it chose between a local and a package theme with one slug, replaced a
151
157
  * recorded owner, or dropped a recorded theme whose source is gone.
158
+ * `change.wireModes` is present when the module lists a theme's one color
159
+ * mode (`themeModes`) for the first time after the app was wired: the app's
160
+ * `Theme` then takes `mode={themeModes[defaultThemeSlug] ?? 'system'}`.
152
161
  */
153
162
  package?: string | undefined;
154
163
  data: {
@@ -160,6 +169,7 @@ export type ThemeAppResponse = {
160
169
  slug: string;
161
170
  changed: boolean;
162
171
  firstAdd: boolean;
172
+ wireModes?: true;
163
173
  };
164
174
  notes?: string[];
165
175
  };
@@ -92,6 +92,9 @@
92
92
  * @property {string} stylesheet production stylesheet import
93
93
  * @property {string} [fontStylesheet] package-owned font stylesheet import
94
94
  * @property {'bundled'|'package'|'local'} source
95
+ * @property {'light'|'dark'} [mode] the one color mode the theme has, when its
96
+ * built module exports one (`colorModes`); the generated module then lists
97
+ * it in `themeModes`. Absent for a theme with both modes.
95
98
  */
96
99
 
97
100
  /**
@@ -103,7 +106,10 @@
103
106
  * `notes` is present only when the command did more than its change says:
104
107
  * it chose between a local and a package theme with one slug, replaced a
105
108
  * recorded owner, or dropped a recorded theme whose source is gone.
106
- * @property {{themes: ThemeAppEntry[], default: string, modulePath: string, change: {action: 'add'|'remove'|'use', slug: string, changed: boolean, firstAdd: boolean}, notes?: string[]}} data
109
+ * `change.wireModes` is present when the module lists a theme's one color
110
+ * mode (`themeModes`) for the first time after the app was wired: the app's
111
+ * `Theme` then takes `mode={themeModes[defaultThemeSlug] ?? 'system'}`.
112
+ * @property {{themes: ThemeAppEntry[], default: string, modulePath: string, change: {action: 'add'|'remove'|'use', slug: string, changed: boolean, firstAdd: boolean, wireModes?: true}, notes?: string[]}} data
107
113
  */
108
114
 
109
115
  /**
@@ -30,6 +30,18 @@ export function projectRoot(cwd: string): string;
30
30
  * @returns {AstryxError | null}
31
31
  */
32
32
  export function editorThemeRefusal(err: AstryxError, cwd: string): AstryxError | null;
33
+ /**
34
+ * A refused compile whose first suggestion is another compile: that compile
35
+ * is run through compile's own checks before it is offered (in memory,
36
+ * nothing built), and each repair a refusal of it offers is folded into the
37
+ * one line. An --out outside the working folder is dropped, and the reason
38
+ * says why; when the rest cannot be repaired, the reason says so. A line
39
+ * that starts with `cd` runs elsewhere, so it is not checked from here.
40
+ * @param {AstryxError} err
41
+ * @param {string} cwd
42
+ * @returns {Promise<AstryxError>}
43
+ */
44
+ export function editorFollowCompile(err: AstryxError, cwd: string): Promise<AstryxError>;
33
45
  /**
34
46
  * A refusal before `compile` runs on an editor theme's files, or null: the
35
47
  * editor's generated settings are not a theme source, `--family` does not
@@ -59,6 +71,42 @@ export function editorCompileProblem(files: string[], { cwd, check, family, icon
59
71
  export function editorThemeHold(files: string[], { cwd }: {
60
72
  cwd: string;
61
73
  }): Promise<() => Promise<void>>;
74
+ /**
75
+ * For `compile` of an editor theme: `appCopyStale` for its result data when
76
+ * the app copy is behind (the same line set and show give); null for any
77
+ * other file or a current copy.
78
+ * @param {string} file the path as given
79
+ * @param {string} cwd
80
+ * @param {{check: boolean, upToDate?: boolean}} opts `upToDate`: the
81
+ * check's own verdict on the theme's outputs
82
+ * @returns {Promise<Record<string, unknown> | null>}
83
+ */
84
+ export function editorBuildExtra(file: string, cwd: string, opts: {
85
+ check: boolean;
86
+ upToDate?: boolean;
87
+ }): Promise<Record<string, unknown> | null>;
88
+ /**
89
+ * For `compile` of an editor theme's own source (themes/<t>/<t>.theme.ts):
90
+ * the one color mode a light-only or dark-only theme has, which its source
91
+ * cannot say, for the build to write into the built module. Null for any
92
+ * other file (the app copy's source re-exports it from its build).
93
+ * @param {string} file the path as given
94
+ * @param {string} cwd
95
+ * @returns {['light'] | ['dark'] | null}
96
+ */
97
+ export function editorColorModes(file: string, cwd: string): ["light"] | ["dark"] | null;
98
+ /**
99
+ * For `compile` of an editor theme (themes/<t>/ or its app copy's source):
100
+ * whether a font family is loaded by the app copy's font stylesheet as
101
+ * this compile writes it (src/themes/<t>/<t>.fonts.css, from the fonts the
102
+ * theme loads now: an @fontsource package by its name, a stylesheet by the
103
+ * `family=` it requests), so the build's "named but not loaded" notice
104
+ * leaves it out. Null for any other file.
105
+ * @param {string} file the path as given
106
+ * @param {string} cwd
107
+ * @returns {Promise<((family: string) => boolean) | null>}
108
+ */
109
+ export function editorLoadedFonts(file: string, cwd: string): Promise<((family: string) => boolean) | null>;
62
110
  /**
63
111
  * For `compile` of a file that is not there: when it is an editor theme's
64
112
  * own source (`themes/<t>/<t>.theme.ts` beside its settings), the command