@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61

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 (203) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/README.md +63 -63
  3. package/api/build/_adapter.d.mts +4 -0
  4. package/api/build/_adapter.mjs +28 -2
  5. package/api/build/blocks/blocks.d.mts +10 -1
  6. package/api/build/blocks/blocks.mjs +84 -7
  7. package/api/build/build.mjs +6 -1
  8. package/api/build/tree.d.mts +4 -0
  9. package/api/build/tree.mjs +9 -2
  10. package/api/doctor/_adapter.d.mts +3 -1
  11. package/api/doctor/_adapter.mjs +14 -1
  12. package/api/doctor/_authoring-audit.d.mts +42 -0
  13. package/api/doctor/_authoring-audit.mjs +106 -0
  14. package/api/doctor/doctor.d.mts +7 -0
  15. package/api/doctor/doctor.mjs +24 -39
  16. package/api/doctor/theme-checks.mjs +56 -21
  17. package/api/integration/add-helpers.mjs +5 -0
  18. package/api/integration/add-theme.mjs +15 -110
  19. package/api/integration/validate-integration.mjs +17 -3
  20. package/api/integration/validateIntegration.doc.mjs +1 -1
  21. package/api/search/_adapter.mjs +124 -3
  22. package/api/search/_candidate-score.mjs +63 -9
  23. package/api/search/_entries.d.mts +10 -0
  24. package/api/search/_entries.mjs +68 -1
  25. package/api/search/_gather-templates.d.mts +11 -0
  26. package/api/search/_gather-templates.mjs +22 -2
  27. package/api/search/_words.mjs +26 -6
  28. package/api/swizzle/copy/copy.mjs +1 -1
  29. package/api/theme/_adapter.d.mts +37 -5
  30. package/api/theme/_adapter.mjs +381 -57
  31. package/api/theme/_fork.d.mts +90 -0
  32. package/api/theme/_fork.mjs +246 -0
  33. package/api/theme/build/build.d.mts +40 -2
  34. package/api/theme/build/build.mjs +477 -66
  35. package/api/theme/eject/eject.mjs +36 -15
  36. package/api/theme/list/list.mjs +3 -6
  37. package/api/theme/palette/generate/generator.d.mts +13 -0
  38. package/api/theme/palette/generate/generator.mjs +32 -2
  39. package/api/theme/targets/targets.d.mts +8 -0
  40. package/api/theme/targets/targets.mjs +24 -4
  41. package/api/theme/template/template.mjs +48 -2
  42. package/api/theme/theme.type.d.mts +8 -0
  43. package/api/theme/theme.type.mjs +5 -1
  44. package/api/theme/themeBuild.doc.mjs +7 -4
  45. package/api/theme/themeEject.doc.mjs +3 -3
  46. package/api/theme/themeRemove.doc.mjs +5 -2
  47. package/api/theme/themeTargets.doc.mjs +1 -1
  48. package/api/theme/themeTemplate.doc.mjs +2 -2
  49. package/api/theme/themeUse.doc.mjs +8 -2
  50. package/api/theme-edit/_adapter.d.mts +46 -3
  51. package/api/theme-edit/_adapter.mjs +496 -112
  52. package/api/theme-edit/_catalog.d.mts +1 -6
  53. package/api/theme-edit/_catalog.mjs +5 -268
  54. package/api/theme-edit/_check.d.mts +9 -4
  55. package/api/theme-edit/_check.mjs +1232 -229
  56. package/api/theme-edit/_color.d.mts +19 -0
  57. package/api/theme-edit/_color.mjs +280 -34
  58. package/api/theme-edit/_compiler.d.mts +3 -1
  59. package/api/theme-edit/_compiler.mjs +52 -13
  60. package/api/theme-edit/_context.d.mts +4 -1
  61. package/api/theme-edit/_context.mjs +126 -13
  62. package/api/theme-edit/_css.d.mts +84 -0
  63. package/api/theme-edit/_css.mjs +700 -0
  64. package/api/theme-edit/_edit.d.mts +9 -3
  65. package/api/theme-edit/_edit.mjs +806 -103
  66. package/api/theme-edit/_how-commands.d.mts +38 -7
  67. package/api/theme-edit/_how-commands.mjs +64 -45
  68. package/api/theme-edit/_how-question.d.mts +33 -0
  69. package/api/theme-edit/_how-question.mjs +2553 -381
  70. package/api/theme-edit/_how.mjs +402 -31
  71. package/api/theme-edit/_overview.mjs +2 -7
  72. package/api/theme-edit/_palette.d.mts +60 -13
  73. package/api/theme-edit/_palette.mjs +826 -295
  74. package/api/theme-edit/_parts.d.mts +42 -10
  75. package/api/theme-edit/_parts.mjs +280 -69
  76. package/api/theme-edit/_png.d.mts +4 -4
  77. package/api/theme-edit/_png.mjs +4 -2
  78. package/api/theme-edit/_preview-app.d.mts +14 -0
  79. package/api/theme-edit/_preview-app.mjs +1675 -235
  80. package/api/theme-edit/_preview.d.mts +7 -16
  81. package/api/theme-edit/_preview.mjs +79 -86
  82. package/api/theme-edit/_project.d.mts +32 -2
  83. package/api/theme-edit/_project.mjs +80 -19
  84. package/api/theme-edit/_settings.d.mts +199 -52
  85. package/api/theme-edit/_settings.mjs +1422 -217
  86. package/api/theme-edit/_tables.d.mts +19 -6
  87. package/api/theme-edit/_tables.mjs +150 -92
  88. package/api/theme-edit/theme-edit.type.d.mts +20 -1
  89. package/api/theme-edit/theme-edit.type.mjs +6 -3
  90. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  91. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  92. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  93. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  94. package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
  95. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  96. package/api/theme-edit/themeEditSet.doc.mjs +1 -1
  97. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  98. package/api/upgrade/_adapter.d.mts +1 -0
  99. package/assets/codemods/run-codemod.mjs +61 -0
  100. package/assets/codemods/runner.mjs +5 -4
  101. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  102. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  103. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  104. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  105. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  106. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  107. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  108. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  109. package/assets/docs/tree/calendars.doc.mjs +1 -3
  110. package/assets/docs/tree/checks.doc.mjs +22 -1
  111. package/assets/docs/tree/publishing.doc.mjs +1 -0
  112. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  113. package/assets/docs.generated.json +2 -1
  114. package/assets/preview-app/next.config.mjs +7 -1
  115. package/assets/self-audit.generated.json +1 -0
  116. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  117. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  118. package/assets/templates/components.generated.json +1 -1
  119. package/authoring/integration/integration.doc.mjs +8 -0
  120. package/authoring/integration/schema.d.mts +8 -0
  121. package/authoring/integration/schema.mjs +1 -0
  122. package/authoring/integration/type.ts +9 -0
  123. package/clients/cli/bin/astryx.mjs +19 -15
  124. package/clients/cli/build-id.generated.json +1 -0
  125. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  126. package/clients/cli/commands/experimental/index.mjs +10 -10
  127. package/clients/cli/commands/experimental/theme.mjs +200 -81
  128. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  129. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  130. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
  131. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  132. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  133. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  134. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  135. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  136. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  137. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  138. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  139. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  140. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  141. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  142. package/clients/cli/commands/integration.mjs +8 -0
  143. package/clients/cli/commands/manifest.mjs +5 -2
  144. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  145. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  146. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  147. package/clients/cli/commands/theme.mjs +439 -66
  148. package/clients/cli/index.mjs +27 -6
  149. package/clients/cli/lib/cli-error.mjs +118 -3
  150. package/clients/cli/lib/manifest.mjs +37 -0
  151. package/clients/cli/lib/resolve-theme.mjs +2 -1
  152. package/clients/cli/manifest.generated.json +1 -0
  153. package/foundation/config/project.mjs +34 -8
  154. package/foundation/config/theme-state.d.mts +16 -0
  155. package/foundation/config/theme-state.mjs +84 -13
  156. package/foundation/discovery/module-exports.mjs +16 -2
  157. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  158. package/foundation/discovery/stored-self-audit.mjs +119 -0
  159. package/foundation/discovery/template-adapter.d.mts +48 -2
  160. package/foundation/discovery/template-adapter.mjs +51 -19
  161. package/foundation/discovery/template-needs.d.mts +19 -0
  162. package/foundation/discovery/template-needs.mjs +50 -16
  163. package/foundation/discovery/template-source-tree.d.mts +7 -0
  164. package/foundation/discovery/template-source-tree.mjs +15 -0
  165. package/foundation/discovery/theme-discovery.d.mts +2 -1
  166. package/foundation/discovery/theme-discovery.mjs +16 -10
  167. package/foundation/discovery/theme-imports.d.mts +16 -0
  168. package/foundation/discovery/theme-imports.mjs +30 -2
  169. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  170. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  171. package/foundation/doc-compiler/import.mjs +22 -15
  172. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  173. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  174. package/foundation/env/private-dir.d.mts +17 -0
  175. package/foundation/env/private-dir.mjs +42 -0
  176. package/foundation/fs/gather-cache.d.mts +108 -0
  177. package/foundation/fs/gather-cache.mjs +783 -0
  178. package/foundation/fs/jiti-cache.d.mts +21 -0
  179. package/foundation/fs/jiti-cache.mjs +66 -0
  180. package/foundation/fs/module-loader.mjs +14 -3
  181. package/foundation/fs/read-record.d.mts +31 -1
  182. package/foundation/fs/read-record.mjs +100 -7
  183. package/foundation/integrations/autolink.d.mts +1 -24
  184. package/foundation/integrations/autolink.mjs +7 -60
  185. package/foundation/integrations/declared-dependencies.d.mts +27 -0
  186. package/foundation/integrations/declared-dependencies.mjs +73 -0
  187. package/foundation/integrations/integrations.d.mts +8 -0
  188. package/foundation/integrations/integrations.mjs +4 -0
  189. package/foundation/integrations/may-have-integrations.d.mts +8 -0
  190. package/foundation/integrations/may-have-integrations.mjs +47 -0
  191. package/foundation/integrations/validate-contributions.d.mts +62 -1
  192. package/foundation/integrations/validate-contributions.mjs +476 -40
  193. package/foundation/release/cache.d.mts +32 -4
  194. package/foundation/release/cache.mjs +105 -16
  195. package/foundation/release/folder-lock.d.mts +28 -0
  196. package/foundation/release/folder-lock.mjs +205 -0
  197. package/foundation/release/lock-lease.d.mts +2 -1
  198. package/foundation/release/lock-lease.mjs +7 -2
  199. package/foundation/response/error-codes.doc.mjs +1 -1
  200. package/foundation/response/response-types.doc.mjs +5 -5
  201. package/package.json +8 -6
  202. package/api/theme-edit/_css-properties.d.mts +0 -10
  203. package/api/theme-edit/_css-properties.mjs +0 -556
