@astryxdesign/cli 0.7.15 → 0.7.16-canary.g54dd64e

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 (123) hide show
  1. package/README.md +5 -3
  2. package/api/component/_adapter.d.mts +1 -1
  3. package/api/component/_adapter.mjs +28 -1
  4. package/api/doctor/_adapter.d.mts +17 -0
  5. package/api/doctor/_adapter.mjs +35 -0
  6. package/api/doctor/doctor.mjs +18 -4
  7. package/api/integration/pack-check.mjs +13 -7
  8. package/api/integration/validate-integration.mjs +1 -1
  9. package/api/theme/_adapter.d.mts +5 -2
  10. package/api/theme/_adapter.mjs +43 -12
  11. package/api/theme/build/build.d.mts +64 -27
  12. package/api/theme/build/build.mjs +341 -69
  13. package/api/theme/eject/eject.mjs +22 -1
  14. package/api/theme/template/template.d.mts +19 -0
  15. package/api/theme/template/template.mjs +102 -25
  16. package/api/theme/theme.type.d.mts +5 -1
  17. package/api/theme/theme.type.mjs +2 -1
  18. package/api/theme/themeBuild.doc.mjs +3 -3
  19. package/api/theme/themeEject.doc.mjs +1 -1
  20. package/api/theme/themeTemplate.doc.mjs +9 -3
  21. package/api/theme-edit/_adapter.d.mts +33 -0
  22. package/api/theme-edit/_adapter.mjs +208 -31
  23. package/api/theme-edit/_check.d.mts +38 -0
  24. package/api/theme-edit/_check.mjs +1326 -211
  25. package/api/theme-edit/_color.d.mts +2 -8
  26. package/api/theme-edit/_color.mjs +292 -219
  27. package/api/theme-edit/_compiler.d.mts +1 -0
  28. package/api/theme-edit/_compiler.mjs +20 -1
  29. package/api/theme-edit/_context.d.mts +29 -0
  30. package/api/theme-edit/_context.mjs +329 -30
  31. package/api/theme-edit/_css.d.mts +60 -1
  32. package/api/theme-edit/_css.mjs +404 -28
  33. package/api/theme-edit/_edit.d.mts +9 -0
  34. package/api/theme-edit/_edit.mjs +1025 -126
  35. package/api/theme-edit/_how-commands.d.mts +11 -26
  36. package/api/theme-edit/_how-commands.mjs +30 -2
  37. package/api/theme-edit/_how-question.d.mts +7 -0
  38. package/api/theme-edit/_how-question.mjs +1304 -176
  39. package/api/theme-edit/_how.mjs +144 -30
  40. package/api/theme-edit/_overview.mjs +2 -0
  41. package/api/theme-edit/_palette.d.mts +11 -0
  42. package/api/theme-edit/_palette.mjs +194 -65
  43. package/api/theme-edit/_parts.d.mts +16 -0
  44. package/api/theme-edit/_parts.mjs +59 -7
  45. package/api/theme-edit/_png.mjs +19 -14
  46. package/api/theme-edit/_preview-app.d.mts +3 -0
  47. package/api/theme-edit/_preview-app.mjs +843 -45
  48. package/api/theme-edit/_preview.d.mts +16 -3
  49. package/api/theme-edit/_preview.mjs +310 -29
  50. package/api/theme-edit/_project.d.mts +11 -0
  51. package/api/theme-edit/_project.mjs +46 -12
  52. package/api/theme-edit/_settings.d.mts +178 -5
  53. package/api/theme-edit/_settings.mjs +2035 -86
  54. package/api/theme-edit/_tables.d.mts +24 -0
  55. package/api/theme-edit/_tables.mjs +211 -149
  56. package/api/theme-edit/_vet.d.mts +42 -0
  57. package/api/theme-edit/_vet.mjs +144 -0
  58. package/api/theme-edit/theme-edit.type.d.mts +2 -1
  59. package/api/theme-edit/theme-edit.type.mjs +1 -1
  60. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  61. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  62. package/api/upgrade/registry/registry.mjs +6 -1
  63. package/assets/docs/tree/single-component.doc.mjs +11 -2
  64. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  65. package/assets/docs.generated.json +2 -2
  66. package/assets/preview-app/next.config.mjs +7 -1
  67. package/assets/preview-app/package.json +1 -0
  68. package/assets/preview-app/src/app/globals.css +1 -0
  69. package/assets/self-audit.generated.json +1 -1
  70. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  71. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  72. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  73. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  74. package/assets/templates/components.generated.json +1 -1
  75. package/assets/templates/pages/dashboard/page.tsx +1 -1
  76. package/authoring/doctypes/_schema.d.mts +52 -5
  77. package/authoring/doctypes/_schema.mjs +62 -7
  78. package/authoring/doctypes/base/type.ts +10 -0
  79. package/authoring/doctypes/component/component.doc.mjs +1 -1
  80. package/authoring/doctypes/function/function.doc.mjs +6 -0
  81. package/authoring/doctypes/function/type.ts +3 -0
  82. package/authoring/doctypes/legacy.mjs +5 -1
  83. package/authoring/index.d.ts +1 -0
  84. package/clients/cli/build-id.generated.json +1 -1
  85. package/clients/cli/commands/doctor.doc.mjs +2 -2
  86. package/clients/cli/commands/experimental/theme.mjs +190 -37
  87. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  88. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  89. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  90. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  91. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  92. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  93. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  94. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  95. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  96. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  97. package/clients/cli/commands/theme.mjs +168 -45
  98. package/clients/cli/formatters/index.mjs +7 -4
  99. package/clients/cli/lib/cli-error.mjs +9 -3
  100. package/clients/cli/lib/component-format.mjs +27 -9
  101. package/clients/cli/lib/json-shim.mjs +40 -2
  102. package/clients/cli/manifest.generated.json +1 -1
  103. package/clients/cli/run.mjs +49 -0
  104. package/foundation/config/project.mjs +50 -14
  105. package/foundation/discovery/theme-discovery.d.mts +5 -1
  106. package/foundation/discovery/theme-discovery.mjs +24 -3
  107. package/foundation/fs/gather-cache.d.mts +9 -2
  108. package/foundation/fs/gather-cache.mjs +79 -15
  109. package/foundation/fs/paths.d.mts +31 -0
  110. package/foundation/fs/paths.mjs +43 -10
  111. package/foundation/render/host-exit.d.mts +8 -0
  112. package/foundation/render/host-exit.mjs +11 -0
  113. package/foundation/render/page-host.mjs +56 -10
  114. package/foundation/render/page-worker.mjs +14 -0
  115. package/foundation/render/render-page.mjs +37 -2
  116. package/foundation/response/error-codes.d.mts +2 -1
  117. package/foundation/response/error-codes.d.ts +1 -0
  118. package/foundation/response/error-codes.doc.mjs +5 -0
  119. package/foundation/response/error-codes.mjs +3 -0
  120. package/foundation/response/json.d.mts +15 -0
  121. package/foundation/response/json.mjs +52 -1
  122. package/foundation/response/response-types.doc.mjs +1 -1
  123. package/package.json +7 -6
