@astryxdesign/cli 0.7.17-canary.g5e463b2 → 0.7.17-canary.g8d3e010

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 (49) hide show
  1. package/api/theme/build/build.d.mts +18 -8
  2. package/api/theme/build/build.mjs +90 -28
  3. package/api/theme/build/font-warning.d.mts +10 -1
  4. package/api/theme/build/font-warning.mjs +22 -1
  5. package/api/theme/build/icon-imports.mjs +25 -2
  6. package/api/theme-edit/_adapter.d.mts +14 -3
  7. package/api/theme-edit/_adapter.mjs +76 -26
  8. package/api/theme-edit/_check.d.mts +14 -0
  9. package/api/theme-edit/_check.mjs +268 -155
  10. package/api/theme-edit/_compiler.mjs +72 -6
  11. package/api/theme-edit/_context.mjs +58 -28
  12. package/api/theme-edit/_edit.d.mts +11 -0
  13. package/api/theme-edit/_edit.mjs +435 -75
  14. package/api/theme-edit/_how-commands.mjs +67 -9
  15. package/api/theme-edit/_how-question.mjs +789 -85
  16. package/api/theme-edit/_how.mjs +7 -1
  17. package/api/theme-edit/_normal.d.mts +22 -0
  18. package/api/theme-edit/_normal.mjs +113 -4
  19. package/api/theme-edit/_parts.d.mts +8 -0
  20. package/api/theme-edit/_parts.mjs +28 -22
  21. package/api/theme-edit/_preview-app.mjs +85 -19
  22. package/api/theme-edit/_preview.mjs +4 -2
  23. package/api/theme-edit/_project.d.mts +4 -0
  24. package/api/theme-edit/_project.mjs +3 -1
  25. package/api/theme-edit/_settings.d.mts +47 -38
  26. package/api/theme-edit/_settings.mjs +332 -337
  27. package/api/theme-edit/_tables.d.mts +9 -0
  28. package/api/theme-edit/_tables.mjs +19 -0
  29. package/api/theme-edit/_vet.d.mts +3 -1
  30. package/api/theme-edit/_vet.mjs +19 -6
  31. package/assets/component-list.generated.json +1 -1
  32. package/assets/docs.generated.json +2 -2
  33. package/assets/search-catalog.generated.json +2 -2
  34. package/assets/self-audit.generated.json +1 -1
  35. package/clients/cli/build-id.generated.json +1 -1
  36. package/clients/cli/commands/experimental/theme.mjs +171 -85
  37. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  38. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  39. package/clients/cli/commands/theme.mjs +22 -54
  40. package/clients/cli/lib/json-shim.mjs +16 -1
  41. package/clients/cli/manifest.generated.json +1 -1
  42. package/foundation/discovery/template-adapter.d.mts +1 -1
  43. package/foundation/fs/exact-codec.d.mts +12 -2
  44. package/foundation/fs/exact-codec.mjs +23 -6
  45. package/foundation/fs/gather-cache.mjs +27 -12
  46. package/foundation/fs/stop-cleanup.d.mts +12 -0
  47. package/foundation/fs/stop-cleanup.mjs +66 -0
  48. package/foundation/render/render-page.mjs +353 -82
  49. package/package.json +6 -6
@@ -181,20 +181,29 @@ export function importSpecifier(relDir: string, base: string): string;
181
181
  /**
182
182
  * Load a theme module as a standalone build of it loads it (the Core the
183
183
  * build selects, the same loader and interception) and name the export the
184
- * build reads, with the theme its definition extends (`parent`, the exact
185
- * authored `extends` value, after every spread and repeated key). Callers
186
- * that must agree with the build on which theme a module defines read it
187
- * here, never from the module's text.
184
+ * build reads. Callers that must agree with the build on which theme a
185
+ * module defines read it here, never from the module's text.
186
+ *
187
+ * With `base`, also whether the theme extends that module's export, by
188
+ * identity, anywhere up its `extends` chain (`extendsBase`): the module is
189
+ * loaded once, and the theme module's imports of it (by any of
190
+ * `base.specifiers`) are handed that one load, so the answer is about the
191
+ * very object, not one that only looks like it.
188
192
  * @param {string} file
189
- * @param {{cwd?: string}} [ctx]
190
- * @returns {Promise<{theme: any, exportName: string, parent: any}>}
193
+ * @param {{cwd?: string, base?: {file: string, exportName: string, specifiers: string[]}}} [ctx]
194
+ * @returns {Promise<{theme: any, exportName: string, extendsBase?: boolean}>}
191
195
  */