@@ -73,6 +73,7 @@ import {
73
73
  findCoreDir,
74
74
  findInstalledPackage,
75
75
  findProjectCoreDir,
76
+ findPackageRoot,
76
77
  } from '../../../foundation/fs/paths.mjs';
77
78
  import {isGlobalCopy} from '../../../foundation/release/choose.mjs';
78
79
  import {isInReleaseCache} from '../../../foundation/release/cache.mjs';
@@ -88,6 +89,7 @@ import {AstryxError} from '../../error.mjs';
88
89
  import {applyWrites} from '../../integration/add-helpers.mjs';
89
90
  import {logger} from '../../logger.mjs';
90
91
  import {loadComponentDoc} from '../../../foundation/discovery/component-loader.mjs';
92
+ import {THEME_SOURCE_EXTENSIONS} from '../../../foundation/discovery/theme-module-extensions.mjs';
91
93
  import {
92
94
  collectThemingTargets,
93
95
  targetsByKey,
@@ -98,6 +100,10 @@ import {
98
100
  formatFontLoadingHelp,
99
101
  } from './font-warning.mjs';
100
102
  import {interceptCore} from './core-interception.mjs';
103
+ import {
104
+ installCommandFor,
105
+ parsedSpecifiers,
106
+ } from '../../../foundation/discovery/template-needs.mjs';
101
107
  import {generateFamilyCSS, resolveThemeFamily} from './family.mjs';
102
108
  import {resolveIconImports} from './icon-imports.mjs';
103
109
 
@@ -578,6 +584,83 @@ function resolveToolVersions(cwd) {
578
584
  };
579
585
  }
580
586
 
