@astryxdesign/cli 0.7.15 → 0.7.16-canary.g07c77c0

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 (159) hide show
  1. package/README.md +5 -3
  2. package/api/build/_adapter.d.mts +1 -0
  3. package/api/build/blocks/blocks.d.mts +1 -0
  4. package/api/build/blocks/blocks.mjs +18 -1
  5. package/api/component/_adapter.d.mts +1 -1
  6. package/api/component/_adapter.mjs +28 -1
  7. package/api/doctor/_adapter.d.mts +17 -0
  8. package/api/doctor/_adapter.mjs +43 -0
  9. package/api/doctor/built-checks.mjs +1 -1
  10. package/api/doctor/doctor.mjs +18 -4
  11. package/api/doctor/theme-checks.mjs +1 -1
  12. package/api/integration/add-contribution.mjs +3 -3
  13. package/api/integration/pack-check.mjs +14 -8
  14. package/api/integration/validate-integration.mjs +1 -1
  15. package/api/search/_adapter.mjs +15 -16
  16. package/api/search/_entries.d.mts +2 -1
  17. package/api/search/_entries.mjs +28 -1
  18. package/api/swizzle/_moduleGraph.mjs +1 -1
  19. package/api/theme/_adapter.d.mts +5 -2
  20. package/api/theme/_adapter.mjs +43 -12
  21. package/api/theme/_fork.mjs +1 -1
  22. package/api/theme/build/build.d.mts +116 -32
  23. package/api/theme/build/build.mjs +449 -102
  24. package/api/theme/eject/eject.mjs +22 -1
  25. package/api/theme/template/template.d.mts +19 -0
  26. package/api/theme/template/template.mjs +102 -25
  27. package/api/theme/theme.type.d.mts +5 -1
  28. package/api/theme/theme.type.mjs +2 -1
  29. package/api/theme/themeBuild.doc.mjs +3 -3
  30. package/api/theme/themeEject.doc.mjs +1 -1
  31. package/api/theme/themeTemplate.doc.mjs +9 -3
  32. package/api/theme-edit/_adapter.d.mts +32 -2
  33. package/api/theme-edit/_adapter.mjs +213 -36
  34. package/api/theme-edit/_check.d.mts +69 -3
  35. package/api/theme-edit/_check.mjs +1517 -218
  36. package/api/theme-edit/_color.d.mts +2 -8
  37. package/api/theme-edit/_color.mjs +292 -219
  38. package/api/theme-edit/_compiler.d.mts +1 -0
  39. package/api/theme-edit/_compiler.mjs +20 -1
  40. package/api/theme-edit/_context.d.mts +29 -0
  41. package/api/theme-edit/_context.mjs +426 -40
  42. package/api/theme-edit/_css.d.mts +60 -1
  43. package/api/theme-edit/_css.mjs +404 -28
  44. package/api/theme-edit/_edit.d.mts +9 -0
  45. package/api/theme-edit/_edit.mjs +1300 -135
  46. package/api/theme-edit/_how-commands.d.mts +11 -26
  47. package/api/theme-edit/_how-commands.mjs +30 -2
  48. package/api/theme-edit/_how-question.d.mts +7 -0
  49. package/api/theme-edit/_how-question.mjs +1304 -176
  50. package/api/theme-edit/_how.mjs +144 -30
  51. package/api/theme-edit/_overview.mjs +2 -0
  52. package/api/theme-edit/_palette.d.mts +11 -0
  53. package/api/theme-edit/_palette.mjs +194 -65
  54. package/api/theme-edit/_parts.d.mts +33 -0
  55. package/api/theme-edit/_parts.mjs +138 -9
  56. package/api/theme-edit/_png.d.mts +18 -0
  57. package/api/theme-edit/_png.mjs +95 -14
  58. package/api/theme-edit/_preview-app.d.mts +9 -0
  59. package/api/theme-edit/_preview-app.mjs +1191 -71
  60. package/api/theme-edit/_preview.d.mts +16 -3
  61. package/api/theme-edit/_preview.mjs +335 -30
  62. package/api/theme-edit/_project.d.mts +11 -0
  63. package/api/theme-edit/_project.mjs +46 -12
  64. package/api/theme-edit/_settings.d.mts +240 -5
  65. package/api/theme-edit/_settings.mjs +2561 -115
  66. package/api/theme-edit/_tables.d.mts +24 -0
  67. package/api/theme-edit/_tables.mjs +211 -149
  68. package/api/theme-edit/_vet.d.mts +42 -0
  69. package/api/theme-edit/_vet.mjs +144 -0
  70. package/api/theme-edit/theme-edit.type.d.mts +2 -1
  71. package/api/theme-edit/theme-edit.type.mjs +1 -1
  72. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  73. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  74. package/api/upgrade/registry/registry.mjs +6 -1
  75. package/assets/codemods/parse.mjs +2 -2
  76. package/assets/docs/tree/single-component.doc.mjs +11 -2
  77. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  78. package/assets/docs.generated.json +2 -2
  79. package/assets/preview-app/next.config.mjs +7 -1
  80. package/assets/preview-app/package.json +1 -0
  81. package/assets/preview-app/src/app/globals.css +1 -0
  82. package/assets/self-audit.generated.json +1 -1
  83. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  84. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  85. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  86. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  87. package/assets/templates/components.generated.json +1 -1
  88. package/assets/templates/pages/dashboard/page.tsx +1 -1
  89. package/authoring/doctypes/_schema.d.mts +52 -5
  90. package/authoring/doctypes/_schema.mjs +62 -7
  91. package/authoring/doctypes/base/type.ts +10 -0
  92. package/authoring/doctypes/component/component.doc.mjs +1 -1
  93. package/authoring/doctypes/function/function.doc.mjs +6 -0
  94. package/authoring/doctypes/function/type.ts +3 -0
  95. package/authoring/doctypes/legacy.mjs +5 -1
  96. package/authoring/index.d.ts +1 -0
  97. package/authoring/shadcn/source-variants.d.mts +1 -1
  98. package/authoring/shadcn/source-variants.mjs +32 -10
  99. package/clients/cli/build-id.generated.json +1 -1
  100. package/clients/cli/commands/doctor.doc.mjs +2 -2
  101. package/clients/cli/commands/experimental/theme.mjs +237 -45
  102. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  103. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +2 -2
  104. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  105. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +3 -3
  106. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  107. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  108. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  109. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  110. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  111. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  112. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  113. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  114. package/clients/cli/commands/theme.mjs +190 -46
  115. package/clients/cli/formatters/index.mjs +7 -4
  116. package/clients/cli/lib/cli-error.mjs +9 -3
  117. package/clients/cli/lib/component-format.mjs +27 -9
  118. package/clients/cli/lib/json-shim.mjs +72 -2
  119. package/clients/cli/manifest.generated.json +1 -1
  120. package/clients/cli/run.mjs +49 -0
  121. package/foundation/agent-docs/agent-docs-target.d.mts +2 -6
  122. package/foundation/agent-docs/agent-docs-target.mjs +9 -17
  123. package/foundation/agent-docs/agent-docs.mjs +3 -2
  124. package/foundation/config/config-writer.mjs +2 -2
  125. package/foundation/config/project.mjs +60 -14
  126. package/foundation/discovery/component-discovery.mjs +5 -17
  127. package/foundation/discovery/icon-set-writer.mjs +1 -1
  128. package/foundation/discovery/module-exports.mjs +1 -15
  129. package/foundation/discovery/template-adapter.mjs +44 -19
  130. package/foundation/discovery/template-source-tree.mjs +3 -16
  131. package/foundation/discovery/theme-discovery.d.mts +5 -1
  132. package/foundation/discovery/theme-discovery.mjs +30 -35
  133. package/foundation/fs/exact-codec.d.mts +35 -0
  134. package/foundation/fs/exact-codec.mjs +148 -0
  135. package/foundation/fs/gather-cache.d.mts +15 -5
  136. package/foundation/fs/gather-cache.mjs +123 -30
  137. package/foundation/fs/paths.d.mts +39 -0
  138. package/foundation/fs/paths.mjs +44 -11
  139. package/foundation/fs/read-record.mjs +11 -1
  140. package/foundation/integrations/contribution-fixes.mjs +1 -16
  141. package/foundation/integrations/may-have-integrations.mjs +3 -2
  142. package/foundation/integrations/public-imports.mjs +1 -1
  143. package/foundation/render/embedded-imports.mjs +1 -1
  144. package/foundation/render/host-exit.d.mts +8 -0
  145. package/foundation/render/host-exit.mjs +11 -0
  146. package/foundation/render/page-host.mjs +56 -10
  147. package/foundation/render/page-worker.mjs +14 -0
  148. package/foundation/render/render-page.mjs +37 -2
  149. package/foundation/response/error-codes.d.mts +2 -1
  150. package/foundation/response/error-codes.d.ts +1 -0
  151. package/foundation/response/error-codes.doc.mjs +5 -0
  152. package/foundation/response/error-codes.mjs +3 -0
  153. package/foundation/response/json.d.mts +15 -0
  154. package/foundation/response/json.mjs +52 -1
  155. package/foundation/response/response-types.doc.mjs +1 -1
  156. package/foundation/runtime/lazy-dependencies.d.mts +14 -0
  157. package/foundation/runtime/lazy-dependencies.mjs +82 -0
  158. package/foundation/xle/browser.d.mts +2 -2
  159. package/package.json +7 -6
