@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
@@ -33,7 +33,10 @@ import * as fs from 'node:fs';
33
33
  import * as path from 'node:path';
34
34
  import {fileURLToPath} from 'node:url';
35
35
  import {spawn} from 'node:child_process';
36
- import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
36
+ import {
37
+ getCliInvocation,
38
+ quoteCommandArgument,
39
+ } from '../../../foundation/env/package-manager.mjs';
37
40
  import {isOutsideProject} from '../../../foundation/env/project-scope.mjs';
38
41
  import {jsonOut} from '../../../foundation/response/json.mjs';
39
42
  import {
@@ -46,7 +49,7 @@ import {
46
49
  list,
47
50
  } from '../formatters/index.mjs';
48
51
  import {logger} from '../../../api/logger.mjs';
49
- import {cliError} from '../lib/cli-error.mjs';
52
+ import {cliError, themeGroupUnknownSubcommand} from '../lib/cli-error.mjs';
50
53
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
51
54
  import {Project} from '../../../foundation/config/project.mjs';
52
55
  import {warnOnIntegrationIssues} from '../../../foundation/integrations/integration-warnings.mjs';
@@ -59,7 +62,10 @@ import {
59
62
  themeListAvailable,
60
63
  themeListCopySources,
61
64
  } from '../../../api/theme/list/list.mjs';
62
- import {themeTargets} from '../../../api/theme/targets/targets.mjs';
65
+ import {
66
+ normalizeTargetFilter,
67
+ themeTargets,
68
+ } from '../../../api/theme/targets/targets.mjs';
63
69
  import {
64
70
  serializePaletteCandidate,
65
71
  themePaletteGenerate,
@@ -70,6 +76,9 @@ import {
70
76
  themeBuild,
71
77
  themeBuildFamily,
72
78
  themeBuildForReport,
79
+ themeSourceFiles,
80
+ themeSourceGuesses,
81
+ writeDeferredBuildOutputs,
73
82
  } from '../../../api/theme/build/build.mjs';
74
83
  import {defineCommand} from '../lib/define-command.mjs';
75
84
  import {NO_RESULT_SET, resultSet} from '../../../foundation/debug/index.mjs';
@@ -101,29 +110,89 @@ import {doc as themePaletteGenerateFn} from '../../../api/theme/themePaletteGene
101
110
  * @typedef {object} ThemeCommandWords
102
111
  * @property {string} group - The group's command path: `theme` or `experimental theme`.
103
112
  * @property {string} build - The build subcommand's name: `build` or `compile`.
113
+ * @property {(err: import('../../../api/error.mjs').AstryxError, cwd: string) => import('../../../api/error.mjs').AstryxError | null} [explain] - A clearer refusal for this group, or null.
114
+ * @property {(files: string[], options: {cwd: string, check?: boolean, family?: boolean}) => Promise<import('../../../api/error.mjs').AstryxError | null>} [preflight] - A refusal before a build starts, or null.
115
+ * @property {(files: string[], options: {cwd: string}) => Promise<() => Promise<void>>} [hold] - Locks held while a build or check runs; resolves to their release.
104
116
  */
105
117
 
106
118
  /** @type {ThemeCommandWords} */
107
119
  const THEME_WORDS = {group: 'theme', build: 'build'};
108
120
 
121
+ /**
122
+ * Text as the group that ran the command words it: under `experimental
123
+ * theme`, the commands it names are that group's own (`build` is `compile`
124
+ * there). Only a command the CLI wrote is reworded: one after the CLI's
125
+ * name, or in backticks; text a person typed (a path, a name) stays as
126
+ * typed. Under `theme`, the text is unchanged.
127
+ * @param {string} text
128
+ * @param {ThemeCommandWords} words
129
+ */
130
+ function inGroupWords(text, words) {
131
+ if (words.group === THEME_WORDS.group) return text;
132
+ // An argument the person typed can hold the same words (a filter of
133
+ // `astryx theme list`); it is echoed as typed. Only an argument with a
134
+ // space or a backtick can match, and it is set aside only where the CLI
135
+ // echoes it: in double quotes, or as the argument after a subcommand.
136
+ const typed = [...new Set(process.argv.slice(2))]
137
+ .filter(arg => /[\s`]/.test(arg))
138
+ .sort((a, b) => b.length - a.length);
139
+ /** @type {string[]} */
140
+ const kept = [];
141
+ let masked = String(text);
142
+ for (const arg of typed) {
143
+ const escaped = arg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
144
+ masked = masked.replace(
145
+ new RegExp(
146
+ `(?<="|\\b(?:add|use|remove|eject|targets|template|build|compile) )${escaped}(?="|\`|\\s|$)`,
147
+ 'g',
148
+ ),
149
+ () => `\uE000${kept.push(arg) - 1}\uE001`,
150
+ );
151
+ }
152
+ return masked
153
+ .replace(
154
+ /((?:\bastryx|@astryxdesign\/cli@[\w.-]+) |`)theme (add|use|remove|list|build|eject|template|targets)\b/g,
155
+ (_, lead, sub) =>
156
+ `${lead}${words.group} ${sub === 'build' ? words.build : sub}`,
157
+ )
158
+ .replace(/\uE000(\d+)\uE001/g, (_, i) => kept[Number(i)]);
159
+ }
160
+
161
+ /**
162
+ * A theme app result with its notes in the words of the group that ran it.
163
+ * @template {{data: {notes?: string[]}}} R
164
+ * @param {R} result
165
+ * @param {ThemeCommandWords} words
166
+ * @returns {R}
167
+ */
168
+ function inGroupNotes(result, words) {
169
+ if (!result?.data?.notes || words.group === THEME_WORDS.group) return result;
170
+ return {
171
+ ...result,
172
+ data: {
173
+ ...result.data,
174
+ notes: result.data.notes.map(n => inGroupWords(n, words)),
175
+ },
176
+ };
177
+ }
178
+
109
179
  /**
110
180
  * A theme API refusal as the group that ran it words it: under
111
181
  * `experimental theme`, the commands it names are that group's own (`build`
112
182
  * is `compile` there). Under `theme`, the text is unchanged.
183
+ * A refusal that names no command gets `fallback`: a command of the same
184
+ * group that works whatever went wrong.
113
185
  * @param {import('../../../api/error.mjs').AstryxError} err
114
186
  * @param {ThemeCommandWords} [words]
187
+ * @param {Array<{name: string, reason: string}>} [fallback]
115
188
  */
116
- function themeError(err, words = THEME_WORDS) {
189
+ function themeError(err, words = THEME_WORDS, fallback = []) {
190
+ err = words.explain?.(err, process.cwd()) ?? err;
117
191
  /** @param {string} text */
118
- const local = text =>
119
- words.group === THEME_WORDS.group
120
- ? text
121
- : text.replace(
122
- /(?<!experimental )\btheme (add|use|remove|list|build|eject|template|targets)\b/g,
123
- (_, sub) => `${words.group} ${sub === 'build' ? words.build : sub}`,
124
- );
192
+ const local = text => inGroupWords(text, words);
193
+ const given = err.suggestions || [];
125
194
  return cliError(local(err.message), {
126
- suggestions: (err.suggestions || []).map(x => ({
195
+ suggestions: (given.length > 0 ? given : fallback).map(x => ({
127
196
  ...x,
128
197
  name: local(x.name),
129
198
  ...(x.reason ? {reason: local(x.reason)} : {}),
@@ -132,6 +201,27 @@ function themeError(err, words = THEME_WORDS) {
132
201
  });
133
202
  }
134
203
 
204
+ /**
205
+ * A command of this CLI as this project runs it, each argument quoted for the
206
+ * shell.
207
+ * @param {ThemeCommandWords} words
208
+ * @param {string} sub the subcommand, such as `list` or the build word
209
+ * @param {string[]} [args]
210
+ * @param {string} reason
211
+ * @returns {{name: string, reason: string}}
212
+ */
213
+ function themeCommand(words, sub, args = [], reason = '') {
214
+ return {
215
+ name: [
216
+ getCliInvocation(process.cwd()),
217
+ words.group,
218
+ sub,
219
+ ...args.map(arg => quoteCommandArgument(arg)),
220
+ ].join(' '),
221
+ reason,
222
+ };
223
+ }
224
+
135
225
  /**
136
226
  * Path to this CLI's real entry (clients/cli/bin/astryx.mjs), resolved from
137
227
  * this module's location (clients/cli/commands/theme.mjs → ../bin/
@@ -241,6 +331,8 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
241
331
  building = false;
242
332
  // A stop during this build has already ended the watch.
243
333
  if (stopped) return;
334
+ // The rebuilt source may import other files now.
335
+ watchSourceFiles(entry);
244
336
  emit(text(watchingLine));
245
337
  const next = queued.values().next();
246
338
  if (!next.done) {
@@ -249,21 +341,56 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
249
341
  }
250
342
  };
251
343
 
252
- // Some editors replace the file (rename) rather than writing in place, which
253
- // can drop the watch. Watch the containing directory and filter to our file
254
- // so edits survive atomic-save/rename.
255
- const watchers = entries.map(entry => {
256
- const baseName = path.basename(entry.filePath);
257
- return fs.watch(path.dirname(entry.filePath), (_eventType, changed) => {
258
- if (changed && changed !== baseName) return;
259
- clearTimeout(debounces.get(entry.filePath));
260
- // Debounce: editors often emit several events per save.
261
- debounces.set(
262
- entry.filePath,
263
- setTimeout(() => rebuild(entry), 100),
264
- );
265
- });
266
- });
344
+ // A theme is its source and the local files it imports (an ejected fork's
345
+ // palettes, a split theme); a change to any of them rebuilds it. Some
346
+ // editors replace a file (rename) rather than write in place, which can drop
347
+ // a file watch, so each containing folder is watched and filtered by name.
348
+ /** @type {Map<{file: string, filePath: string}, Set<string>>} */
349
+ const sourceFiles = new Map();
350
+ /** @type {Map<string, import('node:fs').FSWatcher>} */
351
+ const folderWatchers = new Map();
352
+ /** @param {{file: string, filePath: string}} entry */
353
+ const changed = entry => {
354
+ clearTimeout(debounces.get(entry.filePath));
355
+ // Debounce: editors often emit several events per save.
356
+ debounces.set(
357
+ entry.filePath,
358
+ setTimeout(() => rebuild(entry), 100),
359
+ );
360
+ };
361
+ /** @param {string} dir */
362
+ const watchFolder = dir => {
363
+ if (folderWatchers.has(dir)) return;
364
+ folderWatchers.set(
365
+ dir,
366
+ fs.watch(dir, (_eventType, name) => {
367
+ const file = name ? path.join(dir, name.toString()) : null;
368
+ for (const [entry, files] of sourceFiles) {
369
+ if (
370
+ file
371
+ ? files.has(file)
372
+ : [...files].some(f => path.dirname(f) === dir)
373
+ ) {
374
+ changed(entry);
375
+ }
376
+ }
377
+ }),
378
+ );
379
+ };
380
+ /** @param {{file: string, filePath: string}} entry */
381
+ function watchSourceFiles(entry) {
382
+ const files = new Set(themeSourceFiles(entry.filePath));
383
+ files.add(path.resolve(entry.filePath));
384
+ sourceFiles.set(entry, files);
385
+ for (const file of files) {
386
+ try {
387
+ watchFolder(path.dirname(file));
388
+ } catch {
389
+ // A folder that went away is watched again after the next build.
390
+ }
391
+ }
392
+ }
393
+ for (const entry of entries) watchSourceFiles(entry);
267
394
 
268
395
  // Announce readiness only AFTER fs.watch is armed — the log is the "safe to
269
396
  // edit" signal (tests and humans rely on it), so printing it before the watch
@@ -281,7 +408,7 @@ async function runThemeBuildWatch(entries, options, words = THEME_WORDS) {
281
408
  stopped = true;
282
409
  queued.clear();
283
410
  for (const d of debounces.values()) clearTimeout(d);
284
- for (const w of watchers) w.close();
411
+ for (const w of folderWatchers.values()) w.close();
285
412
  // A rebuild in progress would otherwise keep the process alive after
286
413
  // "Stopped watching.". In a terminal, Ctrl-C already reached it.
287
414
  rebuildChild?.kill(signal);
@@ -518,7 +645,7 @@ function printThemeEject(result, words = THEME_WORDS) {
518
645
  ]
519
646
  : []),
520
647
  text(
521
- `This is a local fork. Build it with ${getCliInvocation()} ${words.group} ${words.build} ${path.join(data.outputDir, data.entry)}.`,
648
+ `This is a local fork. Build it with ${getCliInvocation()} ${words.group} ${words.build} ${quoteCommandArgument(path.join(data.outputDir, data.entry).split(path.sep).join('/'))}.`,
522
649
  ),
523
650
  );
524
651
  }
@@ -566,13 +693,13 @@ export function registerTheme(program) {
566
693
  // us as a positional in cmd.args — exit 1 with a clear error.
567
694
  const extras = (cmd && cmd.args) || [];
568
695
  if (extras.length > 0) {
569
- const unknown = String(extras[0]);
570
- const known = (theme.commands || []).map(c => c.name());
571
- const suggestions = known.map(name => ({
572
- name,
573
- reason: 'available subcommand',
574
- }));
575
- return cliError(`unknown subcommand 'theme ${unknown}'`, {
696
+ const {message, suggestions} = themeGroupUnknownSubcommand(
697
+ 'theme',
698
+ String(extras[0]),
699
+ (theme.commands || []).map(c => c.name()),
700
+ theme,
701
+ );
702
+ return cliError(message, {
576
703
  suggestions,
577
704
  code: ERROR_CODES.ERR_UNKNOWN_SUBCOMMAND,
578
705
  });
@@ -730,7 +857,7 @@ function registerPaletteCommands(
730
857
  * @param {ThemeCommandWords} words
731
858
  */
732
859
  function registerThemeCommands(theme, program, docs, words) {
733
- defineCommand(theme, docs.build, {
860
+ const buildCli = defineCommand(theme, docs.build, {
734
861
  fn: themeBuildFn,
735
862
  action: async (
736
863
  /** @type {string[]} */ files,
@@ -754,28 +881,98 @@ function registerThemeCommands(theme, program, docs, words) {
754
881
  // A quoted glob reaches us unexpanded: say so rather than reporting a
755
882
  // literal `themes/*.ts` as a missing file.
756
883
  const looksGlobby = /[*?[\]{}]/.test(entry.file);
884
+ const guesses = looksGlobby
885
+ ? []
886
+ : themeSourceGuesses(entry.file, process.cwd());
757
887
  return cliError(`File not found: ${entry.filePath}`, {
758
888
  code: ERROR_CODES.ERR_FILE_NOT_FOUND,
759
889
  suggestions: looksGlobby
760
890
  ? [
761
891
  {
762
- name: `astryx ${words.group} ${words.build} ${entry.file.replace(/['"]/g, '')}`,
892
+ // The pattern stays unquoted: the shell expands it.
893
+ name: `${getCliInvocation(process.cwd())} ${words.group} ${words.build} ${entry.file.replace(/['"]/g, '')}`,
763
894
  reason:
764
895
  'globs are expanded by your shell; pass the pattern unquoted, or list the files',
765
896
  },
766
897
  ]
767
- : undefined,
898
+ : guesses.length > 0
899
+ ? guesses.map(guess => ({
900
+ name: `${getCliInvocation(process.cwd())} ${words.group} ${words.build} ${quoteCommandArgument(guess)}`,
901
+ reason: 'a theme source that exists',
902
+ }))
903
+ : [
904
+ themeCommand(
905
+ words,
906
+ 'template',
907
+ ['theme.template.ts'],
908
+ 'start a theme source from the annotated template',
909
+ ),
910
+ ],
768
911
  });
769
912
  }
770
913
 
914
+ /**
915
+ * This build again without some of its options, as the way out of a
916
+ * refusal about how they combine.
917
+ * @param {Array<'out' | 'watch' | 'check' | 'family'>} drop
918
+ * @param {string} reason
919
+ * @param {string[]} [only] the files to build, when not all of them
920
+ */
921
+ const buildWithout = (drop, reason, only = files) =>
922
+ themeCommand(
923
+ words,
924
+ words.build,
925
+ [
926
+ ...(options.family && !drop.includes('family')
927
+ ? ['--family', ...only, '--family-key', String(options.familyKey)]
928
+ : only),
929
+ ...(options.out && !drop.includes('out')
930
+ ? ['--out', options.out]
931
+ : []),
932
+ ...(options.check && !drop.includes('check') ? ['--check'] : []),
933
+ ...(options.watch && !drop.includes('watch') ? ['--watch'] : []),
934
+ ...(options.iconsSpecifier
935
+ ? ['--icons-specifier', options.iconsSpecifier]
936
+ : []),
937
+ ],
938
+ reason,
939
+ );
940
+
941
+ // A refusal from the build that names no command: without --out the
942
+ // outputs go beside the source; otherwise the annotated template shows
943
+ // a theme source that builds.
944
+ const buildFallback = options.out
945
+ ? [buildWithout(['out'], 'write the outputs beside the source')]
946
+ : [
947
+ themeCommand(
948
+ words,
949
+ 'template',
950
+ ['theme.template.ts'],
951
+ 'an annotated theme source that builds, to compare with',
952
+ ),
953
+ ];
954
+
771
955
  // One file passed twice would build twice and report two themes.
772
956
  const seenFiles = new Set();
773
957
  for (const entry of entries) {
774
958
  const key = fs.realpathSync(entry.filePath);
775
959
  if (seenFiles.has(key)) {
960
+ const once = entries
961
+ .filter(
962
+ (other, index) =>
963
+ entries.findIndex(
964
+ first =>
965
+ fs.realpathSync(first.filePath) ===
966
+ fs.realpathSync(other.filePath),
967
+ ) === index,
968
+ )
969
+ .map(other => other.file);
776
970
  return cliError(
777
971
  `${entry.file} is given more than once. Select each theme file once.`,
778
- {code: ERROR_CODES.ERR_THEME_INVALID},
972
+ {
973
+ code: ERROR_CODES.ERR_THEME_INVALID,
974
+ suggestions: [buildWithout([], 'each file once', once)],
975
+ },
779
976
  );
780
977
  }
781
978
  seenFiles.add(key);
@@ -789,17 +986,40 @@ function registerThemeCommands(theme, program, docs, words) {
789
986
  options.family
790
987
  ? '--family requires --family-key <key>'
791
988
  : '--family-key requires --family',
792
- {code: ERROR_CODES.ERR_THEME_INVALID},
989
+ {
990
+ code: ERROR_CODES.ERR_THEME_INVALID,
991
+ suggestions: [
992
+ {
993
+ ...themeCommand(
994
+ words,
995
+ words.build,
996
+ [
997
+ ...files,
998
+ // --out names one output, so it goes with one file only.
999
+ ...(options.out && files.length === 1
1000
+ ? ['--out', options.out]
1001
+ : []),
1002
+ ...(options.check ? ['--check'] : []),
1003
+ ],
1004
+ 'build each theme on its own',
1005
+ ),
1006
+ },
1007
+ ],
1008
+ },
793
1009
  );
794
1010
  }
795
1011
  if (options.family && options.out) {
796
1012
  return cliError('--family cannot be combined with --out', {
797
1013
  code: ERROR_CODES.ERR_THEME_INVALID,
1014
+ suggestions: [
1015
+ buildWithout(['out'], 'family outputs go beside the family root'),
1016
+ ],
798
1017
  });
799
1018
  }
800
1019
  if (options.family && options.watch) {
801
1020
  return cliError('--family cannot be combined with --watch', {
802
1021
  code: ERROR_CODES.ERR_THEME_INVALID,
1022
+ suggestions: [buildWithout(['watch'], 'build the family once')],
803
1023
  });
804
1024
  }
805
1025
 
@@ -808,6 +1028,7 @@ function registerThemeCommands(theme, program, docs, words) {
808
1028
  if (options.check && options.watch) {
809
1029
  return cliError('--check cannot be combined with --watch', {
810
1030
  code: ERROR_CODES.ERR_THEME_INVALID,
1031
+ suggestions: [buildWithout(['watch'], 'check once')],
811
1032
  });
812
1033
  }
813
1034
 
@@ -819,7 +1040,15 @@ function registerThemeCommands(theme, program, docs, words) {
819
1040
  `--out takes a single output path and ${entries.length} theme files were given. ` +
820
1041
  'Build them without --out (each theme writes <name>.css next to its source), ' +
821
1042
  'or run one invocation per theme.',
822
- {code: ERROR_CODES.ERR_THEME_INVALID},
1043
+ {
1044
+ code: ERROR_CODES.ERR_THEME_INVALID,
1045
+ suggestions: [
1046
+ buildWithout(
1047
+ ['out'],
1048
+ 'each theme writes <name>.css next to its source',
1049
+ ),
1050
+ ],
1051
+ },
823
1052
  );
824
1053
  }
825
1054
 
@@ -830,6 +1059,9 @@ function registerThemeCommands(theme, program, docs, words) {
830
1059
  if (json) {
831
1060
  return cliError('--watch is not supported with --json', {
832
1061
  code: ERROR_CODES.ERR_THEME_INVALID,
1062
+ suggestions: [
1063
+ buildWithout(['watch'], 'build once, with a JSON result'),
1064
+ ],
833
1065
  });
834
1066
  }
835
1067
  await runThemeBuildWatch(entries, {...options, detail}, words);
@@ -847,6 +1079,13 @@ function registerThemeCommands(theme, program, docs, words) {
847
1079
  privateVarError = true;
848
1080
  };
849
1081
 
1082
+ const refused = await words.preflight?.(files, {
1083
+ cwd: process.cwd(),
1084
+ check: options.check,
1085
+ family: Boolean(options.family),
1086
+ });
1087
+ if (refused) return themeError(refused, words, buildFallback);
1088
+
850
1089
  if (options.family) {
851
1090
  try {
852
1091
  const result = await themeBuildFamily(
@@ -856,6 +1095,7 @@ function registerThemeCommands(theme, program, docs, words) {
856
1095
  check: options.check,
857
1096
  iconsSpecifier: options.iconsSpecifier,
858
1097
  __onPrivateVarError: onPrivateVarError,
1098
+ __commandWords: words,
859
1099
  },
860
1100
  {cwd: process.cwd()},
861
1101
  );
@@ -870,10 +1110,9 @@ function registerThemeCommands(theme, program, docs, words) {
870
1110
  } catch (e) {
871
1111
  const err =
872
1112
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
873
- return cliError(err.message, {
874
- suggestions: err.suggestions,
875
- code: err.code,
876
- });
1113
+ return themeError(err, words, [
1114
+ buildWithout(['family'], 'build each theme on its own'),
1115
+ ]);
877
1116
  }
878
1117
  }
879
1118
 
@@ -885,9 +1124,50 @@ function registerThemeCommands(theme, program, docs, words) {
885
1124
  /** @type {Array<{file: string, receipt: import('../../../api/theme/theme.type.mjs').ThemeBuildResponse | import('../../../api/theme/theme.type.mjs').ThemeBuildCheckResponse | null}>} */
886
1125
  const results = [];
887
1126
  let stale = false;
1127
+ // A batch builds every theme first and then writes them in order, so
1128
+ // two themes that build the same files are refused before either
1129
+ // writes. Any other failure writes the themes built before it, as a
1130
+ // shell loop under `set -e` would have, and stops.
1131
+ const deferred = !options.check && entries.length > 1;
1132
+ // Each built theme keeps its writes and what it prints together; what
1133
+ // it prints waits until its outputs are written, so no `[ok]` line
1134
+ // names a file that is never written.
1135
+ /** @type {Array<{writes: Array<Array<{dest: string, content: string}>>, lines: Array<() => void>}>} */
1136
+ const built = [];
1137
+ const publish = () => {
1138
+ for (const theme of built.splice(0)) {
1139
+ writeDeferredBuildOutputs(theme.writes);
1140
+ for (const show of theme.lines) show();
1141
+ }
1142
+ };
1143
+ const writeFailed = (/** @type {unknown} */ error) =>
1144
+ themeError(
1145
+ /** @type {import('../../../api/error.mjs').AstryxError} */ (error),
1146
+ words,
1147
+ [
1148
+ buildWithout(
1149
+ [],
1150
+ 'run the same build again once the files can be written',
1151
+ ),
1152
+ ],
1153
+ );
888
1154
  /** @type {Map<string, string>} */
889
1155
  const claimedOutputs = new Map();
890
1156
  for (const entry of entries) {
1157
+ /** @type {Array<() => void>} */
1158
+ const lines = [];
1159
+ /** @type {Array<Array<{dest: string, content: string}>>} */
1160
+ const writes = [];
1161
+ const log = logger.log;
1162
+ const warn = logger.warn;
1163
+ if (deferred) {
1164
+ logger.log = (/** @type {string | undefined} */ message) => {
1165
+ lines.push(() => log.call(logger, message));
1166
+ };
1167
+ logger.warn = (/** @type {string | undefined} */ message) => {
1168
+ lines.push(() => warn.call(logger, message));
1169
+ };
1170
+ }
891
1171
  try {
892
1172
  const buildOptions = {
893
1173
  out: options.out,
@@ -895,6 +1175,8 @@ function registerThemeCommands(theme, program, docs, words) {
895
1175
  iconsSpecifier: options.iconsSpecifier,
896
1176
  __onPrivateVarError: onPrivateVarError,
897
1177
  __claimedOutputs: claimedOutputs,
1178
+ __deferredWrites: deferred ? writes : undefined,
1179
+ __commandWords: words,
898
1180
  };
899
1181
  let result;
900
1182
  if (report) {
@@ -908,18 +1190,24 @@ function registerThemeCommands(theme, program, docs, words) {
908
1190
  if (built.trailer) trailers.push(built.trailer);
909
1191
  if (compact && result?.type === 'theme.build') {
910
1192
  const {outputs, sizeKB, tokenCount, componentCount} = result.data;
911
- emit(
912
- text(
913
- `[ok] ${outputs.css} (${sizeKB} KB, ${tokenCount} token overrides, ${componentCount} component overrides)`,
914
- ),
915
- );
1193
+ const show = () =>
1194
+ emit(
1195
+ text(
1196
+ `[ok] ${outputs.css} (${sizeKB} KB, ${tokenCount} token overrides, ${componentCount} component overrides)`,
1197
+ ),
1198
+ );
1199
+ if (deferred) lines.push(show);
1200
+ else show();
916
1201
  }
917
1202
  } else {
918
1203
  result = await themeBuild(entry.file, buildOptions, {
919
1204
  cwd: process.cwd(),
920
1205
  });
921
1206
  }
1207
+ logger.log = log;
1208
+ logger.warn = warn;
922
1209
  results.push({file: entry.file, receipt: result ?? null});
1210
+ if (deferred) built.push({writes, lines});
923
1211
  if (
924
1212
  options.check &&
925
1213
  result &&
@@ -929,18 +1217,44 @@ function registerThemeCommands(theme, program, docs, words) {
929
1217
  stale = true;
930
1218
  }
931
1219
  } catch (e) {
1220
+ logger.log = log;
1221
+ logger.warn = warn;
932
1222
  const err =
933
1223
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
934
1224
  // Stop at the first failure, as a shell loop under `set -e` does.
935
1225
  // With several themes in flight the message alone rarely says which
936
1226
  // one broke, so name it. Themes already written keep their install
937
1227
  // and font guidance.
1228
+ if (/** @type {any} */ (err).outputCollision) {
1229
+ // Nothing is written, so only this theme's warnings are shown.
1230
+ for (const show of lines) show();
1231
+ return themeError(err, words, [
1232
+ buildWithout([], 'build the first theme on its own', [
1233
+ entries[0].file,
1234
+ ]),
1235
+ ]);
1236
+ }
1237
+ if (deferred) {
1238
+ try {
1239
+ publish();
1240
+ } catch (writeError) {
1241
+ return writeFailed(writeError);
1242
+ }
1243
+ // The failing theme's warnings, such as a missing package, say
1244
+ // why it failed.
1245
+ for (const show of lines) show();
1246
+ }
938
1247
  if (report && compact) printCompactTrailer(trailers);
939
1248
  else if (report) printBatchTrailer(trailers);
940
- return cliError(
941
- entries.length > 1 ? `${entry.file}: ${err.message}` : err.message,
942
- {suggestions: err.suggestions, code: err.code},
943
- );
1249
+ if (entries.length > 1) err.message = `${entry.file}: ${err.message}`;
1250
+ return themeError(err, words, buildFallback);
1251
+ }
1252
+ }
1253
+ if (deferred) {
1254
+ try {
1255
+ publish();
1256
+ } catch (e) {
1257
+ return writeFailed(e);
944
1258
  }
945
1259
  }
946
1260
 
@@ -986,6 +1300,22 @@ function registerThemeCommands(theme, program, docs, words) {
986
1300
  return NO_RESULT_SET;
987
1301
  },
988
1302
  });
1303
+ // A group may hold locks while a build or check runs (the editor's theme
1304
+ // lock), so it never reads a change half written.
1305
+ if (words.hold) {
1306
+ /** @type {(() => Promise<void>) | undefined} */
1307
+ let release;
1308
+ buildCli.hook('preAction', async (_, cmd) => {
1309
+ // Under --watch each rebuild runs on its own and takes the locks
1310
+ // itself; holding them for the whole watch would block every one.
1311
+ if (cmd.opts().watch) return;
1312
+ release = await words.hold?.(cmd.args, {cwd: process.cwd()});
1313
+ });
1314
+ buildCli.hook('postAction', async () => {
1315
+ await release?.();
1316
+ release = undefined;
1317
+ });
1318
+ }
989
1319
 
990
1320
  const listCli = defineCommand(theme, docs.list, {
991
1321
  fn: themeListFn,
@@ -1001,7 +1331,14 @@ function registerThemeCommands(theme, program, docs, words) {
1001
1331
  } catch (e) {
1002
1332
  const err =
1003
1333
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1004
- return themeError(err, words);
1334
+ return themeError(err, words, [
1335
+ options.package
1336
+ ? themeCommand(words, 'list', [], 'every theme, from every package')
1337
+ : {
1338
+ name: `${getCliInvocation(process.cwd())} doctor`,
1339
+ reason: 'names the integration or theme that is broken',
1340
+ },
1341
+ ]);
1005
1342
  }
1006
1343
 
1007
1344
  await warnOnThemeIntegrationIssues(json);
@@ -1048,7 +1385,9 @@ function registerThemeCommands(theme, program, docs, words) {
1048
1385
  } catch (e) {
1049
1386
  const err =
1050
1387
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1051
- return themeError(err, words);
1388
+ return themeError(err, words, [
1389
+ themeCommand(words, 'list', [], 'the themes you can add'),
1390
+ ]);
1052
1391
  }
1053
1392
 
1054
1393
  await warnOnThemeIntegrationIssues(json);
@@ -1057,6 +1396,10 @@ function registerThemeCommands(theme, program, docs, words) {
1057
1396
  ? resultSet({count: result.data.length, resultKind: 'theme'})
1058
1397
  : NO_RESULT_SET;
1059
1398
 
1399
+ if (result.type !== 'theme.list')
1400
+ result = /** @type {any} */ (
1401
+ inGroupNotes(/** @type {any} */ (result), words)
1402
+ );
1060
1403
  if (json) {
1061
1404
  jsonOut(result);
1062
1405
  return answered;
@@ -1083,9 +1426,12 @@ function registerThemeCommands(theme, program, docs, words) {
1083
1426
  } catch (e) {
1084
1427
  const err =
1085
1428
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1086
- return themeError(err, words);
1429
+ return themeError(err, words, [
1430
+ themeCommand(words, 'list', [], 'the themes this app has added'),
1431
+ ]);
1087
1432
  }
1088
1433
  await warnOnThemeIntegrationIssues(json);
1434
+ result = inGroupNotes(result, words);
1089
1435
  if (json) jsonOut(result);
1090
1436
  else printThemeApp(result);
1091
1437
  return NO_RESULT_SET;
@@ -1103,9 +1449,12 @@ function registerThemeCommands(theme, program, docs, words) {
1103
1449
  } catch (e) {
1104
1450
  const err =
1105
1451
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1106
- return themeError(err, words);
1452
+ return themeError(err, words, [
1453
+ themeCommand(words, 'list', [], 'the themes this app has added'),
1454
+ ]);
1107
1455
  }
1108
1456
  await warnOnThemeIntegrationIssues(json);
1457
+ result = inGroupNotes(result, words);
1109
1458
  if (json) jsonOut(result);
1110
1459
  else printThemeApp(result);
1111
1460
  return NO_RESULT_SET;
@@ -1132,7 +1481,9 @@ function registerThemeCommands(theme, program, docs, words) {
1132
1481
  } catch (e) {
1133
1482
  const err =
1134
1483
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1135
- return themeError(err, words);
1484
+ return themeError(err, words, [
1485
+ themeCommand(words, 'list', [], 'the themes you can fork'),
1486
+ ]);
1136
1487
  }
1137
1488
  await warnOnThemeIntegrationIssues(json);
1138
1489
  if (json) jsonOut(result);
@@ -1160,7 +1511,14 @@ function registerThemeCommands(theme, program, docs, words) {
1160
1511
  } catch (e) {
1161
1512
  const err =
1162
1513
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1163
- return themeError(err, words);
1514
+ return themeError(err, words, [
1515
+ themeCommand(
1516
+ words,
1517
+ 'template',
1518
+ ['theme.template.ts'],
1519
+ 'write the template at the project root',
1520
+ ),
1521
+ ]);
1164
1522
  }
1165
1523
 
1166
1524
  // Writes a starter theme file, or declines to overwrite one.
@@ -1171,9 +1529,19 @@ function registerThemeCommands(theme, program, docs, words) {
1171
1529
 
1172
1530
  const invocation = getCliInvocation(process.cwd());
1173
1531
  if (!result.data.written) {
1532
+ const {overwritable, alternative} = result.data;
1174
1533
  emit(
1175
1534
  text(`[skip] ${result.data.path} already exists — left as is.`),
1176
- text(`Pass --overwrite to replace it with a fresh copy.`),
1535
+ ...(overwritable === false && alternative
1536
+ ? [
1537
+ text(
1538
+ 'It is not a theme template that --overwrite may replace. Write the template to a new file:',
1539
+ ),
1540
+ code(
1541
+ `${invocation} ${words.group} template ${quoteCommandArgument(alternative)}`,
1542
+ ),
1543
+ ]
1544
+ : [text(`Pass --overwrite to replace it with a fresh copy.`)]),
1177
1545
  );
1178
1546
  return NO_RESULT_SET;
1179
1547
  }
@@ -1183,7 +1551,9 @@ function registerThemeCommands(theme, program, docs, words) {
1183
1551
  'It documents every defineTheme field, the token families, and the component override syntax. ' +
1184
1552
  'Copy what you need into your own theme file, then delete it.',
1185
1553
  ),
1186
- code(`${invocation} ${words.group} ${words.build} ${result.data.path}`),
1554
+ code(
1555
+ `${invocation} ${words.group} ${words.build} ${quoteCommandArgument(result.data.path)}`,
1556
+ ),
1187
1557
  );
1188
1558
  return NO_RESULT_SET;
1189
1559
  },
@@ -1201,7 +1571,9 @@ function registerThemeCommands(theme, program, docs, words) {
1201
1571
  } catch (e) {
1202
1572
  const err =
1203
1573
  /** @type {import('../../../api/error.mjs').AstryxError} */ (e);
1204
- return themeError(err, words);
1574
+ return themeError(err, words, [
1575
+ themeCommand(words, 'targets', [], 'every theming target'),
1576
+ ]);
1205
1577
  }
1206
1578
 
1207
1579
  // A filter is a substring search with an exact-name fast path (see
@@ -1212,15 +1584,16 @@ function registerThemeCommands(theme, program, docs, words) {
1212
1584
  const matched = new Set(
1213
1585
  result.data.targets.map(target => target.component.toLowerCase()),
1214
1586
  );
1587
+ const needle = normalizeTargetFilter(filter);
1215
1588
  const answered = resultSet({
1216
1589
  count: result.data.targets.length,
1217
1590
  resultKind: 'theme',
1218
1591
  // Falsy, not just null: the api treats an empty filter as no filter
1219
1592
  // at all, so recording one as a match that missed would invent a
1220
1593
  // failed lookup out of a run that never looked anything up.
1221
- directMatch: !filter
1594
+ directMatch: !needle
1222
1595
  ? undefined
1223
- : matched.size === 1 && matched.has(String(filter).toLowerCase()),
1596
+ : matched.size === 1 && matched.has(needle),
1224
1597
  });
1225
1598
  if (json) {
1226
1599
  jsonOut(result);