587
+ /**
588
+ * The command a stale check names, in the words of the group that ran it
589
+ * (`experimental theme compile`); the generated headers keep `theme build`.
590
+ * @param {string} command
591
+ * @param {{group: string, build: string}} [words]
592
+ */
593
+ function rebuildLine(command, words) {
594
+ if (!words || words.group === 'theme') return command;
595
+ return command.replace(/\btheme build\b/, `${words.group} ${words.build}`);
596
+ }
597
+
598
+ /**
599
+ * The folder a build header names paths from: the project root (nearest
600
+ * package.json) of the outputs' folder, or `cwd` outside any project.
601
+ * @param {string} outDir
602
+ * @param {string} cwd
603
+ */
604
+ function headerRoot(outDir, cwd) {
605
+ return findPackageRoot(outDir) ?? path.resolve(cwd);
606
+ }
607
+
608
+ /**
609
+ * Whether a build refuses to replace, at a path `--out` names, the output of
610
+ * another theme source that still exists. False makes it warn and replace.
611
+ */
612
+ const OUT_REFUSES_OTHER_SOURCE = false;
613
+
614
+ /**
615
+ * Where a source name in a build header may point. A header names its source
616
+ * from the outputs' project root; older CLIs named it from the folder the
617
+ * build ran in, which is the output's folder or one above it, up to a
618
+ * monorepo root above the project. The project root comes first, then the
619
+ * output's folder and each folder above it.
620
+ * @param {string} outputFile absolute file the header is in
621
+ * @param {string} name the name the header gives
622
+ * @param {string} cwd
623
+ * @returns {string[]} absolute candidates, without repeats
624
+ */
625
+ function headerSourceCandidates(outputFile, name, cwd) {
626
+ const outDir = path.dirname(path.resolve(outputFile));
627
+ const candidates = [path.resolve(headerRoot(outDir, cwd), name)];
628
+ for (let dir = outDir; ; dir = path.dirname(dir)) {
629
+ candidates.push(path.resolve(dir, name));
630
+ if (path.dirname(dir) === dir) break;
631
+ }
632
+ return [...new Set(candidates)];
633
+ }
634
+
635
+ /**
636
+ * The file a build header's source name points at: the first candidate that
637
+ * exists, or the one from the project root when none does.
638
+ * @param {string} outputFile
639
+ * @param {string} name
640
+ * @param {string} cwd
641
+ */
642
+ function headerSourceFile(outputFile, name, cwd) {
643
+ const candidates = headerSourceCandidates(outputFile, name, cwd);
644
+ return (
645
+ candidates.find(file => {
646
+ try {
647
+ return fs.statSync(file).isFile();
648
+ } catch {
649
+ return false;
650
+ }
651
+ }) ?? candidates[0]
652
+ );
653
+ }
654
+
655
+ /**
656
+ * A path as a build header names it: relative to `base`, with `/`.
657
+ * @param {string} base
658
+ * @param {string} file absolute
659
+ */
660
+ function headerPath(base, file) {
661
+ return path.relative(base, file).split(path.sep).join('/');
662
+ }
663
+
581
664
  /**
582
665
  * Build a @generated attribution header for generated files.
583
666
  * @param {string} sourceFile - Relative path to the source theme file
@@ -610,12 +693,15 @@ function generatedHeader(sourceFile, lang = 'js', command, versions) {
610
693
  * the header and all real content — is compared verbatim. Used only by
611
694
  * `--check`: a differing command must NOT report a file as stale, but any real
612
695
  * content drift must. The `CLI:`/`Core:` provenance lines are deterministic
613
- * for a given toolchain, so they compare verbatim like real content.
696
+ * for a given toolchain, so they compare verbatim like real content. CRLF
697
+ * line endings read as LF.
614
698
  * @param {string} content
615
699
  * @returns {string}
616
700
  */