@@ -31,6 +31,8 @@
31
31
  * @position api/theme-edit — adapter for api/theme-edit/theme-edit.mjs
32
32
  */
33
33
 
34
+ import {writeThemeTemplate} from '../theme/template/template.mjs';
35
+ import {buildSuggestion} from '../theme/build/build.mjs';
34
36
  import {createHash} from 'node:crypto';
35
37
  import * as fs from 'node:fs';
36
38
  import * as path from 'node:path';
@@ -39,10 +41,8 @@ import {themeCacheRoot} from './_project.mjs';
39
41
  import * as preview from './_preview-app.mjs';
40
42
  import {AstryxError} from '../error.mjs';
41
43
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
42
- import {
43
- findAstryxProject,
44
- findPackageRoot,
45
- } from '../../foundation/fs/paths.mjs';
44
+ import {findPackageRoot} from '../../foundation/fs/paths.mjs';
45
+ import {coreApp} from './_context.mjs';
46
46
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
47
47
  import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
48
48
  import {
@@ -50,10 +50,13 @@ import {
50
50
  quoteCommandArgument,
51
51
  } from '../../foundation/env/package-manager.mjs';
52
52
  import {LIKE, P} from './_tables.mjs';
53
- import {camel} from './_settings.mjs';
53
+ import {setLine} from './_check.mjs';
54
+ import {SHOWCASE_GROUPS} from './_preview.mjs';
55
+ import {camel, typedThemeName} from './_settings.mjs';
54
56
  import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
55
57
 
56
58
  export {parsePoints} from './_how.mjs';
59
+ export {newFlagList} from './_edit.mjs';
57
60
  import {themeEditHow as howAt} from './_how.mjs';
58
61
 
59
62
  /**
@@ -90,6 +93,11 @@ export async function themeEditHow(subject, options = {}) {
90
93
  /** The built-in themes a theme can build on (`--like`). */
91
94
  export const builtInThemes = () => [...LIKE];
92
95
 
96
+ /** The sections `show --section` takes. */
97
+ export const showSections = () => [...SHOWCASE_GROUPS];
98
+
99
+ export {dialValueFits} from './_settings.mjs';
100
+
93
101
  /**
94
102
  * The project a command acts on: the Astryx project at or above `cwd`, found
95
103
  * as `upgrade` finds it (the nearest package that declares an Astryx package
@@ -102,7 +110,9 @@ export const builtInThemes = () => [...LIKE];
102
110
  */
103
111
  export function projectRoot(cwd) {
104
112
  const start = path.resolve(cwd);
105
- const project = findAstryxProject(start);
113
+ // One rule: the nearest folder at or above cwd whose package.json lists
114
+ // @astryxdesign/core.
115
+ const project = coreApp(start);
106
116
  const pkg = findPackageRoot(start);
107
117
  const inReach = (/** @type {string} */ dir) =>
108
118
  project ? !path.relative(project, dir).startsWith('..') : true;
@@ -112,13 +122,19 @@ export function projectRoot(cwd) {
112
122
  let json;
113
123
  try {
114
124
  json = JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
115
- } catch {
125
+ } catch (e) {
126
+ // Name the file and what the parser says is wrong, with its place.
127
+ const rel = path.relative(start, file) || 'package.json';
128
+ const why = String(/** @type {Error} */ (e).message ?? '').replace(
129
+ /^Unexpected token.*?, /,
130
+ '',
131
+ );
116
132
  throw new AstryxError(
117
- `${path.relative(start, file) || 'package.json'} is not valid JSON, so the app it belongs to is unknown. Fix it, then run the command again. Nothing was written.`,
133
+ `${rel} is not valid JSON (${why}), so the app it belongs to is unknown. Fix it, then run the command again. Nothing was written.`,
118
134
  [
119
135
  {
120
- name: runLine(start, 'doctor'),
121
- reason: 'names the file and what is wrong in it',
136
+ name: `\${EDITOR:-vi} ${quoteCommandArgument(rel)}`,
137
+ reason: 'open the file and fix it',
122
138
  },
123
139
  ],
124
140
  ERROR_CODES.ERR_PROJECT_REQUIRED,
@@ -195,9 +211,15 @@ function lockDir(root) {
195
211
  * @param {boolean} [bestEffort] a command that can run read-only runs
196
212
  * without the lock when it cannot be taken (a read-only node_modules),
197
213
  * told so, and then writes nothing
214
+ * @param {string | null} [again] the command's own words after the CLI
215
+ * name, to suggest running it again (never the host process's argv: an
216
+ * API caller is not a CLI run)
198
217
  * @returns {Promise<T>}
199
218
  */
200
- async function withLock(root, name, fn, bestEffort = false) {
219
+ async function withLock(root, name, fn, bestEffort = false, again = null) {
220
+ // A preview command, which holds the preview lock, suggests the list of
221
+ // previews (what the other command may be changing).
222
+ again ??= name === 'preview' ? 'experimental theme preview list' : null;
201
223
  /** @type {string | null} */
202
224
  let dir;
203
225
  try {
@@ -239,16 +261,17 @@ async function withLock(root, name, fn, bestEffort = false) {
239
261
  {
240
262
  onBusy: (o, held) => {
241
263
  throw new AstryxError(
242
- `Another command has been changing ${name.replace(/^theme-/, '')} for 30 seconds${o ? ` (process ${o.pid} on ${o.host}${held != null ? `, holding it ${held} s` : ''})` : ''}. Nothing was changed; run this command again. If no astryx command is running, the lock is left from one that stopped: remove the folder ${lock}.`,
243
- // A look that takes no lock: the last build as it is.
244
- [
245
- {
246
- name: name.startsWith('theme-')
247
- ? `${P} show ${name.replace(/^theme-/, '')}`
248
- : 'astryx experimental theme preview list',
249
- reason: 'see it as it is now',
250
- },
251
- ],
264
+ `Another command has been changing ${name.replace(/^theme-/, '')} for 30 seconds${o ? ` (process ${o.pid} on ${o.host}${held != null ? `, holding it ${held} s` : ''})` : ''}. Nothing was changed; run this command again once the other one ends. If no astryx command is running, the lock is left from one that stopped: remove the folder ${lock}.`,
265
+ // Every editor command (show too) takes this lock, so none of
266
+ // them works meanwhile: this same command, once the other ends.
267
+ again
268
+ ? [
269
+ {
270
+ name: runLine(root, again),
271
+ reason: 'run it again once the other command ends',
272
+ },
273
+ ]
274
+ : [],
252
275
  ERROR_CODES.ERR_THEME_BUSY,
253
276
  );
254
277
  },
@@ -346,9 +369,11 @@ function absolute(result, root, from) {
346
369
  * @param {O} options
347
370
  * @param {string | null} lock
348
371
  * @param {(o: O & {cwd: string}) => Promise<T>} fn
372
+ * @param {boolean} [bestEffort]
373
+ * @param {string | null} [again] the command's own words, for a busy lock
349
374
  * @returns {Promise<T>}
350
375
  */
351
- async function inProject(options, lock, fn, bestEffort = false) {
376
+ async function inProject(options, lock, fn, bestEffort = false, again = null) {
352
377
  const from = options.cwd ?? process.cwd();
353
378
  const o = atRoot(options);
354
379
  try {
@@ -360,6 +385,7 @@ async function inProject(options, lock, fn, bestEffort = false) {
360
385
  lock,
361
386
  locked => fn(locked ? o : {...o, readOnly: true}),
362
387
  bestEffort,
388
+ again,
363
389
  )
364
390
  : await fn(o);
365
391
  return absolute(r, o.cwd, from);
@@ -434,20 +460,74 @@ const withThemeLock = o => ({
434
460
  ) => withLock(o.cwd, lockName(slug), fn),
435
461
  });
436
462
 
463
+ /**
464
+ * A command's own words after the CLI name, from what it was called with,
465
+ * every option kept: set and undo as `set` writes them (scope flags and
466
+ * --only), new with --like and each dial, --png where given.
467
+ * @param {string} line a command as the editor writes one (`astryx …`)
468
+ * @param {{png?: boolean}} [o]
469
+ */
470
+ const words = (line, o = {}) =>
471
+ `${line.replace(/^astryx /, '').trimEnd()}${o.png ? ' --png' : ''}`;
472
+
437
473
  /** @type {typeof edit.themeEditNew} */
438
474
  export const themeEditNew = (name, options = {}) =>
439
- inProject(options, lockName(name), o => edit.themeEditNew(name, o));
475
+ inProject(
476
+ options,
477
+ lockName(name),
478
+ o => edit.themeEditNew(name, o),
479
+ false,
480
+ words(
481
+ `${P} new ${quoteCommandArgument(name)} ${edit
482
+ .newFlagList(
483
+ options.like,
484
+ options.settings ?? {},
485
+ /** @type {boolean} */ (options.png),
486
+ )
487
+ .join(' ')}`,
488
+ ),
489
+ );
440
490
  /** @type {typeof edit.themeEditSet} */
441
491
  export const themeEditSet = (theme, thing, value, options = {}) =>
442
- inProject(options, lockName(theme), o =>
443
- edit.themeEditSet(theme, thing, value, o),
492
+ inProject(
493
+ options,
494
+ lockName(theme),
495
+ o => edit.themeEditSet(theme, thing, value, o),
496
+ false,
497
+ words(setLine(theme, thing, value, options), options),
444
498
  );
445
499
  /** @type {typeof edit.themeEditUndo} */
446
500
  export const themeEditUndo = (theme, options = {}) =>
447
- inProject(options, lockName(theme), o => edit.themeEditUndo(theme, o));
501
+ inProject(
502
+ options,
503
+ lockName(theme),
504
+ o => edit.themeEditUndo(theme, o),
505
+ false,
506
+ words(
507
+ options.thing
508
+ ? setLine(
509
+ theme,
510
+ options.thing,
511
+ /** @type {string} */ (options.value ?? ''),
512
+ options,
513
+ true,
514
+ )
515
+ : `${P} undo ${theme}`,
516
+ options,
517
+ ),
518
+ );
448
519
  /** @type {typeof edit.themeEditShow} */
449
520
  export const themeEditShow = (theme, options = {}) =>
450
- inProject(options, lockName(theme), o => edit.themeEditShow(theme, o), true);
521
+ inProject(
522
+ options,
523
+ lockName(theme),
524
+ o => edit.themeEditShow(theme, o),
525
+ true,
526
+ words(
527
+ `${P} show ${theme}${options.section ? ` --section ${quoteCommandArgument(String(options.section))}` : ''}`,
528
+ options,
529
+ ),
530
+ );
451
531
  /** @type {typeof preview.themeEditPreviewAdd} */
452
532
  export const themeEditPreviewAdd = (description, options = {}) =>
453
533
  inProject(options, 'preview', o =>
@@ -577,16 +657,32 @@ export function editorThemeRefusal(err, cwd) {
577
657
  )
578
658
  return null;
579
659
  const root = projectRoot(cwd);
580
- const named = /"([a-z][a-z0-9-]*)"|'([a-z][a-z0-9-]*)'/.exec(err.message);
581
- const slug = named ? editorThemeOf(root, named[1] ?? named[2]) : null;
660
+ // The name as typed, read the way the editor reads a theme name: a path
661
+ // to its folder or a file in it, in any case, names the theme.
662
+ const named = /"([^"]+)"|'([^']+)'/.exec(err.message);
663
+ const word = named ? typedThemeName(named[1] ?? named[2]) : '';
664
+ const slug = word ? editorThemeOf(root, word) : null;
582
665
  if (!slug) return null;
583
666
  // A local theme of that name (a fork in the app's own themes folder) is
584
667
  // one the stable commands take: their own message stands.
585
668
  if (fs.existsSync(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
586
669
  const id = `${camel(slug)}Theme`;
587
670
  const key = /^[a-z][a-z0-9]*$/i.test(slug) ? slug : JSON.stringify(slug);
671
+ // The paths from the folder of the app's generated themes module (where
672
+ // a file that merges themes sits), else from the app root.
673
+ const generated = path.join(root, 'src', 'astryx-themes.ts');
674
+ const from = fs.existsSync(generated) ? path.dirname(generated) : root;
675
+ let rel = path
676
+ .relative(from, path.join(root, 'themes', slug))
677
+ .split(path.sep)
678
+ .join('/');
679
+ if (!rel.startsWith('.')) rel = `./${rel}`;
680
+ const where =
681
+ from === root
682
+ ? 'in a file of your own at the app root'
683
+ : `in a file of your own beside ${path.relative(root, generated).split(path.sep).join('/')} (from another folder, change the paths to match)`;
588
684
  return new AstryxError(
589
- `${slug} is a theme the editor made (themes/${slug}/), not a theme package, so list, add, use, remove and eject do not take it. To use it, import its module and its stylesheet in a file of your own (import {${id}} from './themes/${slug}/${slug}.js'; import './themes/${slug}/${slug}.css';) and merge it into the themes there ({...themes, ${key}: ${id}}); do not add it to src/astryx-themes.ts, which add, use and remove write again. Change it with the editor.`,
685
+ `${slug} is a theme the editor made (themes/${slug}/), not a theme package, so list, add, use, remove and eject do not take it. To use it, import its module and its stylesheet ${where} (import {${id}} from '${rel}/${slug}.js'; import '${rel}/${slug}.css';) and merge it into the themes there ({...themes, ${key}: ${id}}); do not add it to src/astryx-themes.ts, which add, use and remove write again. Change it with the editor.`,
590
686
  [
591
687
  {
592
688
  name: runLine(cwd, `experimental theme editor show ${slug}`),
@@ -603,24 +699,62 @@ export function editorThemeRefusal(err, cwd) {
603
699
  * take an editor theme, and `--check` checks an editor theme by the editor's
604
700
  * own rules (waiting for a change in progress).
605
701
  * @param {string[]} files
606
- * @param {{cwd: string, check?: boolean, family?: boolean}} options
702
+ * @param {{cwd: string, check?: boolean, family?: boolean, iconsSpecifier?: string, out?: string}} options
703
+ * `check`, `out` and `iconsSpecifier` are kept in every compile a refusal
704
+ * suggests
607
705
  * @returns {Promise<AstryxError | null>}
608
706
  */
609
- export async function editorCompileProblem(files, {cwd, check, family}) {
707
+ export async function editorCompileProblem(
708
+ files,
709
+ {cwd, check, family, iconsSpecifier, out},
710
+ ) {
610
711
  const cwdRoot = projectRoot(cwd);
712
+ const COMPILE = {group: 'experimental theme', build: 'compile'};
713
+ /**
714
+ * The compile of `source` (from `from`) with the caller's mode: a check
715
+ * stays a check, and --out names the same file from there.
716
+ * @param {string} source @param {string} from
717
+ */
718
+ const compileLine = (source, from) =>
719
+ buildSuggestion(
720
+ source,
721
+ {
722
+ check,
723
+ iconsSpecifier,
724
+ out: out
725
+ ? path.relative(from, path.resolve(cwd, out)) || out
726
+ : undefined,
727
+ },
728
+ from,
729
+ COMPILE,
730
+ );
611
731
  for (const file of files) {
612
732
  const at = editorThemeAt(cwdRoot, path.resolve(cwd, file));
613
733
  if (!at || !editorOwnFile(at.slug, file)) continue;
614
734
  const {root, slug} = at;
615
735
  const source = `themes/${slug}/${slug}.theme.ts`;
736
+ // An editor theme is built from its project's root, as every editor
737
+ // command runs there: from a subfolder the build would write outside
738
+ // its working folder. The run names the root.
739
+ if (path.resolve(cwd) !== path.resolve(root))
740
+ return new AstryxError(
741
+ `${slug} is a theme the editor made; compile it from the app root (${path.relative(cwd, root) || '.'}), where the editor builds it.`,
742
+ [
743
+ {
744
+ name: `cd ${quoteCommandArgument(path.relative(cwd, root) || '.')} && ${compileLine(source, root)}`,
745
+ reason: 'do this instead',
746
+ },
747
+ ],
748
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
749
+ );
616
750
  if (/\.settings\.(ts|json)$/.test(file))
617
751
  return new AstryxError(
618
752
  `${file} is the editor's own settings for ${slug}, not a theme source; compile the theme source.`,
619
753
  [
620
754
  {
621
- name: runLine(
755
+ name: compileLine(
756
+ path.relative(cwd, path.join(root, source)) || source,
622
757
  cwd,
623
- `experimental theme compile ${quoteCommandArgument(path.relative(cwd, path.join(root, source)) || source)}`,
624
758
  ),
625
759
  reason: 'do this instead',
626
760
  },
@@ -632,9 +766,9 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
632
766
  `${slug} is a theme the editor made; --family builds package theme families, not editor themes. Compile it on its own.`,
633
767
  [
634
768
  {
635
- name: runLine(
769
+ name: compileLine(
770
+ path.relative(cwd, path.join(root, source)) || source,
636
771
  cwd,
637
- `experimental theme compile ${quoteCommandArgument(path.relative(cwd, path.join(root, source)) || source)}`,
638
772
  ),
639
773
  reason: 'do this instead',
640
774
  },
@@ -661,6 +795,22 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
661
795
  if (e instanceof AstryxError) return e;
662
796
  throw e;
663
797
  }
798
+ // An own change to the theme source is what compile builds (and what
799
+ // --check compares): never a reason to refuse it.
800
+ if (
801
+ why &&
802
+ /\.theme\.ts (or a module it imports )?changed since the last build$/.test(
803
+ why,
804
+ )
805
+ )
806
+ why = null;
807
+ // A missing built output is one compile writes itself.
808
+ if (
809
+ why &&
810
+ !check &&
811
+ /^[^/]+\.(css|js|d\.ts|css\.d\.ts) was missing$/.test(why)
812
+ )
813
+ why = null;
664
814
  if (why && !check)
665
815
  return new AstryxError(
666
816
  `${slug}'s generated settings do not match its settings (${why}), so compile would build the old ones. The editor builds it from its settings.`,
@@ -756,3 +906,30 @@ export async function editorThemeHold(files, {cwd}) {
756
906
  }
757
907
  return releaseAll;
758
908
  }
909
+
910
+ /**
911
+ * For `compile` of a file that is not there: when it is an editor theme's
912
+ * own source (`themes/<t>/<t>.theme.ts` beside its settings), the command
913
+ * that writes it again; null otherwise.
914
+ * @param {string} file the path as given
915
+ * @param {string} cwd
916
+ * @returns {{name: string, reason: string} | null}
917
+ */
918
+ export function editorMissingSource(file, cwd) {
919
+ const at = editorThemeAt(projectRoot(cwd), path.resolve(cwd, file));
920
+ if (!at || path.basename(file) !== `${at.slug}.theme.ts`) return null;
921
+ return {
922
+ name: runLine(cwd, `experimental theme editor show ${at.slug}`),
923
+ reason: `the editor writes ${at.slug}.theme.ts again from its settings`,
924
+ };
925
+ }
926
+
927
+ /**
928
+ * `theme template` for the experimental command: in a folder the theme
929
+ * editor made, only the editor's own files are protected.
930
+ * @param {{targetPath?: string, overwrite?: boolean, cwd?: string}} options
931
+ * @returns {import('../theme/theme.type.mjs').ThemeTemplateResponse}
932
+ */
933
+ export function editorThemeTemplate(options) {
934
+ return writeThemeTemplate(options, true);
935
+ }
@@ -1,6 +1,27 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * A value pasted as a CSS declaration (`color: #e11d48;`, `font-weight: 700
6
+ * !important`), from devtools or a stylesheet: its property and value, with
7
+ * the `;` and `!important` gone. Null when the value is not a declaration (a
8
+ * URL's `https:` is not a property).
9
+ * @param {string} v
10
+ * @returns {{property: string, value: string} | null}
11
+ */
12
+ export function pastedDeclaration(v: string): {
13
+ property: string;
14
+ value: string;
15
+ } | null;
16
+ /**
17
+ * A font pasted as a declaration (`font-family: Georgia, serif;`, from
18
+ * devtools or a stylesheet), as the family list it names; a `font:`
19
+ * shorthand gives its family; '' when it names the property and no value.
20
+ * Null when the value is not a pasted declaration.
21
+ * @param {string} v
22
+ * @returns {string | null}
23
+ */
24
+ export function pastedFont(v: string): string | null;
4
25
  /**
5
26
  * @typedef {object} SetFlags
6
27
  * @property {string} [on]
@@ -16,10 +37,16 @@
16
37
  * @param {import('./_settings.mjs').Ctx} ctx
17
38
  * @param {string} slug
18
39
  * @param {import('./_settings.mjs').ThemeData} data
19
- * @param {string} [skip]
40
+ * @param {string | {thing: string, on?: string, when?: string, state?: string, mode?: string}} [skip]
20
41
  * @returns {Array<{setting: import('./_settings.mjs').Setting, why: string, scope?: boolean}>} every saved setting the editor no longer accepts
21
42
  */
22
- export function storedProblems(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, skip?: string): Array<{
43
+ export function storedProblems(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, skip?: string | {
44
+ thing: string;
45
+ on?: string;
46
+ when?: string;
47
+ state?: string;
48
+ mode?: string;
49
+ }): Array<{
23
50
  setting: import("./_settings.mjs").Setting;
24
51
  why: string;
25
52
  scope?: boolean;
@@ -44,7 +71,44 @@ export function exampleOf(type: string, name: string): string;
44
71
  * @returns {import('./_settings.mjs').Setting}
45
72
  */
46
73
  export function checkSetting(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, thing: string, value: string | undefined, flags: SetFlags, unset?: boolean): import("./_settings.mjs").Setting;
47
- export { lengthPx };
74
+ /**
75
+ * A setting's value as set reads it: one line, and tabs as spaces; in a font
76
+ * value every run of spaces or tabs is one space, so `'Open Sans'` and
77
+ * `'Open\tSans'` both name Open Sans.
78
+ * @param {string} thing
79
+ * @param {string} value
80
+ */
81
+ export function normalValue(thing: string, value: string): string;
82
+ /**
83
+ * The first var() in a value that names no design token and would read
84
+ * nothing (no fallback), or one a letter or two off a token, else null.
85
+ * Dials take their own words, so a dial's var() with no near token passes.
86
+ * @param {string} v
87
+ * @param {Record<string, unknown>} TOKENS
88
+ * @param {string} thing
89
+ * @returns {{message: string, near: string[], close: boolean} | null}
90
+ */
91
+ export function unknownVarRef(v: string, TOKENS: Record<string, unknown>, thing: string): {
92
+ message: string;
93
+ near: string[];
94
+ close: boolean;
95
+ } | null;
96
+ /**
97
+ * Why a font value names a font file or a link rather than a family
98
+ * (`./fonts/My.woff2`, `Inter.ttf`, `https://fonts.googleapis.com/…`,
99
+ * `url(…)`), or null. A theme names families; a file is loaded with
100
+ * @font-face or a font package.
101
+ * @param {string} value
102
+ * @returns {string | null}
103
+ */
104
+ export function fontFileReason(value: string): string | null;
105
+ export function setLine(slug: string, thing: string, value: string, s: {
106
+ on?: string;
107
+ when?: string;
108
+ state?: string;
109
+ mode?: string;
110
+ only?: boolean;
111
+ }, unset?: boolean): string;
48
112
  /** The aspects `how` answers at the whole-theme level. */
49
113
  export const ASPECTS: string[];
50
114
  export type SetFlags = {
@@ -55,3 +119,5 @@ export type SetFlags = {
55
119
  only?: boolean | undefined;
56
120
  };
57
121
  import { lengthPx } from './_settings.mjs';
122
+ import { familySpaces } from './_settings.mjs';
123
+ export { lengthPx, familySpaces };