@@ -84,6 +84,7 @@ import {
84
84
  PathSafetyError,
85
85
  } from '../../../foundation/fs/path-safety.mjs';
86
86
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
87
+ import {editorThemeRecord} from '../../../foundation/config/theme-state.mjs';
87
88
  import {validatePrivateVars} from '../../../foundation/config/theme-private-vars.mjs';
88
89
  import {AstryxError} from '../../error.mjs';
89
90
  import {applyWrites} from '../../integration/add-helpers.mjs';
@@ -710,16 +711,21 @@ export function normalizeThemeBuildForCompare(content) {
710
711
  .join('\n');
711
712
  }
712
713
 
713
- /** @param {Array<{dest: string, content: string, allowMissingInCheck?: boolean}>} writes @param {string} cwd @returns {Array<{path: string, reason: 'missing' | 'outdated'}>} */
714
+ /**
715
+ * The outputs that are missing or differ from what the build would write. A
716
+ * missing `.css.d.ts` stylesheet type stub (a write marked `warnWhenMissing`)
717
+ * is not stale: projects that ignore it in version control run the check in
718
+ * CI, so the check warns about it instead (missingDeclarations). Every other
719
+ * missing output, the module's `.d.ts` too, is stale.
720
+ * @param {Array<{dest: string, content: string, warnWhenMissing?: boolean}>} writes @param {string} cwd @returns {Array<{path: string, reason: 'missing' | 'outdated'}>}
721
+ */
714
722
  function staleBuildOutputs(writes, cwd) {
715
723
  /** @type {Array<{path: string, reason: 'missing' | 'outdated'}>} */
716
724
  const stale = [];
717
725
  for (const write of writes) {
718
726
  const rel = path.relative(cwd, write.dest);
719
727
  if (!fs.existsSync(write.dest)) {
720
- if (!write.allowMissingInCheck) {
721
- stale.push({path: rel, reason: 'missing'});
722
- }
728
+ if (!write.warnWhenMissing) stale.push({path: rel, reason: 'missing'});
723
729
  continue;
724
730
  }
725
731
  const onDisk = fs.readFileSync(write.dest, 'utf8');
@@ -733,13 +739,42 @@ function staleBuildOutputs(writes, cwd) {
733
739
  return stale;
734
740
  }
735
741
 
736
- /** @param {Array<{dest: string, allowMissingInCheck?: boolean}>} writes @param {string} cwd */
742
+ /**
743
+ * Every output the build writes, from the same write list the build and the
744
+ * stale comparison use. A missing output makes the check stale, except the
745
+ * `.css.d.ts` stub, which it warns about (missingDeclarations).
746
+ * @param {Array<{dest: string}>} writes @param {string} cwd
747
+ */
737
748
  function checkedBuildOutputs(writes, cwd) {
749
+ return writes.map(write => path.relative(cwd, write.dest));
750
+ }
751
+
752
+ /**
753
+ * The `.css.d.ts` stylesheet type stubs the build writes that are missing,
754
+ * which the check names as checked and warns about in text mode without
755
+ * failing.
756
+ * @param {Array<{dest: string, warnWhenMissing?: boolean}>} writes @param {string} cwd
757
+ * @returns {string[]}
758
+ */
759
+ function missingDeclarations(writes, cwd) {
738
760
  return writes
739
- .filter(write => !write.allowMissingInCheck || fs.existsSync(write.dest))
761
+ .filter(write => write.warnWhenMissing && !fs.existsSync(write.dest))
740
762
  .map(write => path.relative(cwd, write.dest));
741
763
  }
742
764
 
765
+ /**
766
+ * The one text-mode warning line for missing stylesheet type stubs, or
767
+ * nothing when none is missing. The logger is silent under --json.
768
+ * @param {Array<{dest: string, warnWhenMissing?: boolean}>} writes @param {string} cwd
769
+ */
770
+ function warnMissingDeclarations(writes, cwd) {
771
+ const missing = missingDeclarations(writes, cwd);
772
+ if (missing.length === 0) return;
773
+ logger.warn(
774
+ ` Warning: stylesheet type declaration file${missing.length === 1 ? '' : 's'} not found: ${missing.join(', ')}. The check does not fail on ${missing.length === 1 ? 'it' : 'them'}; a build writes ${missing.length === 1 ? 'it' : 'them'}.`,
775
+ );
776
+ }
777
+
743
778
  /** Remedies that end a confinement error, by where the output path came from. */
744
779
  const OUT_REMEDY = 'Pass an --out path inside it.';
745
780
  const SOURCE_REMEDY =
@@ -1059,6 +1094,54 @@ function assertThemeSourceFile(filePath, cwd) {
1059
1094
  }
1060
1095
  }
1061
1096
 
1097
+ /**
1098
+ * What the CLI hands a build beyond themeBuild's options. CLI-internal, never
1099
+ * a themeBuild option: `claimedOutputs` records the outputs earlier builds in
1100
+ * one run wrote, so a later theme cannot replace them; with `deferredWrites`
1101
+ * the build adds its outputs to that list instead of writing them, for
1102
+ * writeDeferredBuildOutputs; `writeRoot` replaces `cwd` as the directory every
1103
+ * output must stay inside, for a scratch build; `commandWords` names the
1104
+ * command in the rebuild hint; `prepareFamily`, `familyLoader`, and
1105
+ * `familyInterception` make the build a family member's plan.
1106
+ * @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
1107
+ */
1108
+
1109
+ /**
1110
+ * Who takes the theme editor warnings (an editor folder, an editor-made
1111
+ * theme) instead of the logger: the watcher's child build hands each to its
1112
+ * parent, which prints it once per session. Set
1113
+ * only by the CLI (not part of the public API), and never by an option of
1114
+ * themeBuild.
1115
+ * @type {((warning: string) => void) | null}
1116
+ */
1117
+ let editorFolderListener = null;
1118
+
1119
+ /**
1120
+ * Hand the theme editor warnings of the builds in this process to
1121
+ * `listener` instead of the logger. CLI-internal: the watch child's
1122
+ * hand-off to its parent.
1123
+ * @param {((warning: string) => void) | null} listener
1124
+ */
1125
+ export function setEditorFolderListener(listener) {
1126
+ editorFolderListener = listener;
1127
+ }
1128
+
1129
+ /**
1130
+ * Who is told a build found private var errors (the CLI, to exit 1). Set
1131
+ * only by the CLI, never by an option of themeBuild.
1132
+ * @type {(() => void) | null}
1133
+ */
1134
+ let privateVarErrorListener = null;
1135
+
1136
+ /**
1137
+ * Tell `listener` when a build in this process finds private var errors.
1138
+ * CLI-internal.
1139
+ * @param {(() => void) | null} listener
1140
+ */
1141
+ export function setPrivateVarErrorListener(listener) {
1142
+ privateVarErrorListener = listener;
1143
+ }
1144
+
1062
1145
  /**
1063
1146
  * Refuse a build that would replace a file it does not own. A build never
1064
1147
  * writes over its input, two of its own outputs at one path, or an output
@@ -1069,21 +1152,49 @@ function assertThemeSourceFile(filePath, cwd) {
1069
1152
  * @param {Array<{dest: string}>} writes
1070
1153
  * @param {string} filePath the theme source
1071
1154
  * @param {string} cwd
1072
- * @param {{claimed?: Map<string, string>, rerun?: string, refuseUnmarked?: boolean, elsewhere?: string}} [options]
1155
+ * @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void}} [options]
1073
1156
  * `claimed`: outputs written earlier in this run, by the source that wrote
1074
- * them; `rerun`: this build's command, to run again once the file is gone;
1075
- * `elsewhere`: the option that moves the outputs
1157
+ * them; `rerun`: this build's command with another --out, or without one;
1158
+ * `elsewhere`: the option that moves the outputs; `onEditorFolder`: takes
1159
+ * the editor-folder warning instead of the logger (a watcher prints it once)
1076
1160
  */
1077
1161
  function assertOutputsReplaceable(
1078
1162
  writes,
1079
1163
  filePath,
1080
1164
  cwd,
1081
- {claimed, rerun, refuseUnmarked = false, elsewhere = '--out'} = {},
1165
+ {
1166
+ claimed,
1167
+ rerun,
1168
+ refuseUnmarked = false,
1169
+ elsewhere = '--out',
1170
+ onEditorFolder,
1171
+ } = {},
1082
1172
  ) {
1083
1173
  const rel = (/** @type {string} */ file) => path.relative(cwd, file);
1084
1174
  const sourceKey = outputKey(filePath);
1085
1175
  const seen = new Set();
1176
+ /** @type {string | false} */
1086
1177
  let warnedOtherSource = false;
1178
+ // The same build without --out, with its other options.
1179
+ const beside = {
1180
+ name: rerun
1181
+ ? rerun(null)
1182
+ : formatCliCommand(`theme build ${shellWord(rel(filePath))}`, cwd),
1183
+ reason: 'write the outputs beside this source',
1184
+ };
1185
+ // A folder the theme editor made holds that theme's outputs only: another
1186
+ // source's outputs there would sit beside its settings as if they were
1187
+ // its own. A source inside the folder builds there as always; one outside
1188
+ // it writes there too, with a warning.
1189
+ let editorFolder = false;
1190
+ if (refuseUnmarked && writes.length) {
1191
+ const dir = path.resolve(path.dirname(writes[0].dest));
1192
+ const record = editorThemeRecord(dir);
1193
+ const fromDir = path.relative(dir, path.resolve(filePath));
1194
+ // On Windows a source on another drive has an absolute relative path.
1195
+ const inside = !fromDir.startsWith('..') && !path.isAbsolute(fromDir);
1196
+ if (record && !inside) editorFolder = true;
1197
+ }
1087
1198
  for (const write of writes) {
1088
1199
  const key = outputKey(write.dest);
1089
1200
  if (key === sourceKey) {
@@ -1139,23 +1250,14 @@ function assertOutputsReplaceable(
1139
1250
  : null;
1140
1251
  if (otherSource && !OUT_REFUSES_OTHER_SOURCE) {
1141
1252
  // One warning per build: every output of that source goes together.
1253
+ // It is printed after every output passes, so it names a replacement
1254
+ // that happens.
1142
1255
  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
- );
1256
+ warnedOtherSource = `Warning: ${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`;
1147
1257
  } else if (otherSource) {
1148
1258
  throw new AstryxError(
1149
1259
  `${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
- ],
1260
+ [beside],
1159
1261
  ERROR_CODES.ERR_FILE_EXISTS,
1160
1262
  );
1161
1263
  }
@@ -1166,20 +1268,71 @@ function assertOutputsReplaceable(
1166
1268
  stat.size > 0 &&
1167
1269
  !fileHead(write.dest).includes(GENERATED_MARKER)
1168
1270
  ) {
1271
+ // Never advice to delete it: it may be the person's file (a settings
1272
+ // file, app source). A path that takes every output instead.
1273
+ const free = freeOutPath(writes);
1169
1274
  throw new AstryxError(
1170
- `${rel(write.dest)} was written by an older CLI (before 0.6.7) or by hand, so the build does not replace it. Delete that file and run the same build again, or pick another ${elsewhere}.`,
1171
- rerun
1172
- ? [
1173
- {
1174
- name: rerun,
1175
- reason: 'run the same build again once the file is deleted',
1176
- },
1177
- ]
1178
- : undefined,
1275
+ `${rel(write.dest)} is a file this build did not write (it has no build header: your own file, another tool's, or an output from a CLI before 0.6.7), so the build does not replace it. Pick another ${elsewhere}.`,
1276
+ [
1277
+ ...(free && rerun
1278
+ ? [
1279
+ {
1280
+ name: rerun(rel(free)),
1281
+ reason: 'a path where no output of this build exists yet',
1282
+ },
1283
+ ]
1284
+ : []),
1285
+ beside,
1286
+ ],
1179
1287
  ERROR_CODES.ERR_FILE_EXISTS,
1180
1288
  );
1181
1289
  }
1182
1290
  }
1291
+ // Warned only once nothing refuses the build, so it names a write that
1292
+ // happens.
1293
+ if (warnedOtherSource) logger.warn(warnedOtherSource);
1294
+ if (editorFolder) {
1295
+ const dir = path.dirname(writes[0].dest);
1296
+ const warning = `Warning: ${rel(dir) || '.'} is a folder the theme editor made, and ${rel(filePath)} is outside it; the build writes there anyway. Build beside the source, or pick another ${elsewhere}, to keep the editor's folder to its own theme.`;
1297
+ if (onEditorFolder) onEditorFolder(warning);
1298
+ else logger.warn(warning);
1299
+ }
1300
+ }
1301
+
1302
+ /**
1303
+ * An --out path where no output of this build exists yet, or null. The
1304
+ * stylesheet and its `.css.d.ts` follow the name --out gives; the module and
1305
+ * its types are named after the theme, so a new name beside them (`brand-2.css`)
1306
+ * helps only when those are free, else a new folder (`brand-2/brand.css`).
1307
+ * @param {Array<{dest: string}>} writes the stylesheet first
1308
+ * @returns {string | null}
1309
+ */
1310
+ function freeOutPath(writes) {
1311
+ const css = writes[0]?.dest;
1312
+ if (!css) return null;
1313
+ const dir = path.dirname(css);
1314
+ const stem = path.basename(css).replace(/\.css$/i, '');
1315
+ /** Whether a write set (each output moved by `move`) touches any file. */
1316
+ const blocked = (/** @type {(dest: string) => string} */ move) =>
1317
+ writes.some(w => fs.existsSync(move(w.dest)));
1318
+ for (let n = 2; n < 100; n += 1) {
1319
+ const next = `${stem}-${n}`;
1320
+ // Only the stylesheet and its types follow --out's name.
1321
+ // The exact names a build with `--out <next>.css` writes, also when
1322
+ // --out did not end in .css (`o.txt` suggests `o.txt-2.css`).
1323
+ const renamed = (/** @type {string} */ dest) =>
1324
+ dest === css
1325
+ ? path.join(dir, `${next}.css`)
1326
+ : dest === `${css}.d.ts`
1327
+ ? path.join(dir, `${next}.css.d.ts`)
1328
+ : dest;
1329
+ if (!blocked(renamed)) return path.join(dir, `${next}.css`);
1330
+ const folder = (/** @type {string} */ dest) =>
1331
+ path.join(dir, next, path.basename(dest));
1332
+ if (!fs.existsSync(path.join(dir, next)) && !blocked(folder))
1333
+ return path.join(dir, next, path.basename(css));
1334
+ }
1335
+ return null;
1183
1336
  }
1184
1337
 
1185
1338
  /**
@@ -1283,7 +1436,9 @@ function toIdentifier(name) {
1283
1436
  * @returns {string}
1284
1437
  */
1285
1438
  export function importSpecifier(relDir, base) {
1286
- const normalized = relDir === '.' ? '' : relDir;
1439
+ // An import specifier always uses `/`. On Windows the cwd-relative dir comes
1440
+ // from path.relative with `\`, which would print `./\themes\ocean/ocean`.
1441
+ const normalized = relDir === '.' ? '' : relDir.split(path.sep).join('/');
1287
1442
  const withinSrc = normalized.replace(/^src\/?/, '').replace(/\/+$/, '');
1288
1443
  return withinSrc ? `./${withinSrc}/${base}` : `./${base}`;
1289
1444
  }
@@ -3504,25 +3659,29 @@ function validateHeadingTypeAugmentationSupport(themeDef) {
3504
3659
  * `logger` (silent by default).
3505
3660
  *
3506
3661
  * @param {string} file - Theme file path, resolved against `cwd`.
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] -
3662
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options] -
3508
3663
  * `out` overrides the output CSS path, or names the folder for it; `check` compares against on-disk outputs
3509
- * instead of writing. `__claimedOutputs` records the outputs earlier builds
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
3513
- * output must stay inside, for a CLI-internal scratch build. `iconsSpecifier` overrides the icon registry import
3664
+ * instead of writing. `iconsSpecifier` overrides the icon registry import
3514
3665
  * specifier in the generated module (e.g. `./icons.mjs`); when omitted, the
3515
3666
  * direct registry specifiers from the theme source are emitted unchanged.
3516
3667
  * @param {{cwd?: string, projectCore?: boolean}} [ctx] `projectCore`: only the
3517
3668
  * project's installed Core (spec AST-081 FR3)
3669
+ * @param {{compact?: boolean, trailers?: ThemeBuildTrailer[]}} [report]
3670
+ * @param {ThemeBuildHandOff} [handOff] - what the CLI's batch, family, and
3671
+ * scratch builds hand a build; never an option of the public themeBuild.
3518
3672
  * @returns {Promise<any>}
3519
3673
  */
3520
3674
  async function themeBuildInternal(
3521
3675
  file,
3522
3676
  options = {},
3523
3677
  {cwd = process.cwd(), projectCore = false} = {},
3524
- /** @type {{compact?: boolean, trailers?: ThemeBuildTrailer[]}} */ report = {},
3678
+ report = {},
3679
+ handOff = {},
3525
3680
  ) {
3681
+ // A backslash in --out separates folders on every platform, as it does in
3682
+ // the other theme paths (a Windows path copied into a POSIX shell).
3683
+ if (typeof options.out === 'string' && options.out.includes('\\'))
3684
+ options = {...options, out: options.out.replace(/\\/g, '/')};
3526
3685
  const filePath = path.resolve(cwd, file);
3527
3686
 
3528
3687
  if (!fs.existsSync(filePath)) {
@@ -3536,6 +3695,22 @@ async function themeBuildInternal(
3536
3695
  );
3537
3696
  }
3538
3697
 
3698
+ // A theme the theme editor made is built from its settings by the editor;
3699
+ // a plain build reads its settings module as last written (released CLIs
3700
+ // built it, so it still does, and says so).
3701
+ {
3702
+ const dir = path.dirname(filePath);
3703
+ const slug = path.basename(dir);
3704
+ if (
3705
+ (!handOff.commandWords || handOff.commandWords.group === 'theme') &&
3706
+ path.basename(filePath) === `${slug}.theme.ts` &&
3707
+ editorThemeRecord(dir)
3708
+ )
3709
+ (editorFolderListener ?? (w => logger.warn(w)))(
3710
+ `Warning: ${path.relative(cwd, filePath)} is a theme the theme editor made (${slug}.settings.json is beside it). This build reads ${slug}.settings.ts as last written; to build it from its settings, run ${formatCliCommand(`experimental theme editor show ${shellWord(slug)}`, cwd)}.`,
3711
+ );
3712
+ }
3713
+
3539
3714
  if (fs.statSync(filePath).isDirectory()) {
3540
3715
  throw new AstryxError(
3541
3716
  `${path.relative(cwd, filePath) || '.'} is a folder. Pass the theme file inside it.`,
@@ -3574,7 +3749,7 @@ async function themeBuildInternal(
3574
3749
  // shared loader so exact authored parent identity stays CLI-private instead
3575
3750
  // of becoming a public DefinedTheme field.
3576
3751
  const interception =
3577
- options.__familyInterception ??
3752
+ handOff.familyInterception ??
3578
3753
  (_generateAdaptationCSS && themeFolderResolvesCore(filePath)
3579
3754
  ? undefined
3580
3755
  : interceptCore(_coreThemeModule, _coreRootModule));
@@ -3599,7 +3774,7 @@ async function themeBuildInternal(
3599
3774
  const loaded = await extractThemeDefinition(
3600
3775
  filePath,
3601
3776
  interception,
3602
- options.__familyLoader,
3777
+ handOff.familyLoader,
3603
3778
  );
3604
3779
  const after = fs.readFileSync(filePath, 'utf8');
3605
3780
  if (before !== after || before === '') {
@@ -3614,9 +3789,64 @@ async function themeBuildInternal(
3614
3789
  } catch (e) {
3615
3790
  const err = /** @type {Error} */ (e);
3616
3791
  const shown = path.relative(cwd, filePath) || filePath;
3792
+ // A theme file that is a link and does not load: named with the file it
3793
+ // points to (some loaders read its relative imports from the link's
3794
+ // folder, others from the file's own), never with Node's require stack.
3795
+ // Only an unresolved relative import is about the link; any other
3796
+ // failure (a package not installed) keeps its own remedy.
3797
+ let link = null;
3798
+ try {
3799
+ if (
3800
+ fs.lstatSync(filePath).isSymbolicLink() &&
3801
+ /Cannot find (?:module|package) '\.\.?\//.test(err.message)
3802
+ )
3803
+ link = fs.realpathSync(filePath);
3804
+ } catch {
3805
+ link = null;
3806
+ }
3807
+ const message = err.message
3808
+ .replace(/\n+Require stack:(?:\n- [^\n]*)*/, '')
3809
+ .split(filePath)
3810
+ .join(shown);
3617
3811
  throw new AstryxError(
3618
- err.message.split(filePath).join(shown),
3619
- themeLoadSuggestions(err, shown, cwd),
3812
+ link
3813
+ ? `${shown} is a link to ${path.relative(cwd, link) || link}, and it could not be loaded (a relative import may be read from the link's folder or from the file's own, depending on the loader); build the file itself: ${message}`
3814
+ : message,
3815
+ link
3816
+ ? [
3817
+ {
3818
+ // The file itself, with its outputs kept inside the working
3819
+ // folder (beside the link) when the file is outside it.
3820
+ name: formatCliCommand(
3821
+ [
3822
+ 'theme',
3823
+ 'build',
3824
+ path.relative(cwd, link) || link,
3825
+ ...(path.relative(cwd, link).startsWith('..') ||
3826
+ path.isAbsolute(path.relative(cwd, link))
3827
+ ? [
3828
+ '--out',
3829
+ path
3830
+ .relative(
3831
+ cwd,
3832
+ path.join(
3833
+ path.dirname(filePath),
3834
+ `${path.basename(filePath).replace(/\.[^.]+$/, '')}.css`,
3835
+ ),
3836
+ )
3837
+ .split(path.sep)
3838
+ .join('/'),
3839
+ ]
3840
+ : []),
3841
+ ]
3842
+ .map(shellWord)
3843
+ .join(' '),
3844
+ cwd,
3845
+ ),
3846
+ reason: 'build the file itself',
3847
+ },
3848
+ ]
3849
+ : themeLoadSuggestions(err, shown, cwd),
3620
3850
  ERROR_CODES.ERR_THEME_LOAD,
3621
3851
  );
3622
3852
  }
@@ -3626,13 +3856,13 @@ async function themeBuildInternal(
3626
3856
  // JSON.stringify and Object.keys, so it could not reach output regardless.)
3627
3857
  // Both reads happen BEFORE the strip, which is what removes the evidence.
3628
3858
  const ancestryObserved =
3629
- !options.__prepareFamily ||
3859
+ !handOff.prepareFamily ||
3630
3860
  !interception ||
3631
3861
  interception.observed(themeDef) ||
3632
3862
  Object.hasOwn(themeDef, 'extends');
3633
- if (options.__prepareFamily && interception) interception.retain(themeDef);
3863
+ if (handOff.prepareFamily && interception) interception.retain(themeDef);
3634
3864
  const sourceParent =
3635
- options.__prepareFamily && interception
3865
+ handOff.prepareFamily && interception
3636
3866
  ? interception.parentOf(themeDef)
3637
3867
  : undefined;
3638
3868
  const adaptationLineage = interception
@@ -3691,7 +3921,7 @@ async function themeBuildInternal(
3691
3921
  // generation so neither the no-CSS return nor --check can bypass the error.
3692
3922
  // Family preparation keeps its own named-import registry contract, which
3693
3923
  // themeBuildFamily checks against the selected members' graph.
3694
- const standaloneIcons = !options.__prepareFamily;
3924
+ const standaloneIcons = !handOff.prepareFamily;
3695
3925
  // Function icon entries stay functions in the built module, beside a node
3696
3926
  // view bound to `<theme>IconNodes` and computed from `<theme>IconEntries`.
3697
3927
  const functionEntries =
@@ -3750,7 +3980,7 @@ async function themeBuildInternal(
3750
3980
  logger.error(` [error] ${source}${e}`);
3751
3981
  }
3752
3982
  if (privateVarErrors.length > 0) {
3753
- options.__onPrivateVarError?.();
3983
+ privateVarErrorListener?.();
3754
3984
  logger.error(
3755
3985
  `\n ${source}${privateVarErrors.length} private var error(s). Use standard CSS properties instead.`,
3756
3986
  );
@@ -4067,7 +4297,20 @@ async function themeBuildInternal(
4067
4297
  // Source path relative to cwd — used in @generated headers
4068
4298
  const sourceRelative = path.relative(cwd, filePath);
4069
4299
  // 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)) : ''}`;
4300
+ // The project's own invocation, each path quoted for the shell.
4301
+ const rebuildCommand = formatCliCommand(
4302
+ [
4303
+ 'theme',
4304
+ 'build',
4305
+ sourceRelative,
4306
+ ...(options.out
4307
+ ? ['--out', path.relative(cwd, path.resolve(cwd, options.out))]
4308
+ : []),
4309
+ ]
4310
+ .map(shellWord)
4311
+ .join(' '),
4312
+ cwd,
4313
+ );
4071
4314
  // Stable provenance recorded in @generated headers — versions, not a
4072
4315
  // timestamp, so identical inputs produce byte-identical output.
4073
4316
  const versions = resolveToolVersions(cwd);
@@ -4077,7 +4320,7 @@ async function themeBuildInternal(
4077
4320
  const baseName = themeDef.name;
4078
4321
  // Every write stays inside cwd. A CLI-internal caller that renders into a
4079
4322
  // scratch directory it creates and removes names that directory instead.
4080
- const writeRoot = options.__writeRoot ?? cwd;
4323
+ const writeRoot = handOff.writeRoot ?? cwd;
4081
4324
  let outPath;
4082
4325
  if (options.out) {
4083
4326
  outPath = path.resolve(cwd, options.out);
@@ -4157,7 +4400,7 @@ async function themeBuildInternal(
4157
4400
  'export {};\n';
4158
4401
  // A family member's module is generated by themeBuildFamily, which carries
4159
4402
  // its registries and slot functions through the family's own imports.
4160
- const jsContent = options.__prepareFamily
4403
+ const jsContent = handOff.prepareFamily
4161
4404
  ? ''
4162
4405
  : generatedHeader(headerSource, 'js', buildCommand, versions) +
4163
4406
  generateBuiltModule(
@@ -4187,7 +4430,7 @@ async function themeBuildInternal(
4187
4430
  ]),
4188
4431
  ];
4189
4432
 
4190
- if (options.__prepareFamily) {
4433
+ if (handOff.prepareFamily) {
4191
4434
  return {
4192
4435
  filePath,
4193
4436
  sourceRelative: sourceRelative.split(path.sep).join('/'),
@@ -4209,7 +4452,7 @@ async function themeBuildInternal(
4209
4452
 
4210
4453
  const writes = [
4211
4454
  {dest: outPath, content: cssContent},
4212
- {dest: cssDtsPath, content: cssDtsContent, allowMissingInCheck: true},
4455
+ {dest: cssDtsPath, content: cssDtsContent, warnWhenMissing: true},
4213
4456
  {dest: jsPath, content: jsContent},
4214
4457
  {dest: dtsPath, content: dtsContent},
4215
4458
  ];
@@ -4223,14 +4466,15 @@ async function themeBuildInternal(
4223
4466
  if (!options.check) {
4224
4467
  confineOutputs(writes, writeRoot, options.out ? OUT_REMEDY : SOURCE_REMEDY);
4225
4468
  // prettier-ignore
4226
- const rerun = formatCliCommand(['theme', 'build', path.relative(cwd, filePath), ...(options.out ? ['--out', options.out] : []), ...(options.iconsSpecifier ? ['--icons-specifier', options.iconsSpecifier] : [])].map(shellWord).join(' '), cwd);
4469
+ const rerun = (/** @type {string | null} */ out) => formatCliCommand(['theme', 'build', path.relative(cwd, filePath), ...(out == null ? [] : ['--out', out]), ...(options.iconsSpecifier ? ['--icons-specifier', options.iconsSpecifier] : [])].map(shellWord).join(' '), cwd);
4227
4470
  // A header-less file at the default paths beside the source is an output
4228
4471
  // of a CLI before 0.6.7, which the build has always replaced. A path that
4229
4472
  // --out names may hold anything, so there only build outputs are replaced.
4230
4473
  assertOutputsReplaceable(writes, filePath, cwd, {
4231
- claimed: options.__claimedOutputs,
4474
+ claimed: handOff.claimedOutputs,
4232
4475
  rerun,
4233
4476
  refuseUnmarked: Boolean(options.out),
4477
+ onEditorFolder: editorFolderListener ?? undefined,
4234
4478
  });
4235
4479
  }
4236
4480
 
@@ -4260,26 +4504,29 @@ async function themeBuildInternal(
4260
4504
  if (remedy) logger.error(`\n ${remedy.join('\n ')}`);
4261
4505
  else
4262
4506
  logger.error(
4263
- `\n Rebuild with: ${rebuildLine(rebuildCommand, options.__commandWords)}`,
4507
+ `\n Rebuild with: ${rebuildLine(rebuildCommand, handOff.commandWords)}`,
4264
4508
  );
4265
4509
  }
4266
- return {
4510
+ warnMissingDeclarations(writes, cwd);
4511
+ return /** @type {import('../theme.type.mjs').ThemeBuildCheckResponse} */ ({
4267
4512
  type: 'theme.build.check',
4268
4513
  data: {
4269
4514
  name: themeDef.name,
4270
4515
  upToDate,
4271
4516
  stale,
4272
4517
  checked: checkedBuildOutputs(writes, cwd),
4518
+ // The code a stale check exits 1 with, for --json callers.
4519
+ ...(upToDate ? {} : {code: ERROR_CODES.ERR_THEME_STALE}),
4273
4520
  },
4274
- };
4521
+ });
4275
4522
  }
4276
4523
 
4277
4524
  // A batch publishes every theme's outputs after all of them are built, so
4278
4525
  // two themes that build the same files are refused before either writes.
4279
- if (options.__deferredWrites) options.__deferredWrites.push(writes);
4526
+ if (handOff.deferredWrites) handOff.deferredWrites.push(writes);
4280
4527
  else writeBuildOutputs(writes);
4281
4528
  for (const write of writes) {
4282
- options.__claimedOutputs?.set(outputKey(write.dest), sourceRelative);
4529
+ handOff.claimedOutputs?.set(outputKey(write.dest), sourceRelative);
4283
4530
  }
4284
4531
 
4285
4532
  if (!report.compact) {
@@ -4503,6 +4750,7 @@ function groupUnloadedFonts(trailers) {
4503
4750
  * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options]
4504
4751
  * @param {{cwd?: string}} [ctx]
4505
4752
  * @param {{compact?: boolean}} [report]
4753
+ * @param {ThemeBuildHandOff} [handOff]
4506
4754
  * @returns {Promise<{receipt: import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null, trailer: ThemeBuildTrailer | null}>}
4507
4755
  */
4508
4756
  export async function themeBuildForReport(
@@ -4510,18 +4758,38 @@ export async function themeBuildForReport(
4510
4758
  options = {},
4511
4759
  ctx = {},
4512
4760
  {compact = false} = {},
4761
+ handOff = {},
4513
4762
  ) {
4514
4763
  /** @type {ThemeBuildTrailer[]} */
4515
4764
  const trailers = [];
4516
4765
  const receipt = /** @type {any} */ (
4517
- await themeBuildInternal(file, options, ctx, {compact, trailers})
4766
+ await themeBuildInternal(file, options, ctx, {compact, trailers}, handOff)
4518
4767
  );
4519
4768
  return {receipt, trailer: trailers[0] ?? null};
4520
4769
  }
4521
4770
 
4522
4771
  /** @param {string} file @param {{out?: string, check?: boolean, iconsSpecifier?: string}} [options] @param {{cwd?: string, projectCore?: boolean}} [ctx] `projectCore`: read only the project's installed Core, never the carried one (doctor; spec AST-081 FR3) @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>} */
4523
4772
  export async function themeBuild(file, options = {}, ctx = {}) {
4524
- return /** @type {any} */ (themeBuildInternal(file, options, ctx));
4773
+ const {out, check, iconsSpecifier} = options;
4774
+ return /** @type {any} */ (
4775
+ themeBuildInternal(file, {out, check, iconsSpecifier}, ctx)
4776
+ );
4777
+ }
4778
+
4779
+ /**
4780
+ * {@link themeBuild} with the CLI's hand-off: the same build, outputs, and
4781
+ * receipt, plus what only the CLI's batch and scratch builds pass.
4782
+ * CLI-internal: not exported from the API entry.
4783
+ * @param {string} file
4784
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string}} options
4785
+ * @param {{cwd?: string, projectCore?: boolean}} ctx
4786
+ * @param {ThemeBuildHandOff} handOff
4787
+ * @returns {Promise<import('../theme.type.mjs').ThemeBuildResponse | import('../theme.type.mjs').ThemeBuildCheckResponse | null>}
4788
+ */
4789
+ export async function themeBuildWithHandOff(file, options, ctx, handOff) {
4790
+ return /** @type {any} */ (
4791
+ themeBuildInternal(file, options, ctx, {}, handOff)
4792
+ );
4525
4793
  }
4526
4794
  /** @param {string} name */
4527
4795
  // prettier-ignore
@@ -4660,11 +4928,12 @@ async function preloadFamilySource(filePath, loader, interception) {
4660
4928
  finally { patch.undo(); }
4661
4929
  }
4662
4930
 
4663
- /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
4931
+ /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string}} options @param {{cwd?: string}} [ctx] @param {{commandWords?: {group: string, build: string}}} [handOff] - the CLI's words for the rebuild hint */
4664
4932
  export async function themeBuildFamily(
4665
4933
  files,
4666
4934
  options,
4667
4935
  {cwd = process.cwd()} = {},
4936
+ handOff = {},
4668
4937
  ) {
4669
4938
  if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(options?.familyKey ?? '')) {
4670
4939
  throw new AstryxError(
@@ -4697,7 +4966,7 @@ export async function themeBuildFamily(
4697
4966
  }
4698
4967
  const file = source.file;
4699
4968
  // prettier-ignore
4700
- const member = await themeBuildInternal(file, {iconsSpecifier: options.iconsSpecifier, __prepareFamily: true, __familyLoader: familyLoader, __familyInterception: familyInterception, __onPrivateVarError: options.__onPrivateVarError}, {cwd});
4969
+ const member = await themeBuildInternal(file, {iconsSpecifier: options.iconsSpecifier}, {cwd}, {}, {prepareFamily: true, familyLoader, familyInterception});
4701
4970
  if (!member || member.type) {
4702
4971
  throw new AstryxError(
4703
4972
  `Theme family member "${file}" did not produce a complete build plan.`,
@@ -4871,7 +5140,7 @@ export async function themeBuildFamily(
4871
5140
  },
4872
5141
  {
4873
5142
  dest: cssDtsPath,
4874
- allowMissingInCheck: true,
5143
+ warnWhenMissing: true,
4875
5144
  content:
4876
5145
  generatedHeader(headerSource, 'ts', buildCommand, root.versions) +
4877
5146
  'export {};\n',
@@ -4928,18 +5197,21 @@ export async function themeBuildFamily(
4928
5197
  if (remedy) logger.error(`\n ${remedy.join('\n ')}`);
4929
5198
  else
4930
5199
  logger.error(
4931
- `\n Rebuild with: ${rebuildLine(rebuildCommand, options.__commandWords)}`,
5200
+ `\n Rebuild with: ${rebuildLine(rebuildCommand, handOff.commandWords)}`,
4932
5201
  );
4933
5202
  }
4934
- return {
5203
+ warnMissingDeclarations(writes, cwd);
5204
+ return /** @type {import('../theme.type.mjs').ThemeBuildCheckResponse} */ ({
4935
5205
  type: 'theme.build.check',
4936
5206
  data: {
4937
5207
  name: root.theme.name,
4938
5208
  upToDate,
4939
5209
  stale,
4940
5210
  checked: checkedBuildOutputs(writes, cwd),
5211
+ // The code a stale check exits 1 with, for --json callers.
5212
+ ...(upToDate ? {} : {code: ERROR_CODES.ERR_THEME_STALE}),
4941
5213
  },
4942
- };
5214
+ });
4943
5215
  }
4944
5216
  writeBuildOutputs(writes);
4945
5217
  for (const output of Object.values(outputs)) logger.log(`[ok] ${output}`);