192
- export function loadThemeExport(file: string, { cwd }?: {
196
+ export function loadThemeExport(file: string, { cwd, base }?: {
193
197
  cwd?: string;
198
+ base?: {
199
+ file: string;
200
+ exportName: string;
201
+ specifiers: string[];
202
+ };
194
203
  }): Promise<{
195
204
  theme: any;
196
205
  exportName: string;
197
- parent: any;
206
+ extendsBase?: boolean;
198
207
  }>;
199
208
  /**
200
209
  * The input a theme module gives `defineTheme()` for the theme a build of
@@ -475,6 +484,7 @@ export type ThemeBuildHandOff = {
475
484
  };
476
485
  colorModes?: ["light"] | ["dark"] | null;
477
486
  fontHelp?: FontHelp | null;
487
+ loadedFonts?: ((family: string) => boolean) | null;
478
488
  };
479
489
  /**
480
490
  * How a caller that loads a theme's fonts itself (the editor's app copy)
@@ -1208,7 +1208,7 @@ function assertThemeSourceFile(filePath, cwd, mode = {}) {
1208
1208
  * `familyInterception` make the build a family member's plan.
1209
1209
  * `colorModes` is the one color mode a calling command knows the theme has
1210
1210
  * (the theme editor, from its settings), written into the built module.
1211
- * @typedef {{prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}, colorModes?: ['light'] | ['dark'] | null, fontHelp?: FontHelp | null}} ThemeBuildHandOff
1211
+ * @typedef {{prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}, colorModes?: ['light'] | ['dark'] | null, fontHelp?: FontHelp | null, loadedFonts?: ((family: string) => boolean) | null}} ThemeBuildHandOff
1212
1212
  */
1213
1213
 
1214
1214
  /**
@@ -1345,11 +1345,12 @@ export function buildSuggestion(source, mode, cwd, words, shape = {}) {
1345
1345
  * @param {Array<{dest: string}>} writes
1346
1346
  * @param {string} filePath the theme source
1347
1347
  * @param {string} cwd
1348
- * @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void}} [options]
1348
+ * @param {{claimed?: Map<string, string>, rerun?: (out: string | null) => string, refuseUnmarked?: boolean, elsewhere?: string, onEditorFolder?: (warning: string) => void, onWarning?: (message: string) => void}} [options]
1349
1349
  * `claimed`: outputs written earlier in this run, by the source that wrote
1350
1350
  * them; `rerun`: this build's command with another --out, or without one;
1351
1351
  * `elsewhere`: the option that moves the outputs; `onEditorFolder`: takes
1352
- * the editor-folder warning instead of the logger (a watcher prints it once)
1352
+ * the editor-folder warning instead of the logger (a watcher prints it
1353
+ * once); `onWarning`: each warning's message too, for the result
1353
1354
  */
1354
1355
  function assertOutputsReplaceable(
1355
1356
  writes,
@@ -1361,6 +1362,7 @@ function assertOutputsReplaceable(
1361
1362
  refuseUnmarked = false,
1362
1363
  elsewhere = '--out',
1363
1364
  onEditorFolder,
1365
+ onWarning,
1364
1366
  } = {},
1365
1367
  ) {
1366
1368
  const rel = (/** @type {string} */ file) => path.relative(cwd, file);
@@ -1442,7 +1444,7 @@ function assertOutputsReplaceable(
1442
1444
  // It is printed after every output passes, so it names a replacement
1443
1445
  // that happens.
1444
1446
  if (warnedOtherSource) continue;
1445
- warnedOtherSource = `Warning: ${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`;
1447
+ warnedOtherSource = `${rel(write.dest)} was built from ${otherSource}; this build of ${rel(filePath)} replaces it.`;
1446
1448
  } else if (otherSource) {
1447
1449
  throw new AstryxError(
1448
1450
  `${rel(write.dest)} is the build output of another theme source, ${otherSource}, so this build does not replace it. Pick another ${elsewhere}.`,
@@ -1479,12 +1481,16 @@ function assertOutputsReplaceable(
1479
1481
  }
1480
1482
  // Warned only once nothing refuses the build, so it names a write that
1481
1483
  // happens.
1482
- if (warnedOtherSource) logger.warn(warnedOtherSource);
1484
+ if (warnedOtherSource) {
1485
+ logger.warn(`Warning: ${warnedOtherSource}`);
1486
+ onWarning?.(warnedOtherSource);
1487
+ }
1483
1488
  if (editorFolder) {
1484
1489
  const dir = path.dirname(writes[0].dest);
1485
- 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.`;
1486
- if (onEditorFolder) onEditorFolder(warning);
1487
- else logger.warn(warning);
1490
+ const message = `${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.`;
1491
+ if (onEditorFolder) onEditorFolder(`Warning: ${message}`);
1492
+ else logger.warn(`Warning: ${message}`);
1493
+ onWarning?.(message);
1488
1494
  }
1489
1495
  }
1490
1496
 
@@ -1576,7 +1582,31 @@ function writeBuildOutputs(writes) {
1576
1582
  })),
1577
1583
  );
1578
1584
  } catch (error) {
1579
- const message = `Failed to write theme outputs: ${/** @type {Error} */ (error).message}`;
1585
+ const e = /** @type {NodeJS.ErrnoException} */ (error);
1586
+ // A place the outputs cannot be written: name it and its fix (the
1587
+ // writes go through temporary files beside each output, whose names
1588
+ // help nobody).
1589
+ if (e.code === 'EACCES' || e.code === 'EPERM' || e.code === 'EROFS') {
1590
+ const failed = e.path ? path.resolve(e.path) : null;
1591
+ const output = writes.find(w => path.resolve(w.dest) === failed);
1592
+ const place = output
1593
+ ? output.dest
1594
+ : failed
1595
+ ? path.dirname(failed)
1596
+ : path.dirname(writes[0].dest);
1597
+ const shownPlace = path.relative(process.cwd(), place) || place;
1598
+ throw new AstryxError(
1599
+ `Could not write the theme's outputs: ${shownPlace} is not writable (${e.code}). Give yourself write permission on it (chmod u+w ${shellWord(shownPlace)}), then build again. Nothing was changed.`,
1600
+ [
1601
+ {
1602
+ name: `ls -ld ${shellWord(shownPlace)}`,
1603
+ reason: 'see its permissions',
1604
+ },
1605
+ ],
1606
+ ERROR_CODES.ERR_WRITE_FAILED,
1607
+ );
1608
+ }
1609
+ const message = `Failed to write theme outputs: ${e.message}`;
1580
1610
  throw new AstryxError(message, undefined, ERROR_CODES.ERR_WRITE_FAILED);
1581
1611
  }
1582
1612
  }
@@ -2983,34 +3013,61 @@ function standaloneInterception(filePath) {
2983
3013
  /**
2984
3014
  * Load a theme module as a standalone build of it loads it (the Core the
2985
3015
  * build selects, the same loader and interception) and name the export the
2986
- * build reads, with the theme its definition extends (`parent`, the exact
2987
- * authored `extends` value, after every spread and repeated key). Callers
2988
- * that must agree with the build on which theme a module defines read it
2989
- * here, never from the module's text.
3016
+ * build reads. Callers that must agree with the build on which theme a
3017
+ * module defines read it here, never from the module's text.
3018
+ *
3019
+ * With `base`, also whether the theme extends that module's export, by
3020
+ * identity, anywhere up its `extends` chain (`extendsBase`): the module is
3021
+ * loaded once, and the theme module's imports of it (by any of
3022
+ * `base.specifiers`) are handed that one load, so the answer is about the
3023
+ * very object, not one that only looks like it.
2990
3024
  * @param {string} file
2991
- * @param {{cwd?: string}} [ctx]
2992
- * @returns {Promise<{theme: any, exportName: string, parent: any}>}
3025
+ * @param {{cwd?: string, base?: {file: string, exportName: string, specifiers: string[]}}} [ctx]
3026
+ * @returns {Promise<{theme: any, exportName: string, extendsBase?: boolean}>}
2993
3027
  */
2994
- export async function loadThemeExport(file, {cwd = process.cwd()} = {}) {
3028
+ export async function loadThemeExport(file, {cwd = process.cwd(), base} = {}) {
2995
3029
  const filePath = path.resolve(cwd, file);
2996
3030
  await selectCore(cwd, {projectOnly: false});
2997
- const interception = standaloneInterception(filePath);
2998
3031
  const {theme, exportName = 'default'} = await extractThemeDefinition(
2999
3032
  filePath,
3000
- interception,
3033
+ standaloneInterception(filePath),
3001
3034
  );
3002
- if (interception)
3003
- return {theme, exportName, parent: interception.parentOf(theme)};
3004
- // A build without interception records no parent: the same export is
3005
- // read again through a recorder.
3035
+ if (!base) return {theme, exportName};
3006
3036
  const recorder = interceptCore(_coreThemeModule, _coreRootModule);
3037
+ const shared = (
3038
+ await extractThemeDefinition(
3039
+ path.resolve(cwd, base.file),
3040
+ recorder,
3041
+ undefined,
3042
+ base.exportName,
3043
+ )
3044
+ ).theme;
3045
+ const withBase = {
3046
+ ...recorder,
3047
+ modules: {
3048
+ ...recorder.modules,
3049
+ ...Object.fromEntries(
3050
+ base.specifiers.map(s => [s, {[base.exportName]: shared}]),
3051
+ ),
3052
+ },
3053
+ };
3007
3054
  const again = await extractThemeDefinition(
3008
3055
  filePath,
3009
- recorder,
3056
+ withBase,
3010
3057
  undefined,
3011
3058
  exportName,
3012
3059
  );
3013
- return {theme, exportName, parent: recorder.parentOf(again.theme)};
3060
+ let extendsBase = false;
3061
+ for (
3062
+ let at = recorder.parentOf(again.theme), depth = 0;
3063
+ at && depth < 64;
3064
+ at = recorder.parentOf(at), depth++
3065
+ )
3066
+ if (at === shared) {
3067
+ extendsBase = true;
3068
+ break;
3069
+ }
3070
+ return {theme, exportName, extendsBase};
3014
3071
  }
3015
3072
 
3016
3073
  /**
@@ -4636,9 +4693,10 @@ async function themeBuildInternal(
4636
4693
  .join(path.dirname(options.out), `${stem}.css`)
4637
4694
  .split(path.sep)
4638
4695
  .join('/');
4639
- logger.warn(
4640
- `Warning: --out names the stylesheet, which is CSS; give it a .css name such as ${fixed}.`,
4641
- );
4696
+ // The result's warnings say it too, as text does.
4697
+ const w = `--out names the stylesheet, which is CSS; give it a .css name such as ${fixed}.`;
4698
+ warningMessages.push(w);
4699
+ logger.warn(`Warning: ${w}`);
4642
4700
  }
4643
4701
  // A build keeps the explicit output inside the write root, relative or
4644
4702
  // absolute. Check mode writes nothing, so it refuses only a relative path
@@ -4728,6 +4786,8 @@ async function themeBuildInternal(
4728
4786
  ? `export declare const colorModes: readonly [${JSON.stringify(colorModes[0])}];\n`
4729
4787
  : '');
4730
4788
 
4789
+ // A family the caller knows the app loads (a font stylesheet it writes
4790
+ // for the theme) is not named as unloaded.
4731
4791
  const unloadedFonts = [
4732
4792
  ...new Set([
4733
4793
  ...collectUnloadedFonts(resolvedTheme),
@@ -4735,7 +4795,7 @@ async function themeBuildInternal(
4735
4795
  (/** @type {any} */ value) => collectUnloadedFonts(value),
4736
4796
  ),
4737
4797
  ]),
4738
- ];
4798
+ ].filter(family => !handOff.loadedFonts?.(family));
4739
4799
 