617
701
  export function normalizeThemeBuildForCompare(content) {
702
+ // A checkout may turn line endings into CRLF; the text is the same.
618
703
  return content
704
+ .replace(/\r\n/g, '\n')
619
705
  .split('\n')
620
706
  .filter(line => {
621
707
  const t = line.replace(/^\s*\*?\s?/, '');
@@ -820,7 +906,12 @@ function themeFilesIn(dir) {
820
906
  try {
821
907
  return fs
822
908
  .readdirSync(dir)
823
- .filter(name => /(?:\.theme|Theme)\.(?:[cm]?[jt]sx?)$/.test(name))
909
+ .filter(
910
+ name =>
911
+ /(?:\.theme|Theme)\.[^.]+$/.test(name) &&
912
+ THEME_SOURCE_EXTENSIONS.includes(path.extname(name)) &&
913
+ !fileHead(path.join(dir, name)).includes(GENERATED_MARKER),
914
+ )
824
915
  .sort()
825
916
  .slice(0, 3);
826
917
  } catch {
@@ -828,12 +919,153 @@ function themeFilesIn(dir) {
828
919
  }
829
920
  }
830
921
 
922
+ /**
923
+ * The files a theme source is made of: the source and every local file it
924
+ * imports, directly or through other local files, read from their import
925
+ * statements. A watch rebuilds when any of them changes. Package imports and
926
+ * files that cannot be read are left out.
927
+ * @param {string} filePath absolute theme source
928
+ * @returns {string[]} absolute paths, the source first
929
+ */
930
+ export function themeSourceFiles(filePath) {
931
+ const seen = new Set([path.resolve(filePath)]);
932
+ const queue = [path.resolve(filePath)];
933
+ while (queue.length > 0 && seen.size < 500) {
934
+ const file = /** @type {string} */ (queue.shift());
935
+ let source;
936
+ try {
937
+ source = fs.readFileSync(file, 'utf8');
938
+ } catch {
939
+ continue;
940
+ }
941
+ for (const spec of parsedSpecifiers(source)) {
942
+ // Only relative and absolute imports are the theme's own files. A bare
943
+ // specifier names a package, which a workspace link can resolve to a
944
+ // real path outside node_modules.
945
+ if (!spec.startsWith('.') && !path.isAbsolute(spec)) continue;
946
+ // Resolved as the build resolves it.
947
+ let target;
948
+ try {
949
+ target = path.resolve(resolveThemeModule(spec, file));
950
+ } catch {
951
+ continue;
952
+ }
953
+ if (
954
+ target.split(path.sep).includes('node_modules') ||
955
+ seen.has(target) ||
956
+ !fs.existsSync(target)
957
+ )
958
+ continue;
959
+ seen.add(target);
960
+ queue.push(target);
961
+ }
962
+ }
963
+ return [...seen];
964
+ }
965
+
966
+ /**
967
+ * Theme sources a missing build input probably meant, relative to `cwd`: the
968
+ * same path with `/` for `\`; or, for a bare theme name, the theme sources in
969
+ * `themes/<name>/` and `src/themes/<name>/` of the project, and `<name>` with a
970
+ * theme source extension. A build output is never offered.
971
+ * @param {string} file the input as given
972
+ * @param {string} cwd
973
+ * @returns {string[]} at most three paths
974
+ */
975
+ export function themeSourceGuesses(file, cwd) {
976
+ const shown = (/** @type {string} */ absolute) =>
977
+ path.relative(cwd, absolute).split(path.sep).join('/');
978
+ const isSource = (/** @type {string} */ absolute) =>
979
+ fs.existsSync(absolute) &&
980
+ !fs.statSync(absolute).isDirectory() &&
981
+ !fileHead(absolute).includes(GENERATED_MARKER);
982
+ if (file.includes('\\')) {
983
+ const forward = path.resolve(cwd, file.replace(/\\/g, '/'));
984
+ return isSource(forward) ? [shown(forward)] : [];
985
+ }
986
+ if (/[/.]/.test(file)) return [];
987
+ const root = findPackageRoot(cwd) ?? cwd;
988
+ const guesses = [
989
+ path.join(root, 'themes', file),
990
+ path.join(root, 'src', 'themes', file),
991
+ ].flatMap(folder =>
992
+ themeFilesIn(folder).map(name => shown(path.join(folder, name))),
993
+ );
994
+ for (const extension of THEME_SOURCE_EXTENSIONS) {
995
+ const candidate = path.resolve(cwd, file + extension);
996
+ if (isSource(candidate)) guesses.push(shown(candidate));
997
+ }
998
+ return guesses.slice(0, 3);
999
+ }
1000
+
1001
+ /**
1002
+ * Refuse a file that is not a theme source before loading it: an output of a
1003
+ * build (it carries the `@generated` header, whatever its extension, and
1004
+ * names the source it was built from), or a file whose extension no theme
1005
+ * source has, such as `.css` or `.json` (THEME_SOURCE_EXTENSIONS).
1006
+ * @param {string} filePath
1007
+ * @param {string} cwd
1008
+ */
1009
+ function assertThemeSourceFile(filePath, cwd) {
1010
+ const rel = (/** @type {string} */ file) => path.relative(cwd, file);
1011
+ const sourceHead = fileHead(filePath);
1012
+ if (sourceHead.includes(GENERATED_MARKER)) {
1013
+ const line = /Source: (.+)/.exec(sourceHead)?.[1]?.trim();
1014
+ // The header names its sources from the outputs' project root; the
1015
+ // command to build them names them from the working folder.
1016
+ const sources = line
1017
+ ? line.split(', ').map(name =>
1018
+ rel(headerSourceFile(filePath, name.trim(), cwd))
1019
+ .split(path.sep)
1020
+ .join('/'),
1021
+ )
1022
+ : [];
1023
+ const familyKey = /Command: .*--family-key (\S+)/.exec(sourceHead)?.[1];
1024
+ const build =
1025
+ sources.length > 1 && familyKey
1026
+ ? `theme build --family ${sources.map(shellWord).join(' ')} --family-key ${shellWord(familyKey)}`
1027
+ : sources.length > 0
1028
+ ? `theme build ${shellWord(sources[0])}`
1029
+ : null;
1030
+ throw new AstryxError(
1031
+ `${rel(filePath)} is an output of \`theme build\`, not a theme source.${sources.length > 0 ? ` It was built from ${sources.join(', ')}.` : ''}`,
1032
+ build
1033
+ ? [
1034
+ {
1035
+ name: formatCliCommand(build, cwd),
1036
+ reason: 'build the theme source',
1037
+ },
1038
+ ]
1039
+ : undefined,
1040
+ ERROR_CODES.ERR_THEME_INVALID,
1041
+ );
1042
+ }
1043
+ if (!THEME_SOURCE_EXTENSIONS.includes(path.extname(filePath).toLowerCase())) {
1044
+ throw new AstryxError(
1045
+ `${rel(filePath)} is not a theme module. A theme source is a ${THEME_SOURCE_EXTENSIONS.join(', ')} file that exports defineTheme(...).`,
1046
+ themeFilesIn(path.dirname(filePath)).map(name => ({
1047
+ name: formatCliCommand(
1048
+ `theme build ${shellWord(
1049
+ rel(path.join(path.dirname(filePath), name))
1050
+ .split(path.sep)
1051
+ .join('/'),
1052
+ )}`,
1053
+ cwd,
1054
+ ),
1055
+ reason: 'a theme source in that folder',
1056
+ })),
1057
+ ERROR_CODES.ERR_THEME_LOAD,
1058
+ );
1059
+ }
1060
+ }
1061
+
831
1062
  /**
832
1063
  * Refuse a build that would replace a file it does not own. A build never
833
1064
  * writes over its input, two of its own outputs at one path, or an output
834
- * another theme in the same run already wrote. With `refuseUnmarked`, it also
835
- * replaces only its own earlier outputs (they carry the `@generated` header)
836
- * and empty files, never another file such as `package.json` or app source.
1065
+ * another theme in the same run already wrote. With `refuseUnmarked` (a path
1066
+ * --out names), it also replaces only its own earlier outputs (their header
1067
+ * names this source, or a source that is gone) and empty files, never another
1068
+ * source's output or another file such as `package.json` or app source.
837
1069
  * @param {Array<{dest: string}>} writes
838
1070
  * @param {string} filePath the theme source
839
1071
  * @param {string} cwd
@@ -850,23 +1082,8 @@ function assertOutputsReplaceable(
850
1082
  ) {
851
1083
  const rel = (/** @type {string} */ file) => path.relative(cwd, file);
852
1084
  const sourceKey = outputKey(filePath);
853
- const sourceHead = fileHead(filePath);
854
- if (sourceHead.includes(GENERATED_MARKER)) {
855
- const from = /Source: (.+)/.exec(sourceHead)?.[1]?.trim();
856
- throw new AstryxError(
857
- `${rel(filePath)} is an output of \`theme build\`, not a theme source.${from ? ` It was built from ${from}.` : ''}`,
858
- from
859
- ? [
860
- {
861
- name: formatCliCommand(`theme build ${shellWord(from)}`, cwd),
862
- reason: 'build the theme source',
863
- },
864
- ]
865
- : undefined,
866
- ERROR_CODES.ERR_THEME_INVALID,
867
- );
868
- }
869
1085
  const seen = new Set();
1086
+ let warnedOtherSource = false;
870
1087
  for (const write of writes) {
871
1088
  const key = outputKey(write.dest);
872
1089
  if (key === sourceKey) {
@@ -894,11 +1111,13 @@ function assertOutputsReplaceable(
894
1111
  seen.add(key);
895
1112
  const earlier = claimed?.get(key);
896
1113
  if (earlier !== undefined) {
897
- throw new AstryxError(
898
- `${earlier} already wrote ${rel(write.dest)} in this run. Two themes build the same outputs; give each theme its own name.`,
1114
+ const collision = new AstryxError(
1115
+ `${earlier} and ${rel(filePath)} both build ${rel(write.dest)}. Give each theme its own name; nothing was written.`,
899
1116
  undefined,
900
1117
  ERROR_CODES.ERR_THEME_INVALID,
901
1118
  );
1119
+ /** @type {any} */ (collision).outputCollision = true;
1120
+ throw collision;
902
1121
  }
903
1122
  let stat;
904
1123
  try {
@@ -913,6 +1132,33 @@ function assertOutputsReplaceable(
913
1132
  ERROR_CODES.ERR_INVALID_ARGUMENT,
914
1133
  );
915
1134
  }
1135
+ // Only a path --out names is checked: at the default paths beside the
1136
+ // source, a build replaces what is there, as it always has.
1137
+ const otherSource = refuseUnmarked
1138
+ ? builtFromOtherSource(write.dest, filePath, cwd)
1139
+ : null;
1140
+ if (otherSource && !OUT_REFUSES_OTHER_SOURCE) {
1141
+ // One warning per build: every output of that source goes together.
1142
+ if (warnedOtherSource) continue;
1143
+ warnedOtherSource = true;
1144
+ logger.warn(
1145
+ `Warning: ${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`,
1146
+ );
1147
+ } else if (otherSource) {
1148
+ throw new AstryxError(
1149
+ `${rel(write.dest)} is the build output of another theme source, ${otherSource}, so this build does not replace it. Pick another ${elsewhere}.`,
1150
+ [
1151
+ {
1152
+ name: formatCliCommand(
1153
+ `theme build ${shellWord(rel(filePath))}`,
1154
+ cwd,
1155
+ ),
1156
+ reason: 'write the outputs beside this source',
1157
+ },
1158
+ ],
1159
+ ERROR_CODES.ERR_FILE_EXISTS,
1160
+ );
1161
+ }
916
1162
  // Outputs from CLIs before 0.6.7 have no header, so they read as files
917
1163
  // the build did not write; only the user can say they may go.
918
1164
  if (
@@ -936,6 +1182,46 @@ function assertOutputsReplaceable(
936
1182
  }
937
1183
  }
938
1184
 
1185
+ /**
1186
+ * The other theme source a build output names in its `Source:` header, when
1187
+ * that source still exists and is not `source`. The name is resolved as
1188
+ * headerSourceCandidates says; a match is exact. A family output names
1189
+ * every member, and is this source's when any of them is. Null when the output is this source's,
1190
+ * names no source, or names one that is gone (an orphan a build may replace).
1191
+ * @param {string} dest
1192
+ * @param {string} source absolute theme source
1193
+ * @param {string} cwd
1194
+ * @returns {string | null}
1195
+ */
1196
+ function builtFromOtherSource(dest, source, cwd) {
1197
+ const head = fileHead(dest);
1198
+ if (!head.includes(GENERATED_MARKER)) return null;
1199
+ const line = /Source: (.+)/.exec(head)?.[1]?.trim();
1200
+ if (!line) return null;
1201
+ const names = line.split(', ').map(name => name.trim());
1202
+ const own = path.resolve(source);
1203
+ const candidates = names.flatMap(name =>
1204
+ headerSourceCandidates(dest, name, cwd),
1205
+ );
1206
+ if (candidates.includes(own)) return null;
1207
+ const existing = candidates.find(file => {
1208
+ try {
1209
+ return fs.statSync(file).isFile();
1210
+ } catch {
1211
+ return false;
1212
+ }
1213
+ });
1214
+ return existing ? path.relative(cwd, existing) || existing : null;
1215
+ }
1216
+
1217
+ /**
1218
+ * Publish the outputs a batch deferred, one theme at a time, in build order.
1219
+ * @param {Array<Array<{dest: string, content: string}>>} deferred
1220
+ */
1221
+ export function writeDeferredBuildOutputs(deferred) {
1222
+ for (const writes of deferred.splice(0)) writeBuildOutputs(writes);
1223
+ }
1224
+
939
1225
  /** @param {Array<{dest: string, content: string}>} writes */
940
1226
  function writeBuildOutputs(writes) {
941
1227
  if (writes.length === 0) return;
@@ -1972,17 +2258,24 @@ const THEME_SCOPE_TO = `[data-astryx-theme]`;
1972
2258
  * the author's TypeScript sees, which is the point: the CSS the build emits
1973
2259
  * matches the theme they type-checked.
1974
2260
  */
2261
+ // Every theme source extension is in this list: jiti hands a file whose
2262
+ // extension it does not list to Node's own loader, which cannot load `.jsx`
2263
+ // or, on some Node versions, TypeScript.
1975
2264
  const THEME_MODULE_EXTENSIONS = [
1976
- '.ts',
1977
- '.tsx',
1978
- '.mts',
1979
- '.cts',
1980
- '.mtsx',
1981
- '.ctsx',
1982
- '.mjs',
1983
- '.cjs',
1984
- '.js',
1985
- '.json',
2265
+ ...new Set([
2266
+ '.ts',
2267
+ '.tsx',
2268
+ '.mts',
2269
+ '.cts',
2270
+ '.mtsx',
2271
+ '.ctsx',
2272
+ '.mjs',
2273
+ '.cjs',
2274
+ '.js',
2275
+ '.jsx',
2276
+ '.json',
2277
+ ...THEME_SOURCE_EXTENSIONS,
2278
+ ]),
1986
2279
  ];
1987
2280
  // prettier-ignore
1988
2281
  const registryGraphError = (/** @type {string} */ message) => new AstryxError(message, undefined, ERROR_CODES.ERR_THEME_INVALID);
@@ -2328,12 +2621,10 @@ function themeLoadReason(error) {
2328
2621
  ) {
2329
2622
  return `its default export is null or not an object.\n${THEME_EXPORT_FIX}`;
2330
2623
  }
2331
- const missing =
2332
- /Cannot find (?:module|package) '((?:@[^/']+\/)?[^/'.][^/']*)/.exec(
2333
- message,
2334
- )?.[1];
2624
+ const missing = missingThemePackage(error);
2335
2625
  if (missing) {
2336
- return `${message}\nThe theme imports ${missing}, which is not installed. Install it (for example \`npm install ${missing}\`), then build again.`;
2626
+ // Node's "Require stack" names absolute paths; the package is the fact.
2627
+ return `Cannot find module '${missing}'.\nThe theme imports ${missing}, which is not installed. Install it, then build again.`;
2337
2628
  }
2338
2629
  return `${message}\nMake sure all imports in the theme file are resolvable.`;
2339
2630
  }
@@ -2341,6 +2632,62 @@ function themeLoadReason(error) {
2341
2632
  /** A theme module that loaded but exports no theme object. */
2342
2633
  class ThemeShapeError extends Error {}
2343
2634
 
2635
+ /**
2636
+ * The command that moves a failed theme load forward: the install for a
2637
+ * package the theme imports and the app lacks, the same build for a file that
2638
+ * changed while it loaded, else the annotated template, which shows a theme
2639
+ * source that loads.
2640
+ * @param {Error} error
2641
+ * @param {string} shown the theme file as the message names it
2642
+ * @param {string} cwd
2643
+ * @returns {import('../../../foundation/response/base').Suggestion[]}
2644
+ */
2645
+ function themeLoadSuggestions(error, shown, cwd) {
2646
+ const missing = missingThemePackage(error.cause ?? error);
2647
+ if (missing) {
2648
+ const {installCommand} = installCommandFor(
2649
+ [missing],
2650
+ findPackageRoot(cwd) ?? cwd,
2651
+ );
2652
+ if (installCommand) {
2653
+ return [
2654
+ {
2655
+ name: installCommand,
2656
+ reason: `install ${missing}, which the theme imports`,
2657
+ },
2658
+ ];
2659
+ }
2660
+ }
2661
+ if (/changed while it was loading/.test(error.message)) {
2662
+ return [
2663
+ {
2664
+ name: formatCliCommand(`theme build ${shellWord(shown)}`, cwd),
2665
+ reason: 'build again once the file is saved',
2666
+ },
2667
+ ];
2668
+ }
2669
+ return [
2670
+ {
2671
+ name: formatCliCommand('theme template theme.template.ts', cwd),
2672
+ reason: 'an annotated theme source that loads, to compare with',
2673
+ },
2674
+ ];
2675
+ }
2676
+
2677
+ /**
2678
+ * The package a theme load failed on because it is not installed.
2679
+ * @param {unknown} error
2680
+ * @returns {string | null}
2681
+ */
2682
+ export function missingThemePackage(error) {
2683
+ const message = error instanceof Error ? error.message : String(error);
2684
+ return (
2685
+ /Cannot find (?:module|package) '((?:@[^/']+\/)?[^/'.][^/']*)/.exec(
2686
+ message,
2687
+ )?.[1] ?? null
2688
+ );
2689
+ }
2690
+
2344
2691
  /**
2345
2692
  * Load one theme through the build's real module loader and validate the raw
2346
2693
  * input captured from its defineTheme lineage. Used by doctor so it applies the
@@ -2581,7 +2928,7 @@ function importStatement({importPath, importedName, localName}, specifier) {
2581
2928
  * @param {any} themeDef
2582
2929
  * @param {import('./icon-imports.mjs').IconImports | null} iconInfo
2583
2930
  * @param {string} [iconsSpecifier] - Overrides the selected registry specifier.
2584
- * @param {{themeBinding?: string, iconsExpression?: string, indicatorsExpression?: string, artifactBaseName?: string, exportIcons?: boolean, componentIconInfo?: {imports: import('./icon-imports.mjs').IconImports['imports'], expression: string, mergeName?: string} | null}} [moduleOptions]
2931
+ * @param {{themeBinding?: string, iconsExpression?: string, indicatorsExpression?: string, artifactBaseName?: string, cssFileName?: string, exportIcons?: boolean, componentIconInfo?: {imports: import('./icon-imports.mjs').IconImports['imports'], expression: string, mergeName?: string} | null}} [moduleOptions]
2585
2932
  * @returns {string}
2586
2933
  */
2587
2934
  function generateBuiltModule(
@@ -2593,6 +2940,7 @@ function generateBuiltModule(
2593
2940
  const themeBinding =
2594
2941
  moduleOptions.themeBinding ?? `${toIdentifier(themeDef.name)}Theme`;
2595
2942
  const artifactBaseName = moduleOptions.artifactBaseName ?? themeDef.name;
2943
+ const cssFileName = moduleOptions.cssFileName ?? `${artifactBaseName}.css`;
2596
2944
  const exportIcons = moduleOptions.exportIcons ?? true;
2597
2945
  const iconImport = (iconInfo?.imports ?? [])
2598
2946
  .map(binding =>
@@ -2743,7 +3091,7 @@ function generateBuiltModule(
2743
3091
  * Import the CSS file alongside this module:
2744
3092
  *
2745
3093
  * import { ${themeBinding} } from './${artifactBaseName}';
2746
- * import './${artifactBaseName}.css';
3094
+ * import './${cssFileName}';
2747
3095
  */
2748
3096
  export const ${themeBinding} = {
2749
3097
  name: '${themeDef.name}',
@@ -3156,10 +3504,12 @@ function validateHeadingTypeAugmentationSupport(themeDef) {
3156
3504
  * `logger` (silent by default).
3157
3505
  *
3158
3506
  * @param {string} file - Theme file path, resolved against `cwd`.
3159
- * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void, __writeRoot?: string, __claimedOutputs?: Map<string, string>}} [options] -
3507
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void, __writeRoot?: string, __claimedOutputs?: Map<string, string>, __deferredWrites?: Array<Array<{dest: string, content: string}>>, __commandWords?: {group: string, build: string}}} [options] -
3160
3508
  * `out` overrides the output CSS path, or names the folder for it; `check` compares against on-disk outputs
3161
3509
  * instead of writing. `__claimedOutputs` records the outputs earlier builds
3162
- * in one run wrote, so a later theme cannot replace them. `__writeRoot` replaces `cwd` as the directory every
3510
+ * in one run wrote, so a later theme cannot replace them; with
3511
+ * `__deferredWrites` the build adds its outputs to that list instead of
3512
+ * writing them, for writeDeferredBuildOutputs. `__writeRoot` replaces `cwd` as the directory every
3163
3513
  * output must stay inside, for a CLI-internal scratch build. `iconsSpecifier` overrides the icon registry import
3164
3514
  * specifier in the generated module (e.g. `./icons.mjs`); when omitted, the
3165
3515
  * direct registry specifiers from the theme source are emitted unchanged.
@@ -3178,7 +3528,10 @@ async function themeBuildInternal(
3178
3528
  if (!fs.existsSync(filePath)) {
3179
3529
  throw new AstryxError(
3180
3530
  `File not found: ${filePath}`,
3181
- undefined,
3531
+ themeSourceGuesses(file, cwd).map(guess => ({
3532
+ name: formatCliCommand(`theme build ${shellWord(guess)}`, cwd),
3533
+ reason: 'a theme source that exists',
3534
+ })),
3182
3535
  ERROR_CODES.ERR_FILE_NOT_FOUND,
3183
3536
  );
3184
3537
  }
@@ -3197,6 +3550,8 @@ async function themeBuildInternal(
3197
3550
  );
3198
3551
  }
3199
3552
 
3553
+ assertThemeSourceFile(filePath, cwd);
3554
+
3200
3555
  if (!report.compact) {
3201
3556
  logger.log(`\nBuilding theme from ${path.relative(cwd, filePath)}...`);
3202
3557
  }
@@ -3258,7 +3613,12 @@ async function themeBuildInternal(
3258
3613
  loadDegradation = loaded.degraded;
3259
3614
  } catch (e) {
3260
3615
  const err = /** @type {Error} */ (e);
3261
- throw new AstryxError(err.message, undefined, ERROR_CODES.ERR_THEME_LOAD);
3616
+ const shown = path.relative(cwd, filePath) || filePath;
3617
+ throw new AstryxError(
3618
+ err.message.split(filePath).join(shown),
3619
+ themeLoadSuggestions(err, shown, cwd),
3620
+ ERROR_CODES.ERR_THEME_LOAD,
3621
+ );
3262
3622
  }
3263
3623
 
3264
3624
  // The marker is scoped to that isolated load: drop it before the theme
@@ -3288,9 +3648,15 @@ async function themeBuildInternal(
3288
3648
  interception && hasCoverageGap ? interception.unobservedIn(themeDef) : [];
3289
3649
  if (interception) interception.strip(themeDef);
3290
3650
  if (!ancestryObserved) {
3651
+ const shown = path.relative(cwd, filePath);
3291
3652
  throw new AstryxError(
3292
- `Theme "${themeDef.name ?? path.basename(filePath)}" exact family ancestry could not be observed during CLI loading.`,
3293
- undefined,
3653
+ `Theme "${themeDef.name ?? path.basename(filePath)}" in ${shown} is a plain object, so a family build cannot see which theme it extends. A family member is made with defineTheme(...) from @astryxdesign/core/theme; build a plain-object theme on its own.`,
3654
+ [
3655
+ {
3656
+ name: formatCliCommand(`theme build ${shellWord(shown)}`, cwd),
3657
+ reason: 'build this theme on its own',
3658
+ },
3659
+ ],
3294
3660
  ERROR_CODES.ERR_THEME_INVALID,
3295
3661
  );
3296
3662
  }
@@ -3700,7 +4066,8 @@ async function themeBuildInternal(
3700
4066
 
3701
4067
  // Source path relative to cwd — used in @generated headers
3702
4068
  const sourceRelative = path.relative(cwd, filePath);
3703
- const buildCommand = `astryx theme build ${sourceRelative}${options.out ? ' --out ' + path.relative(cwd, path.resolve(cwd, options.out)) : ''}`;
4069
+ // What `--check` prints to rebuild, from the working folder.
4070
+ const rebuildCommand = `astryx theme build ${sourceRelative}${options.out ? ' --out ' + path.relative(cwd, path.resolve(cwd, options.out)) : ''}`;
3704
4071
  // Stable provenance recorded in @generated headers — versions, not a
3705
4072
  // timestamp, so identical inputs produce byte-identical output.
3706
4073
  const versions = resolveToolVersions(cwd);
@@ -3719,6 +4086,18 @@ async function themeBuildInternal(
3719
4086
  if (/[\\/]$/.test(options.out) || isDirectorySync(outPath)) {
3720
4087
  outPath = path.join(outPath, `${baseName}.css`);
3721
4088
  }
4089
+ // The stylesheet is CSS whatever its name; a name that does not end in
4090
+ // .css still builds, and the module's import names the file as written.
4091
+ if (path.extname(outPath).toLowerCase() !== '.css') {
4092
+ const stem = path.basename(outPath).replace(/(?:\.d)?\.[^.]+$/, '');
4093
+ const fixed = path
4094
+ .join(path.dirname(options.out), `${stem}.css`)
4095
+ .split(path.sep)
4096
+ .join('/');
4097
+ logger.warn(
4098
+ `Warning: --out names the stylesheet, which is CSS; give it a .css name such as ${fixed}.`,
4099
+ );
4100
+ }
3722
4101
  // A build keeps the explicit output inside the write root, relative or
3723
4102
  // absolute. Check mode writes nothing, so it refuses only a relative path
3724
4103
  // that escapes cwd.
@@ -3728,6 +4107,12 @@ async function themeBuildInternal(
3728
4107
  } else {
3729
4108
  outPath = path.join(path.dirname(filePath), `${baseName}.css`);
3730
4109
  }
4110
+ // The header names the source and command from the project root of the
4111
+ // outputs, so a build from any folder writes the same bytes, `--check`
4112
+ // agrees with it, and a later build reads the source back exactly.
4113
+ const headerBase = headerRoot(path.dirname(outPath), cwd);
4114
+ const headerSource = headerPath(headerBase, filePath);
4115
+ const buildCommand = `astryx theme build ${headerSource}${options.out ? ' --out ' + headerPath(headerBase, outPath) : ''}`;
3731
4116
 
3732
4117
  const displayTheme = resolvedTheme || themeDef;
3733
4118
  const tokenCount =
@@ -3759,31 +4144,38 @@ async function themeBuildInternal(
3759
4144
  ? path.join(outDir, variantsFileName)
3760
4145
  : null;
3761
4146
  const variantContent = variantDecl
3762
- ? generatedHeader(sourceRelative, 'ts', buildCommand, versions) +
3763
- variantDecl
4147
+ ? generatedHeader(headerSource, 'ts', buildCommand, versions) + variantDecl
3764
4148
  : null;
3765
4149
 
3766
4150
  // Generate all file contents in memory first. The main .d.ts references
3767
4151
  // the variants file (when present) via a triple-slash directive so
3768
4152
  // importing the theme also loads the custom-variant augmentations.
3769
4153
  const cssContent =
3770
- generatedHeader(sourceRelative, 'css', buildCommand, versions) + css;
4154
+ generatedHeader(headerSource, 'css', buildCommand, versions) + css;
3771
4155
  const cssDtsContent =
3772
- generatedHeader(sourceRelative, 'ts', buildCommand, versions) +
4156
+ generatedHeader(headerSource, 'ts', buildCommand, versions) +
3773
4157
  'export {};\n';
3774
4158
  // A family member's module is generated by themeBuildFamily, which carries
3775
4159
  // its registries and slot functions through the family's own imports.
3776
4160
  const jsContent = options.__prepareFamily
3777
4161
  ? ''
3778
- : generatedHeader(sourceRelative, 'js', buildCommand, versions) +
4162
+ : generatedHeader(headerSource, 'js', buildCommand, versions) +
3779
4163
  generateBuiltModule(
3780
4164
  resolvedTheme || themeDef,
3781
4165
  iconInfo,
3782
4166
  options.iconsSpecifier,
3783
- {componentIconInfo},
4167
+ {
4168
+ componentIconInfo,
4169
+ // A stylesheet named other than `.css` is named as written. A
4170
+ // `.css` name keeps the theme's own name in the module, so the
4171
+ // module is the same whatever `--out` names the stylesheet.
4172
+ ...(path.extname(outPath).toLowerCase() === '.css'
4173
+ ? {}
4174
+ : {cssFileName: path.basename(outPath)}),
4175
+ },
3784
4176
  );
3785
4177
  const dtsContent =
3786
- generatedHeader(sourceRelative, 'ts', buildCommand, versions) +
4178
+ generatedHeader(headerSource, 'ts', buildCommand, versions) +
3787
4179
  generateBuiltTypes(resolvedTheme || themeDef, iconInfo, variantsFileName);
3788
4180
 
3789
4181
  const unloadedFonts = [
@@ -3849,12 +4241,15 @@ async function themeBuildInternal(
3849
4241
  if (options.check) {
3850
4242
  const stale = staleBuildOutputs(writes, cwd);
3851
4243
  const upToDate = stale.length === 0;
4244
+ const checkedLine = ` checked: ${checkedBuildOutputs(writes, cwd).join(', ')}`;
3852
4245
  if (upToDate) {
3853
4246
  logger.log(`\n[ok] Theme outputs are up to date with ${sourceRelative}.`);
4247
+ logger.log(checkedLine);
3854
4248
  } else {
3855
4249
  logger.error(
3856
4250
  `\n[fail] ${stale.length} theme output(s) are out of date with ${sourceRelative}:`,
3857
4251
  );
4252
+ logger.error(checkedLine);
3858
4253
  for (const s of stale) {
3859
4254
  logger.error(
3860
4255
  ` ${s.reason === 'missing' ? 'missing' : 'stale'}: ${s.path}`,
@@ -3863,7 +4258,10 @@ async function themeBuildInternal(
3863
4258
  // prettier-ignore
3864
4259
  const remedy = outsideCheckRemedy(writes, [filePath], writeRoot, relative => [relative(filePath), ...(options.out ? ['--out', relative(outPath)] : []), ...(options.iconsSpecifier ? ['--icons-specifier', options.iconsSpecifier] : [])]);
3865
4260
  if (remedy) logger.error(`\n ${remedy.join('\n ')}`);
3866
- else logger.error(`\n Rebuild with: ${buildCommand}`);
4261
+ else
4262
+ logger.error(
4263
+ `\n Rebuild with: ${rebuildLine(rebuildCommand, options.__commandWords)}`,
4264
+ );
3867
4265
  }
3868
4266
  return {
3869
4267
  type: 'theme.build.check',
@@ -3876,7 +4274,10 @@ async function themeBuildInternal(
3876
4274
  };
3877
4275
  }
3878
4276
 
3879
- writeBuildOutputs(writes);
4277
+ // A batch publishes every theme's outputs after all of them are built, so
4278
+ // two themes that build the same files are refused before either writes.
4279
+ if (options.__deferredWrites) options.__deferredWrites.push(writes);
4280
+ else writeBuildOutputs(writes);
3880
4281
  for (const write of writes) {
3881
4282
  options.__claimedOutputs?.set(outputKey(write.dest), sourceRelative);
3882
4283
  }
@@ -3899,9 +4300,8 @@ async function themeBuildInternal(
3899
4300
  }
3900
4301
 
3901
4302
  const relOutDir = path.relative(cwd, outDir) || '.';
3902
- const cssBase = path.basename(outPath, '.css');
3903
4303
  const jsImport = importSpecifier(relOutDir, baseName);
3904
- const cssImport = importSpecifier(relOutDir, cssBase) + '.css';
4304
+ const cssImport = importSpecifier(relOutDir, path.basename(outPath));
3905
4305
  const exportName = `${toIdentifier(baseName)}Theme`;
3906
4306
 
3907
4307
  // Fonts the theme names but nothing loads (#5015). Resolved tokens and
@@ -4260,7 +4660,7 @@ async function preloadFamilySource(filePath, loader, interception) {
4260
4660
  finally { patch.undo(); }
4261
4661
  }
4262
4662
 
4263
- /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void}} options @param {{cwd?: string}} [ctx] */
4663
+ /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
4264
4664
  export async function themeBuildFamily(
4265
4665
  files,
4266
4666
  options,
@@ -4380,9 +4780,15 @@ export async function themeBuildFamily(
4380
4780
  const sourceRelative = members
4381
4781
  .map(member => member.sourceRelative)
4382
4782
  .join(', ');
4383
- const buildCommand = `${getCliInvocation()} theme build --family ${members
4783
+ const rebuildCommand = `${getCliInvocation()} theme build --family ${members
4384
4784
  .map(member => member.sourceRelative)
4385
4785
  .join(' ')} --family-key ${baseName}`;
4786
+ const headerBase = headerRoot(outDir, cwd);
4787
+ const headerSources = members.map(member =>
4788
+ headerPath(headerBase, member.filePath),
4789
+ );
4790
+ const headerSource = headerSources.join(', ');
4791
+ const buildCommand = `astryx theme build --family ${headerSources.join(' ')} --family-key ${baseName}`;
4386
4792
  const bindings = allocateFamilyBindings(members);
4387
4793
  const css = generateFamilyCSS(members);
4388
4794
  /** @type {Array<{specifier: string, exportName: string}>} */
@@ -4461,25 +4867,24 @@ export async function themeBuildFamily(
4461
4867
  {
4462
4868
  dest: outPath,
4463
4869
  content:
4464
- generatedHeader(sourceRelative, 'css', buildCommand, root.versions) +
4465
- css,
4870
+ generatedHeader(headerSource, 'css', buildCommand, root.versions) + css,
4466
4871
  },
4467
4872
  {
4468
4873
  dest: cssDtsPath,
4469
4874
  allowMissingInCheck: true,
4470
4875
  content:
4471
- generatedHeader(sourceRelative, 'ts', buildCommand, root.versions) +
4876
+ generatedHeader(headerSource, 'ts', buildCommand, root.versions) +
4472
4877
  'export {};\n',
4473
4878
  },
4474
4879
  {
4475
4880
  dest: jsPath,
4476
4881
  content:
4477
- generatedHeader(sourceRelative, 'js', buildCommand, root.versions) + js,
4882
+ generatedHeader(headerSource, 'js', buildCommand, root.versions) + js,
4478
4883
  },
4479
4884
  {
4480
4885
  dest: dtsPath,
4481
4886
  content:
4482
- generatedHeader(sourceRelative, 'ts', buildCommand, root.versions) +
4887
+ generatedHeader(headerSource, 'ts', buildCommand, root.versions) +
4483
4888
  declarations +
4484
4889
  (augmentations ? `\n${augmentations}` : ''),
4485
4890
  },
@@ -4502,14 +4907,17 @@ export async function themeBuildFamily(
4502
4907
  if (options.check) {
4503
4908
  const stale = staleBuildOutputs(writes, cwd);
4504
4909
  const upToDate = stale.length === 0;
4910
+ const checkedLine = ` checked: ${checkedBuildOutputs(writes, cwd).join(', ')}`;
4505
4911
  if (upToDate) {
4506
4912
  logger.log(
4507
4913
  `\n[ok] Theme family outputs are up to date with ${sourceRelative}.`,
4508
4914
  );
4915
+ logger.log(checkedLine);
4509
4916
  } else {
4510
4917
  logger.error(
4511
4918
  `\n[fail] ${stale.length} theme family output(s) are out of date:`,
4512
4919
  );
4920
+ logger.error(checkedLine);
4513
4921
  for (const entry of stale) {
4514
4922
  logger.error(
4515
4923
  ` ${entry.reason === 'missing' ? 'missing' : 'stale'}: ${entry.path}`,
@@ -4518,7 +4926,10 @@ export async function themeBuildFamily(
4518
4926
  // prettier-ignore
4519
4927
  const remedy = outsideCheckRemedy(writes, members.map(member => member.filePath), cwd, relative => ['--family', ...members.map(member => relative(member.filePath)), '--family-key', baseName, ...(options.iconsSpecifier ? ['--icons-specifier', options.iconsSpecifier] : [])]);
4520
4928
  if (remedy) logger.error(`\n ${remedy.join('\n ')}`);
4521
- else logger.error(`\n Rebuild with: ${buildCommand}`);
4929
+ else
4930
+ logger.error(
4931
+ `\n Rebuild with: ${rebuildLine(rebuildCommand, options.__commandWords)}`,
4932
+ );
4522
4933
  }
4523
4934
  return {
4524
4935
  type: 'theme.build.check',