4740
4800
  if (handOff.prepareFamily) {
4741
4801
  return {
@@ -4788,6 +4848,8 @@ async function themeBuildInternal(
4788
4848
  rerun,
4789
4849
  refuseUnmarked: Boolean(options.out),
4790
4850
  onEditorFolder: editorFolderListener ?? undefined,
4851
+ // The result's warnings carry what text prints.
4852
+ onWarning: message => warningMessages.push(message),
4791
4853
  });
4792
4854
  }
4793
4855
 
@@ -8,9 +8,18 @@
8
8
  * @returns {string[]}
9
9
  */
10
10
  export function namedFontFamilies(value: string): string[];
11
+ /**
12
+ * The family list of a CSS `font` shorthand: what follows its size (and
13
+ * line height), as the shorthand's grammar puts it last. A system font
14
+ * keyword (`caption`, `menu`, ...) or a value with no size names none.
15
+ * @param {string} value
16
+ * @returns {string}
17
+ */
18
+ export function fontShorthandFamilyList(value: string): string;
11
19
  /**
12
20
  * Collect the font families a resolved theme names but does not load —
13
- * every `--font-family-*` token plus every component-override `fontFamily`,
21
+ * every `--font-family-*` token plus every component-override `fontFamily`
22
+ * and the families of a `font` shorthand,
14
23
  * minus generics, CSS-wide keywords, `var()` references, and known system
15
24
  * families. Source order, first-seen casing, deduped case-insensitively.
16
25
  *
@@ -146,9 +146,27 @@ export function namedFontFamilies(value) {
146
146
  );
147
147
  }
148
148
 
149
+ /**
150
+ * The family list of a CSS `font` shorthand: what follows its size (and
151
+ * line height), as the shorthand's grammar puts it last. A system font
152
+ * keyword (`caption`, `menu`, ...) or a value with no size names none.
153
+ * @param {string} value
154
+ * @returns {string}
155
+ */
156
+ export function fontShorthandFamilyList(value) {
157
+ // A size has a unit (a bare number is a weight); a line height may
158
+ // follow it after a slash.
159
+ const size =
160
+ /(?<=^|\s)(?:[+-]?(?:\d+\.?\d*|\.\d+)(?:[a-z]+|%)|xx-small|x-small|small|medium|large|x-large|xx-large|xxx-large|larger|smaller|(?:calc|clamp|min|max|var)\([^)]*\))(?:\s*\/\s*\S+)?\s+(?=\S)/i;
161
+ // The first size: a family name after it may hold anything.
162
+ const m = size.exec(String(value));
163
+ return m ? String(value).slice(m.index + m[0].length) : '';
164
+ }
165
+
149
166
  /**
150
167
  * Collect the font families a resolved theme names but does not load —
151
- * every `--font-family-*` token plus every component-override `fontFamily`,
168
+ * every `--font-family-*` token plus every component-override `fontFamily`
169
+ * and the families of a `font` shorthand,
152
170
  * minus generics, CSS-wide keywords, `var()` references, and known system
153
171
  * families. Source order, first-seen casing, deduped case-insensitively.
154
172
  *
@@ -202,6 +220,9 @@ export function collectUnloadedFonts(resolvedTheme) {
202
220
  if (!node || typeof node !== 'object') return;
203
221
  for (const [key, value] of Object.entries(node)) {
204
222
  if (key === 'fontFamily') consider(value);
223
+ // A `font` shorthand names its families last.
224
+ else if (key === 'font' && typeof value === 'string')
225
+ consider(fontShorthandFamilyList(value));
205
226
  else walk(value);
206
227
  }
207
228
  };
@@ -160,6 +160,19 @@ export async function resolveIconImports(
160
160
  const defaultName = staticSlots ? 'themeComponentIcons' : 'themeIcons';
161
161
  /** @param {string} [name] @param {string} [reason] @returns {never} */
162
162
  const invalidRegistry = (name, reason) => registryError(name, reason, field);
163
+ /**
164
+ * A theme written as an expression the build does not follow (a call to
165
+ * a helper, a conditional): where its icons come from cannot be read.
166
+ * @param {any} node
167
+ * @returns {never}
168
+ */
169
+ const untraceableTheme = node => {
170
+ throw new AstryxError(
171
+ `The build carries a theme's ${field === 'icons' ? 'icon registry' : 'componentIcons'} from the source that writes it, and follows a theme only through its name, an import of it, or defineTheme({...}); here a theme is written as ${node?.type === 'CallExpression' ? 'a call to a helper' : node?.type === 'ConditionalExpression' ? 'a conditional' : 'an expression'}, which it cannot follow. Write each theme as defineTheme({...}), and the theme it extends by its name (extends: neutralTheme).`,
172
+ undefined,
173
+ ERROR_CODES.ERR_THEME_INVALID,
174
+ );
175
+ };
163
176
 
164
177
  if (exportName === undefined) {
165
178
  if (!hasIcons) return null;
@@ -797,10 +810,20 @@ export async function resolveIconImports(
797
810
  if (ref) return themeReference(ref, rejectOpaque);
798
811
  }
799
812
  if (node?.type === 'CallExpression') {
800
- if (!isDefineTheme(module, node.callee) || node.arguments.length !== 1)
801
- invalidRegistry();
813
+ if (!isDefineTheme(module, node.callee)) untraceableTheme(node);
814
+ if (node.arguments.length !== 1) invalidRegistry();
802
815
  node = unwrap(node.arguments[0]);
803
816
  }
817
+ // Any other expression (a helper's call, a conditional) is a theme the
818
+ // build cannot read from the source: it does not say the theme sets a
819
+ // registry, only that it cannot be followed.
820
+ if (
821
+ node &&
822
+ node.type !== 'ObjectExpression' &&
823
+ node.type !== 'Identifier' &&
824
+ node.type !== 'MemberExpression'
825
+ )
826
+ untraceableTheme(node);
804
827
  const config = await fields(module, node);
805
828
  const baseField = config.get('extends');
806
829
  // A built module keeps its functions in `__icons` (or `__componentIcons`)
@@ -21,6 +21,16 @@ export function themeEditHow(subject: string, options?: import("./theme-edit.typ
21
21
  * @param {string} cwd
22
22
  */
23
23
  export function projectRoot(cwd: string): string;
24
+ /**
25
+ * The preview commands in a line, rebased from the project root onto the
26
+ * folder the command ran in: each `--path` and each `preview app` folder,
27
+ * so a pointer works where it is printed (in a refusal, a `see` line, a
28
+ * note). A folder that comes out starting with `-` goes after `--`.
29
+ * @param {string} line
30
+ * @param {string} root
31
+ * @param {string} from
32
+ */
33
+ export function previewCommandsFrom(line: string, root: string, from: string): string;
24
34
  /**
25
35
  * A clearer refusal for a theme the editor made, named to list, add, use,
26
36
  * remove or eject: those commands work on package themes, and the editor
@@ -116,7 +126,7 @@ export function editorSourcePath(file: string, cwd: string): string | null;
116
126
  * copy.
117
127
  * @param {string} file the path as given
118
128
  * @param {string} cwd
119
- * @param {{check: boolean, upToDate?: boolean, out?: string}} opts
129
+ * @param {{check: boolean, upToDate?: boolean, out?: string, iconsSpecifier?: string}} opts
120
130
  * `upToDate`: the check's own verdict on the theme's outputs
121
131
  * @returns {Promise<Record<string, unknown> | null>}
122
132
  */
@@ -124,6 +134,7 @@ export function editorBuildExtra(file: string, cwd: string, opts: {
124
134
  check: boolean;
125
135
  upToDate?: boolean;
126
136
  out?: string;
137
+ iconsSpecifier?: string;
127
138
  }): Promise<Record<string, unknown> | null>;
128
139
  /**
129
140
  * For `compile` of an editor theme's own source (themes/<t>/<t>.theme.ts):
@@ -171,7 +182,6 @@ export function editorThemeTemplate(options: {
171
182
  cwd?: string;
172
183
  }): import("../theme/theme.type.mjs").ThemeTemplateResponse;
173
184
  export { parsePoints } from "./_how.mjs";
174
- export { newFlagList } from "./_edit.mjs";
175
185
  export function builtInThemes(): string[];
176
186
  export function editorBaseIn(slug: string | null | undefined, cwd: string): string;
177
187
  export function showSections(): string[];
@@ -197,7 +207,8 @@ export const themeEditPreviewApp: typeof preview.themeEditPreviewApp;
197
207
  export const themeEditPreviewList: typeof preview.themeEditPreviewList;
198
208
  /** @type {typeof preview.themeEditPreviewRemove} */
199
209
  export const themeEditPreviewRemove: typeof preview.themeEditPreviewRemove;
200
- export { typoOf } from "./_normal.mjs";
201
210
  import { AstryxError } from '../error.mjs';
202
211
  import * as edit from './_edit.mjs';
203
212
  import * as preview from './_preview-app.mjs';
213
+ export { newFlagList, checkedChangeLine as editorCheckedLine } from "./_edit.mjs";
214
+ export { booleanWord, typoNear, typoOf } from "./_normal.mjs";
@@ -94,7 +94,7 @@ setAfterBuild(writeAppCopy);
94
94
  import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
95
95
 
96
96
  export {parsePoints} from './_how.mjs';
97
- export {newFlagList} from './_edit.mjs';
97
+ export {newFlagList, checkedChangeLine as editorCheckedLine} from './_edit.mjs';
98
98
  import {themeEditHow as howAt} from './_how.mjs';
99
99
 
100
100
  /**
@@ -419,14 +419,14 @@ function absolute(result, root, from) {
419
419
  /^themes\/\S*$/.test(v) && !(key && PROSE.has(key))
420
420
  ? path.join(root, v)
421
421
  : key && PROSE.has(key)
422
- ? v.replace(
422
+ ? previewCommandsFrom(v, root, from).replace(
423
423
  /(^|[\s(,])((?:themes|src|app)\/[^\s,;)]*)/g,
424
424
  (all, before, file) =>
425
425
  /^themes\//.test(file) || inRoot(file)
426
426
  ? `${before}${path.join(root, file)}`
427
427
  : all,
428
428
  )
429
- : v
429
+ : previewCommandsFrom(v, root, from)
430
430
  : Array.isArray(v)
431
431
  ? v.map(x => map(x, key))
432
432
  : v && typeof v === 'object'
@@ -481,6 +481,23 @@ async function inProject(options, lock, fn, bestEffort = false, again = null) {
481
481
  */
482
482
  function fromCaller(e, root, from) {
483
483
  if (path.resolve(from) === root || !Array.isArray(e?.suggestions)) return e;
484
+ for (const s of e.suggestions)
485
+ if (typeof s?.name === 'string')
486
+ s.name = previewCommandsFrom(s.name, root, from);
487
+ return e;
488
+ }
489
+
490
+ /**
491
+ * The preview commands in a line, rebased from the project root onto the
492
+ * folder the command ran in: each `--path` and each `preview app` folder,
493
+ * so a pointer works where it is printed (in a refusal, a `see` line, a
494
+ * note). A folder that comes out starting with `-` goes after `--`.
495
+ * @param {string} line
496
+ * @param {string} root
497
+ * @param {string} from
498
+ */
499
+ export function previewCommandsFrom(line, root, from) {
500
+ if (path.resolve(from) === root) return line;
484
501
  const ARG = String.raw`('(?:[^']|'\\'')*'|"[^"]*"|[^\s'"]+)`;
485
502
  /** @param {string} v */
486
503
  const unquote = v =>
@@ -493,32 +510,40 @@ function fromCaller(e, root, from) {
493
510
  const rel = v =>
494
511
  /^<.*>$/.test(v)
495
512
  ? v
496
- : quoteCommandArgument(
497
- path.relative(path.resolve(from), path.resolve(root, unquote(v))) ||
498
- '.',
499
- );
500
- for (const s of e.suggestions) {
501
- if (typeof s?.name !== 'string') continue;
502
- if (!s.name.startsWith('astryx experimental theme preview ')) continue;
503
- s.name = s.name
504
- .replace(
513
+ : path.relative(path.resolve(from), path.resolve(root, unquote(v))) ||
514
+ '.';
515
+ const CMD = 'astryx experimental theme preview ';
516
+ const parts = line.split(CMD);
517
+ return parts
518
+ .map((part, i) => {
519
+ // A command after a `cd … &&` runs in the folder it names: as given.
520
+ if (i === 0 || /\bcd [^&]*&& (?:npx \S+ )?$/.test(parts[i - 1]))
521
+ return part;
522
+ let out = part.replace(
505
523
  new RegExp(`(--path )${ARG}`, 'g'),
506
524
  (
507
525
  /** @type {string} */ _m,
508
526
  /** @type {string} */ flag,
509
527
  /** @type {string} */ v,
510
- ) => flag + rel(v),
511
- )
512
- .replace(
513
- new RegExp(`^(astryx experimental theme preview app )${ARG}`),
528
+ ) => flag + quoteCommandArgument(rel(v)),
529
+ );
530
+ out = out.replace(
531
+ new RegExp(`^app ((?:--theme ${ARG} )?)(-- )?${ARG}`),
514
532
  (
515
- /** @type {string} */ _m,
516
- /** @type {string} */ cmd,
533
+ /** @type {string} */ m,
534
+ /** @type {string} */ flags,
535
+ /** @type {string} */ _t,
536
+ /** @type {string | undefined} */ dash,
517
537
  /** @type {string} */ v,
518
- ) => cmd + rel(v),
538
+ ) => {
539
+ if (!dash && v.startsWith('-')) return m;
540
+ const r = rel(v);
541
+ return `app ${flags}${r.startsWith('-') ? '-- ' : ''}${quoteCommandArgument(r)}`;
542
+ },
519
543
  );
520
- }
521
- return e;
544
+ return out;
545
+ })
546
+ .join(CMD);
522
547
  }
523
548
 
524
549
  /**
@@ -620,7 +645,8 @@ export const themeEditPreviewAdd = (description, options = {}) =>
620
645
  * saying where the change stands (a change stopped part way is finished by
621
646
  * the next preview command), never an ok with exit 0.
622
647
  * @template T
623
- * @param {string} where where the change stands, and what finishes it
648
+ * @param {string | (() => string)} where where the change stands, and what
649
+ * finishes it; a function is asked when the stop lands, so it can look
624
650
  * @param {() => Promise<T>} fn
625
651
  * @returns {Promise<T>}
626
652
  */
@@ -628,7 +654,9 @@ async function stopTold(where, fn) {
628
654
  const on = (/** @type {NodeJS.Signals} */ sig) => {
629
655
  process.removeListener('SIGINT', on);
630
656
  process.removeListener('SIGTERM', on);
631
- process.stderr.write(`Stopped: ${where}.\n`);
657
+ process.stderr.write(
658
+ `Stopped: ${typeof where === 'function' ? where() : where}.\n`,
659
+ );
632
660
  // With no other listener (a lock's, which ends the process itself),
633
661
  // the stop ends it here.
634
662
  if (process.listenerCount(sig) === 0) process.kill(process.pid, sig);
@@ -657,9 +685,23 @@ async function stopTold(where, fn) {
657
685
  */
658
686
  export const themeEditPreviewApp = async (dir, options = {}) => {
659
687
  const from = options.cwd ?? process.cwd();
688
+ // The app is written into a temp folder and moved into place in one step,
689
+ // with no pause on the way: when a stop lands, the folder holds the whole
690
+ // app or is as it was. Which one is told.
691
+ const target =
692
+ typeof dir === 'string' && dir.trim() ? path.resolve(from, dir) : null;
693
+ /** @param {string} d */
694
+ const holdsApp = d => fs.existsSync(path.join(d, 'package.json'));
695
+ const hadApp = target != null && holdsApp(target);
696
+ const shownTarget = target
697
+ ? path.relative(from, target).split(path.sep).join('/') || '.'
698
+ : null;
660
699
  return fromHere(
661
700
  await stopTold(
662
- `the new app may be part made; ${PREVIEW_WORDS} app with a new folder name makes a whole one`,
701
+ () =>
702
+ target && !hadApp && holdsApp(target)
703
+ ? `the new app in ${shownTarget}/ is written whole (it is moved into place in one step); cd ${quoteCommandArgument(shownTarget?.startsWith('-') ? `./${shownTarget}` : (shownTarget ?? '.'))} && npm install && npm run dev opens it`
704
+ : `nothing was written${shownTarget ? ` (${shownTarget}/ is as it was)` : ''}; run the same command again`,
663
705
  () =>
664
706
  inProject(
665
707
  options,
@@ -893,7 +935,7 @@ export function editorThemeRefusal(err, cwd) {
893
935
  }
894
936
 
895
937
  /** The shared typo rule, for a typed subcommand. */
896
- export {typoOf} from './_normal.mjs';
938
+ export {booleanWord, typoNear, typoOf} from './_normal.mjs';
897
939
 
898
940
  /**
899
941
  * The editor themes of the app the folder `cwd` is in, by name; none when
@@ -1651,7 +1693,7 @@ function appCopyTheme(root, file) {
1651
1693
  * copy.
1652
1694
  * @param {string} file the path as given
1653
1695
  * @param {string} cwd
1654
- * @param {{check: boolean, upToDate?: boolean, out?: string}} opts
1696
+ * @param {{check: boolean, upToDate?: boolean, out?: string, iconsSpecifier?: string}} opts
1655
1697
  * `upToDate`: the check's own verdict on the theme's outputs
1656
1698
  * @returns {Promise<Record<string, unknown> | null>}
1657
1699
  */
@@ -1667,6 +1709,14 @@ export async function editorBuildExtra(file, cwd, opts) {
1667
1709
  const skipped = outSkipsCopy(root, slug, cwd, opts);
1668
1710
  if (skipped) return {appCopySkipped: skipped};
1669
1711
  }
1712
+ // Every set and show builds the theme again from its source, without
1713
+ // --icons-specifier: said, with the change that keeps it.
1714
+ if (opts.iconsSpecifier && !opts.check)
1715
+ return {
1716
+ warnings: [
1717
+ `${slug} is a theme the editor made: every set and show builds it again from themes/${slug}/${slug}.theme.ts without --icons-specifier, which puts the theme's own import of the registry back. To keep this one, import the registry from its package in ${slug}.theme.ts.`,
1718
+ ],
1719
+ };
1670
1720
  if (opts.check) {
1671
1721
  // A theme output that is stale is the check's own finding (it names
1672
1722
  // the file); the copy is compared only with a current build.
@@ -80,6 +80,20 @@ export function fontListMeant(value: string): {
80
80
  * @param {string} name
81
81
  */
82
82
  export function exampleOf(type: string, name: string): string;
83
+ /**
84
+ * What a text property CSS inherits, set on a part, also reaches: the parts
85
+ * inside it that set no such property of their own, said in one line; null
86
+ * for any other property or when none does.
87
+ * @param {import('./_settings.mjs').Ctx} ctx
88
+ * @param {{on?: string, only?: boolean, thing?: string}} s
89
+ * @param {string} prop kebab-case
90
+ * @returns {string | null}
91
+ */
92
+ export function inheritedReach(ctx: import("./_settings.mjs").Ctx, s: {
93
+ on?: string;
94
+ only?: boolean;
95
+ thing?: string;
96
+ }, prop: string): string | null;
83
97
  /**
84
98
  * The states `set` takes on a part: the ones its doc lists and the ones
85
99
  * every part takes, less any a change in it is refused for while the same