@astryxdesign/cli 0.7.14 → 0.7.15-canary.gea16e8d

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 (129) hide show
  1. package/api/doctor/_adapter.d.mts +1 -0
  2. package/api/doctor/_adapter.mjs +8 -0
  3. package/api/doctor/_authoring-audit.d.mts +42 -0
  4. package/api/doctor/_authoring-audit.mjs +106 -0
  5. package/api/doctor/doctor.d.mts +7 -0
  6. package/api/doctor/doctor.mjs +24 -39
  7. package/api/search/_adapter.mjs +124 -3
  8. package/api/search/_candidate-score.mjs +63 -9
  9. package/api/search/_entries.d.mts +10 -0
  10. package/api/search/_entries.mjs +68 -1
  11. package/api/search/_gather-templates.d.mts +11 -0
  12. package/api/search/_gather-templates.mjs +22 -2
  13. package/api/search/_words.mjs +26 -6
  14. package/api/swizzle/copy/copy.mjs +1 -1
  15. package/api/theme/_adapter.mjs +20 -9
  16. package/api/theme/build/build.d.mts +15 -1
  17. package/api/theme/build/build.mjs +132 -32
  18. package/api/theme/targets/targets.d.mts +8 -0
  19. package/api/theme/targets/targets.mjs +14 -1
  20. package/api/theme/themeBuild.doc.mjs +6 -3
  21. package/api/theme/themeEject.doc.mjs +3 -3
  22. package/api/theme/themeTargets.doc.mjs +1 -1
  23. package/api/theme-edit/_adapter.d.mts +46 -3
  24. package/api/theme-edit/_adapter.mjs +372 -109
  25. package/api/theme-edit/_check.d.mts +6 -3
  26. package/api/theme-edit/_check.mjs +665 -87
  27. package/api/theme-edit/_color.mjs +4 -2
  28. package/api/theme-edit/_compiler.d.mts +2 -1
  29. package/api/theme-edit/_compiler.mjs +27 -13
  30. package/api/theme-edit/_context.d.mts +2 -1
  31. package/api/theme-edit/_context.mjs +47 -8
  32. package/api/theme-edit/_edit.d.mts +9 -3
  33. package/api/theme-edit/_edit.mjs +484 -66
  34. package/api/theme-edit/_how-commands.d.mts +33 -7
  35. package/api/theme-edit/_how-commands.mjs +57 -45
  36. package/api/theme-edit/_how-question.d.mts +4 -0
  37. package/api/theme-edit/_how-question.mjs +1004 -223
  38. package/api/theme-edit/_how.mjs +96 -9
  39. package/api/theme-edit/_palette.d.mts +38 -13
  40. package/api/theme-edit/_palette.mjs +620 -223
  41. package/api/theme-edit/_parts.mjs +63 -7
  42. package/api/theme-edit/_png.d.mts +4 -4
  43. package/api/theme-edit/_png.mjs +4 -2
  44. package/api/theme-edit/_preview-app.d.mts +6 -0
  45. package/api/theme-edit/_preview-app.mjs +1194 -207
  46. package/api/theme-edit/_preview.mjs +2 -2
  47. package/api/theme-edit/_project.d.mts +12 -1
  48. package/api/theme-edit/_project.mjs +37 -6
  49. package/api/theme-edit/_settings.d.mts +104 -33
  50. package/api/theme-edit/_settings.mjs +818 -118
  51. package/api/theme-edit/_tables.d.mts +7 -0
  52. package/api/theme-edit/_tables.mjs +61 -0
  53. package/api/theme-edit/theme-edit.type.d.mts +11 -1
  54. package/api/theme-edit/theme-edit.type.mjs +4 -3
  55. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  56. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  57. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  58. package/api/theme-edit/themeEditPreviewList.doc.mjs +1 -1
  59. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  60. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  61. package/api/upgrade/_adapter.d.mts +1 -0
  62. package/assets/codemods/run-codemod.mjs +61 -0
  63. package/assets/codemods/runner.mjs +5 -4
  64. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  65. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  66. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  67. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  68. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  69. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  70. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  71. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  72. package/assets/docs/tree/calendars.doc.mjs +1 -3
  73. package/assets/docs.generated.json +2 -1
  74. package/assets/self-audit.generated.json +1 -0
  75. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  76. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  77. package/assets/templates/components.generated.json +1 -1
  78. package/clients/cli/bin/astryx.mjs +19 -15
  79. package/clients/cli/build-id.generated.json +1 -0
  80. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  81. package/clients/cli/commands/experimental/theme.mjs +178 -78
  82. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  83. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  84. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  85. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  86. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  87. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  88. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  89. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  90. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  91. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  92. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  93. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  94. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  95. package/clients/cli/commands/manifest.mjs +5 -2
  96. package/clients/cli/commands/theme.mjs +118 -22
  97. package/clients/cli/index.mjs +9 -3
  98. package/clients/cli/lib/manifest.mjs +37 -0
  99. package/clients/cli/lib/resolve-theme.mjs +2 -1
  100. package/clients/cli/manifest.generated.json +1 -0
  101. package/foundation/discovery/module-exports.mjs +16 -2
  102. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  103. package/foundation/discovery/stored-self-audit.mjs +119 -0
  104. package/foundation/discovery/template-adapter.d.mts +48 -2
  105. package/foundation/discovery/template-adapter.mjs +51 -19
  106. package/foundation/discovery/template-needs.d.mts +6 -0
  107. package/foundation/discovery/template-needs.mjs +20 -1
  108. package/foundation/discovery/template-source-tree.d.mts +7 -0
  109. package/foundation/discovery/template-source-tree.mjs +15 -0
  110. package/foundation/discovery/theme-discovery.d.mts +2 -1
  111. package/foundation/discovery/theme-discovery.mjs +2 -8
  112. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  113. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  114. package/foundation/doc-compiler/import.mjs +12 -11
  115. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  116. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  117. package/foundation/env/private-dir.d.mts +17 -0
  118. package/foundation/env/private-dir.mjs +42 -0
  119. package/foundation/fs/gather-cache.d.mts +108 -0
  120. package/foundation/fs/gather-cache.mjs +724 -0
  121. package/foundation/fs/module-loader.mjs +7 -1
  122. package/foundation/fs/read-record.d.mts +31 -1
  123. package/foundation/fs/read-record.mjs +100 -7
  124. package/foundation/integrations/validate-contributions.mjs +24 -11
  125. package/foundation/release/cache.d.mts +11 -2
  126. package/foundation/release/cache.mjs +59 -10
  127. package/foundation/release/folder-lock.d.mts +21 -0
  128. package/foundation/release/folder-lock.mjs +171 -0
  129. package/package.json +8 -6
@@ -21,4 +21,15 @@ export function gatherTemplates(cwd: string): Promise<Candidate[]>;
21
21
  * @returns {Promise<Candidate[]>}
22
22
  */
23
23
  export function gatherThemes(cwd: string): Promise<Candidate[]>;
24
+ /**
25
+ * The source file each template candidate's `weakKeywords` are read from,
26
+ * when it could be read, and the names if this run already read them: a
27
+ * gather kept between runs stores the names it has and the file for the rest
28
+ * (api/search/_adapter.mjs), so storing costs no parse.
29
+ * @type {WeakMap<object, {file: string, derivedSoFar: () => string[] | undefined}>}
30
+ */
31
+ export const derivedFromSource: WeakMap<object, {
32
+ file: string;
33
+ derivedSoFar: () => string[] | undefined;
34
+ }>;
24
35
  export type Candidate = import("./_lexical.mjs").Candidate;
@@ -15,6 +15,14 @@ import {
15
15
  } from '../../foundation/discovery/template-adapter.mjs';
16
16
  import {sameWord, wordsOf} from './_words.mjs';
17
17
 
18
+ /**
19
+ * The source file each template candidate's `weakKeywords` are read from,
20
+ * when it could be read, and the names if this run already read them: a
21
+ * gather kept between runs stores the names it has and the file for the rest
22
+ * (api/search/_adapter.mjs), so storing costs no parse.
23
+ * @type {WeakMap<object, {file: string, derivedSoFar: () => string[] | undefined}>}
24
+ */
25
+ export const derivedFromSource = new WeakMap();
18
26
  /** @typedef {import('./_lexical.mjs').Candidate} Candidate */
19
27
 
20
28
  /**
@@ -75,14 +83,20 @@ export async function gatherTemplates(cwd) {
75
83
  let derive = () => [];
76
84
  /** @type {string[] | null} */
77
85
  let weakKeywordBound = null;
86
+ /** @type {string | null} */
87
+ let readSource = null;
88
+ /** @type {(() => string[] | undefined) | undefined} */
89
+ let derivedNow;
78
90
  if (t.type === 'page') {
79
91
  if (t.filePath) {
80
92
  try {
81
93
  const source = fs.readFileSync(t.filePath, 'utf-8');
94
+ readSource = t.filePath;
82
95
  // Parsing the source costs more than the rest of the page's gather.
83
96
  // It waits until a term could match a name the source can yield.
84
97
  /** @type {string[] | undefined} */
85
98
  let derived;
99
+ derivedNow = () => derived;
86
100
  derive = () => {
87
101
  if (derived === undefined) {
88
102
  try {
@@ -101,8 +115,8 @@ export async function gatherTemplates(cwd) {
101
115
  if (t.category)
102
116
  keywords.push(...t.category.split(/[^A-Za-z0-9]+/).filter(Boolean));
103
117
  }
104
- return {
105
- domain: 'template',
118
+ const candidate = {
119
+ domain: /** @type {const} */ ('template'),
106
120
  name: commandName,
107
121
  keywords,
108
122
  get weakKeywords() {
@@ -123,6 +137,12 @@ export async function gatherTemplates(cwd) {
123
137
  _resultName: t.dirName,
124
138
  _commandName: commandName,
125
139
  };
140
+ if (readSource)
141
+ derivedFromSource.set(candidate, {
142
+ file: readSource,
143
+ derivedSoFar: () => derivedNow?.(),
144
+ });
145
+ return candidate;
126
146
  });
127
147
  }
128
148
 
@@ -136,14 +136,34 @@ export function sameTermWord(t, w) {
136
136
  * @returns {string[]}
137
137
  */
138
138
  export function wordsOf(text) {
139
- return String(text)
140
- .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
141
- .replace(/([A-Z])([A-Z][a-z])/g, '$1 $2')
142
- .toLowerCase()
143
- .split(/[^a-z0-9]+/)
144
- .filter(Boolean);
139
+ const key = String(text);
140
+ let words = splitWords.get(key);
141
+ if (words === undefined) {
142
+ // A long-running caller ranks many queries; start over rather than grow.
143
+ if (splitWords.size >= SPLIT_WORDS_LIMIT) splitWords.clear();
144
+ words = Object.freeze(
145
+ key
146
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
147
+ .replace(/([A-Z])([A-Z][a-z])/g, '$1 $2')
148
+ .toLowerCase()
149
+ .split(/[^a-z0-9]+/)
150
+ .filter(Boolean),
151
+ );
152
+ splitWords.set(key, words);
153
+ }
154
+ return /** @type {string[]} */ (words);
145
155
  }
146
156
 
157
+ /**
158
+ * Each text's words, split once per process: a search splits the same names
159
+ * and keywords for every term of every query.
160
+ * @type {Map<string, readonly string[]>}
161
+ */
162
+ const splitWords = new Map();
163
+
164
+ /** How many texts' words are kept before the cache starts over. */
165
+ const SPLIT_WORDS_LIMIT = 100_000;
166
+
147
167
  /**
148
168
  * Whether a term is found inside a name or keyword: it is one of its words, or
149
169
  * the start of one (a truncation), and covers at least half of the whole
@@ -554,7 +554,7 @@ export async function swizzleCopy(component, options = {}) {
554
554
  for (const dir of [...createdDirs].reverse()) {
555
555
  fs.rmSync(dir, {recursive: true, force: true});
556
556
  }
557
- if (!outputDirExisted) {
557
+ if (!outputDirExisted && fs.existsSync(outputDir)) {
558
558
  fs.rmSync(outputDir, {recursive: true, force: true});
559
559
  }
560
560
  throw writeFailed(output.dest, cwd, err, unrestored);
@@ -403,8 +403,9 @@ export default {
403
403
  * @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
404
404
  * @param {string} dir
405
405
  * @param {string} cwd
406
+ * @param {string} projectDir the project root the default target is in
406
407
  */
407
- function assertEjectTargetFree(theme, dir, cwd) {
408
+ function assertEjectTargetFree(theme, dir, cwd, projectDir) {
408
409
  /** @type {string[]} */
409
410
  let entries;
410
411
  try {
@@ -415,7 +416,8 @@ function assertEjectTargetFree(theme, dir, cwd) {
415
416
  }
416
417
  const rel = path.relative(cwd, dir) || '.';
417
418
  const isDefault =
418
- path.resolve(cwd, defaultEjectTarget(theme.slug)) === path.resolve(dir);
419
+ path.resolve(projectDir, defaultEjectTarget(theme.slug)) ===
420
+ path.resolve(dir);
419
421
  const suggestion = isDefault
420
422
  ? undefined
421
423
  : [
@@ -472,17 +474,26 @@ function themeDescriptorName(file) {
472
474
  * @returns {string} project-relative output directory
473
475
  */
474
476
  export function ejectThemeFiles(theme, {cwd, targetPath, overwrite = false}) {
477
+ // The fork lands in the project, as list and add read it: the default root
478
+ // is the project's, and a relative [path] is read from the working folder
479
+ // but must stay inside the project.
480
+ const projectDir = findPackageRoot(cwd) ?? path.resolve(cwd);
481
+ const target = !targetPath
482
+ ? defaultEjectTarget(theme.slug)
483
+ : path.isAbsolute(targetPath)
484
+ ? targetPath
485
+ : path.relative(projectDir, path.resolve(cwd, targetPath)) || '.';
475
486
  let resolvedDir;
476
487
  try {
477
- resolvedDir = assertWithin(
478
- targetPath || defaultEjectTarget(theme.slug),
479
- cwd,
480
- {label: 'theme target path'},
481
- );
488
+ resolvedDir = assertWithin(target, projectDir, {
489
+ label: 'theme target path',
490
+ });
482
491
  } catch (error) {
483
492
  if (error instanceof PathSafetyError) {
484
493
  throw new AstryxError(
485
- error.message,
494
+ targetPath
495
+ ? error.message.replace(`"${target}"`, `"${targetPath}"`)
496
+ : error.message,
486
497
  undefined,
487
498
  ERROR_CODES.ERR_PATH_TRAVERSAL,
488
499
  );
@@ -521,7 +532,7 @@ export function ejectThemeFiles(theme, {cwd, targetPath, overwrite = false}) {
521
532
  }
522
533
  }
523
534
 
524
- assertEjectTargetFree(theme, resolvedDir, cwd);
535
+ assertEjectTargetFree(theme, resolvedDir, cwd, projectDir);
525
536
 
526
537
  if (!overwrite) {
527
538
  const existing = writes.find(write => fs.existsSync(write.dest));
@@ -48,6 +48,16 @@ export function coreUnavailableMessage(cwd: string, importError: any): string;
48
48
  * @returns {string}
49
49
  */
50
50
  export function normalizeThemeBuildForCompare(content: string): string;
51
+ /**
52
+ * Theme sources a missing build input probably meant, relative to `cwd`: the
53
+ * same path with `/` for `\`; or, for a bare theme name, the theme sources in
54
+ * `themes/<name>/` and `src/themes/<name>/` of the project, and `<name>` with a
55
+ * theme source extension. A build output is never offered.
56
+ * @param {string} file the input as given
57
+ * @param {string} cwd
58
+ * @returns {string[]} at most three paths
59
+ */
60
+ export function themeSourceGuesses(file: string, cwd: string): string[];
51
61
  /**
52
62
  * Import specifier for install/scaffold instructions. Drops a leading `src/`
53
63
  * from the cwd-relative dir (most consumers import from a file under src/) but
@@ -144,12 +154,16 @@ export function themeBuild(file: string, options?: {
144
154
  cwd?: string;
145
155
  projectCore?: boolean;
146
156
  }): Promise<import("../theme.type.mjs").ThemeBuildResponse | import("../theme.type.mjs").ThemeBuildCheckResponse | null>;
147
- /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void}} options @param {{cwd?: string}} [ctx] */
157
+ /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
148
158
  export function themeBuildFamily(files: string[], options: {
149
159
  familyKey: string;
150
160
  check?: boolean;
151
161
  iconsSpecifier?: string;
152
162
  __onPrivateVarError?: () => void;
163
+ __commandWords?: {
164
+ group: string;
165
+ build: string;
166
+ };
153
167
  }, { cwd }?: {
154
168
  cwd?: string;
155
169
  }): Promise<{
@@ -73,6 +73,7 @@ import {
73
73
  findCoreDir,
74
74
  findInstalledPackage,
75
75
  findProjectCoreDir,
76
+ findPackageRoot,
76
77
  } from '../../../foundation/fs/paths.mjs';
77
78
  import {isGlobalCopy} from '../../../foundation/release/choose.mjs';
78
79
  import {isInReleaseCache} from '../../../foundation/release/cache.mjs';
@@ -88,6 +89,7 @@ import {AstryxError} from '../../error.mjs';
88
89
  import {applyWrites} from '../../integration/add-helpers.mjs';
89
90
  import {logger} from '../../logger.mjs';
90
91
  import {loadComponentDoc} from '../../../foundation/discovery/component-loader.mjs';
92
+ import {THEME_SOURCE_EXTENSIONS} from '../../../foundation/discovery/theme-module-extensions.mjs';
91
93
  import {
92
94
  collectThemingTargets,
93
95
  targetsByKey,
@@ -578,6 +580,17 @@ function resolveToolVersions(cwd) {
578
580
  };
579
581
  }
580
582
 
583
+ /**
584
+ * The command a stale check names, in the words of the group that ran it
585
+ * (`experimental theme compile`); the generated headers keep `theme build`.
586
+ * @param {string} command
587
+ * @param {{group: string, build: string}} [words]
588
+ */
589
+ function rebuildLine(command, words) {
590
+ if (!words || words.group === 'theme') return command;
591
+ return command.replace(/\btheme build\b/, `${words.group} ${words.build}`);
592
+ }
593
+
581
594
  /**
582
595
  * Build a @generated attribution header for generated files.
583
596
  * @param {string} sourceFile - Relative path to the source theme file
@@ -820,7 +833,12 @@ function themeFilesIn(dir) {
820
833
  try {
821
834
  return fs
822
835
  .readdirSync(dir)
823
- .filter(name => /(?:\.theme|Theme)\.(?:[cm]?[jt]sx?)$/.test(name))
836
+ .filter(
837
+ name =>
838
+ /(?:\.theme|Theme)\.[^.]+$/.test(name) &&
839
+ THEME_SOURCE_EXTENSIONS.includes(path.extname(name)) &&
840
+ !fileHead(path.join(dir, name)).includes(GENERATED_MARKER),
841
+ )
824
842
  .sort()
825
843
  .slice(0, 3);
826
844
  } catch {
@@ -828,6 +846,86 @@ function themeFilesIn(dir) {
828
846
  }
829
847
  }
830
848
 
849
+ /**
850
+ * Theme sources a missing build input probably meant, relative to `cwd`: the
851
+ * same path with `/` for `\`; or, for a bare theme name, the theme sources in
852
+ * `themes/<name>/` and `src/themes/<name>/` of the project, and `<name>` with a
853
+ * theme source extension. A build output is never offered.
854
+ * @param {string} file the input as given
855
+ * @param {string} cwd
856
+ * @returns {string[]} at most three paths
857
+ */
858
+ export function themeSourceGuesses(file, cwd) {
859
+ const shown = (/** @type {string} */ absolute) =>
860
+ path.relative(cwd, absolute).split(path.sep).join('/');
861
+ const isSource = (/** @type {string} */ absolute) =>
862
+ fs.existsSync(absolute) &&
863
+ !fs.statSync(absolute).isDirectory() &&
864
+ !fileHead(absolute).includes(GENERATED_MARKER);
865
+ if (file.includes('\\')) {
866
+ const forward = path.resolve(cwd, file.replace(/\\/g, '/'));
867
+ return isSource(forward) ? [shown(forward)] : [];
868
+ }
869
+ if (/[/.]/.test(file)) return [];
870
+ const root = findPackageRoot(cwd) ?? cwd;
871
+ const guesses = [
872
+ path.join(root, 'themes', file),
873
+ path.join(root, 'src', 'themes', file),
874
+ ].flatMap(folder =>
875
+ themeFilesIn(folder).map(name => shown(path.join(folder, name))),
876
+ );
877
+ for (const extension of THEME_SOURCE_EXTENSIONS) {
878
+ const candidate = path.resolve(cwd, file + extension);
879
+ if (isSource(candidate)) guesses.push(shown(candidate));
880
+ }
881
+ return guesses.slice(0, 3);
882
+ }
883
+
884
+ /**
885
+ * Refuse a file that is not a theme source before loading it: an output of a
886
+ * build (it carries the `@generated` header, whatever its extension, and
887
+ * names the source it was built from), or a file whose extension no theme
888
+ * source has, such as `.css` or `.json` (THEME_SOURCE_EXTENSIONS).
889
+ * @param {string} filePath
890
+ * @param {string} cwd
891
+ */
892
+ function assertThemeSourceFile(filePath, cwd) {
893
+ const rel = (/** @type {string} */ file) => path.relative(cwd, file);
894
+ const sourceHead = fileHead(filePath);
895
+ if (sourceHead.includes(GENERATED_MARKER)) {
896
+ const from = /Source: (.+)/.exec(sourceHead)?.[1]?.trim();
897
+ throw new AstryxError(
898
+ `${rel(filePath)} is an output of \`theme build\`, not a theme source.${from ? ` It was built from ${from}.` : ''}`,
899
+ from
900
+ ? [
901
+ {
902
+ name: formatCliCommand(`theme build ${shellWord(from)}`, cwd),
903
+ reason: 'build the theme source',
904
+ },
905
+ ]
906
+ : undefined,
907
+ ERROR_CODES.ERR_THEME_INVALID,
908
+ );
909
+ }
910
+ if (!THEME_SOURCE_EXTENSIONS.includes(path.extname(filePath).toLowerCase())) {
911
+ throw new AstryxError(
912
+ `${rel(filePath)} is not a theme module. A theme source is a ${THEME_SOURCE_EXTENSIONS.join(', ')} file that exports defineTheme(...).`,
913
+ themeFilesIn(path.dirname(filePath)).map(name => ({
914
+ name: formatCliCommand(
915
+ `theme build ${shellWord(
916
+ rel(path.join(path.dirname(filePath), name))
917
+ .split(path.sep)
918
+ .join('/'),
919
+ )}`,
920
+ cwd,
921
+ ),
922
+ reason: 'a theme source in that folder',
923
+ })),
924
+ ERROR_CODES.ERR_THEME_LOAD,
925
+ );
926
+ }
927
+ }
928
+
831
929
  /**
832
930
  * Refuse a build that would replace a file it does not own. A build never
833
931
  * writes over its input, two of its own outputs at one path, or an output
@@ -850,22 +948,6 @@ function assertOutputsReplaceable(
850
948
  ) {
851
949
  const rel = (/** @type {string} */ file) => path.relative(cwd, file);
852
950
  const sourceKey = outputKey(filePath);
853
- const sourceHead = fileHead(filePath);
854
- if (sourceHead.includes(GENERATED_MARKER)) {
855
- const from = /Source: (.+)/.exec(sourceHead)?.[1]?.trim();
856
- throw new AstryxError(
857
- `${rel(filePath)} is an output of \`theme build\`, not a theme source.${from ? ` It was built from ${from}.` : ''}`,
858
- from
859
- ? [
860
- {
861
- name: formatCliCommand(`theme build ${shellWord(from)}`, cwd),
862
- reason: 'build the theme source',
863
- },
864
- ]
865
- : undefined,
866
- ERROR_CODES.ERR_THEME_INVALID,
867
- );
868
- }
869
951
  const seen = new Set();
870
952
  for (const write of writes) {
871
953
  const key = outputKey(write.dest);
@@ -1972,17 +2054,24 @@ const THEME_SCOPE_TO = `[data-astryx-theme]`;
1972
2054
  * the author's TypeScript sees, which is the point: the CSS the build emits
1973
2055
  * matches the theme they type-checked.
1974
2056
  */
2057
+ // Every theme source extension is in this list: jiti hands a file whose
2058
+ // extension it does not list to Node's own loader, which cannot load `.jsx`
2059
+ // or, on some Node versions, TypeScript.
1975
2060
  const THEME_MODULE_EXTENSIONS = [
1976
- '.ts',
1977
- '.tsx',
1978
- '.mts',
1979
- '.cts',
1980
- '.mtsx',
1981
- '.ctsx',
1982
- '.mjs',
1983
- '.cjs',
1984
- '.js',
1985
- '.json',
2061
+ ...new Set([
2062
+ '.ts',
2063
+ '.tsx',
2064
+ '.mts',
2065
+ '.cts',
2066
+ '.mtsx',
2067
+ '.ctsx',
2068
+ '.mjs',
2069
+ '.cjs',
2070
+ '.js',
2071
+ '.jsx',
2072
+ '.json',
2073
+ ...THEME_SOURCE_EXTENSIONS,
2074
+ ]),
1986
2075
  ];
1987
2076
  // prettier-ignore
1988
2077
  const registryGraphError = (/** @type {string} */ message) => new AstryxError(message, undefined, ERROR_CODES.ERR_THEME_INVALID);
@@ -3156,7 +3245,7 @@ function validateHeadingTypeAugmentationSupport(themeDef) {
3156
3245
  * `logger` (silent by default).
3157
3246
  *
3158
3247
  * @param {string} file - Theme file path, resolved against `cwd`.
3159
- * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void, __writeRoot?: string, __claimedOutputs?: Map<string, string>}} [options] -
3248
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void, __writeRoot?: string, __claimedOutputs?: Map<string, string>, __commandWords?: {group: string, build: string}}} [options] -
3160
3249
  * `out` overrides the output CSS path, or names the folder for it; `check` compares against on-disk outputs
3161
3250
  * instead of writing. `__claimedOutputs` records the outputs earlier builds
3162
3251
  * in one run wrote, so a later theme cannot replace them. `__writeRoot` replaces `cwd` as the directory every
@@ -3178,7 +3267,10 @@ async function themeBuildInternal(
3178
3267
  if (!fs.existsSync(filePath)) {
3179
3268
  throw new AstryxError(
3180
3269
  `File not found: ${filePath}`,
3181
- undefined,
3270
+ themeSourceGuesses(file, cwd).map(guess => ({
3271
+ name: formatCliCommand(`theme build ${shellWord(guess)}`, cwd),
3272
+ reason: 'a theme source that exists',
3273
+ })),
3182
3274
  ERROR_CODES.ERR_FILE_NOT_FOUND,
3183
3275
  );
3184
3276
  }
@@ -3197,6 +3289,8 @@ async function themeBuildInternal(
3197
3289
  );
3198
3290
  }
3199
3291
 
3292
+ assertThemeSourceFile(filePath, cwd);
3293
+
3200
3294
  if (!report.compact) {
3201
3295
  logger.log(`\nBuilding theme from ${path.relative(cwd, filePath)}...`);
3202
3296
  }
@@ -3863,7 +3957,10 @@ async function themeBuildInternal(
3863
3957
  // prettier-ignore
3864
3958
  const remedy = outsideCheckRemedy(writes, [filePath], writeRoot, relative => [relative(filePath), ...(options.out ? ['--out', relative(outPath)] : []), ...(options.iconsSpecifier ? ['--icons-specifier', options.iconsSpecifier] : [])]);
3865
3959
  if (remedy) logger.error(`\n ${remedy.join('\n ')}`);
3866
- else logger.error(`\n Rebuild with: ${buildCommand}`);
3960
+ else
3961
+ logger.error(
3962
+ `\n Rebuild with: ${rebuildLine(buildCommand, options.__commandWords)}`,
3963
+ );
3867
3964
  }
3868
3965
  return {
3869
3966
  type: 'theme.build.check',
@@ -4260,7 +4357,7 @@ async function preloadFamilySource(filePath, loader, interception) {
4260
4357
  finally { patch.undo(); }
4261
4358
  }
4262
4359
 
4263
- /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void}} options @param {{cwd?: string}} [ctx] */
4360
+ /** @param {string[]} files @param {{familyKey: string, check?: boolean, iconsSpecifier?: string, __onPrivateVarError?: () => void, __commandWords?: {group: string, build: string}}} options @param {{cwd?: string}} [ctx] */
4264
4361
  export async function themeBuildFamily(
4265
4362
  files,
4266
4363
  options,
@@ -4518,7 +4615,10 @@ export async function themeBuildFamily(
4518
4615
  // prettier-ignore
4519
4616
  const remedy = outsideCheckRemedy(writes, members.map(member => member.filePath), cwd, relative => ['--family', ...members.map(member => relative(member.filePath)), '--family-key', baseName, ...(options.iconsSpecifier ? ['--icons-specifier', options.iconsSpecifier] : [])]);
4520
4617
  if (remedy) logger.error(`\n ${remedy.join('\n ')}`);
4521
- else logger.error(`\n Rebuild with: ${buildCommand}`);
4618
+ else
4619
+ logger.error(
4620
+ `\n Rebuild with: ${rebuildLine(buildCommand, options.__commandWords)}`,
4621
+ );
4522
4622
  }
4523
4623
  return {
4524
4624
  type: 'theme.build.check',
@@ -1,6 +1,14 @@
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 targets filter as it is matched: trimmed, lowercase, and without a
6
+ * leading `.`, so a class copied from the output (`.astryx-switch`) reads as
7
+ * its name. Null when nothing is left, which means no filter.
8
+ * @param {string | undefined | null} filter
9
+ * @returns {string | null}
10
+ */
11
+ export function normalizeTargetFilter(filter: string | undefined | null): string | null;
4
12
  /**
5
13
  * List every component theming target — the `defineTheme` `components` keys,
6
14
  * with the props and states each one accepts.
@@ -33,6 +33,19 @@ function matchesLoosely(target, filter) {
33
33
  );
34
34
  }
35
35
 
36
+ /**
37
+ * A targets filter as it is matched: trimmed, lowercase, and without a
38
+ * leading `.`, so a class copied from the output (`.astryx-switch`) reads as
39
+ * its name. Null when nothing is left, which means no filter.
40
+ * @param {string | undefined | null} filter
41
+ * @returns {string | null}
42
+ */
43
+ export function normalizeTargetFilter(filter) {
44
+ return filter
45
+ ? String(filter).trim().replace(/^\./, '').toLowerCase() || null
46
+ : null;
47
+ }
48
+
36
49
  /**
37
50
  * List every component theming target — the `defineTheme` `components` keys,
38
51
  * with the props and states each one accepts.
@@ -49,7 +62,7 @@ export async function themeTargets(filter, {cwd = process.cwd()} = {}) {
49
62
  const coreDir = coreDirOrThrow(requireThemeCoreDir, cwd);
50
63
 
51
64
  const all = await collectThemingTargets(path.join(coreDir, 'src'));
52
- const needle = filter ? String(filter).toLowerCase() : null;
65
+ const needle = normalizeTargetFilter(filter);
53
66
  let targets = all;
54
67
  if (needle) {
55
68
  const named = all.filter(t => t.component.toLowerCase() === needle);
@@ -94,14 +94,17 @@ export const doc = {
94
94
  },
95
95
  ],
96
96
  throws: [
97
- {code: 'ERR_FILE_NOT_FOUND', when: 'the theme file does not exist'},
97
+ {
98
+ code: 'ERR_FILE_NOT_FOUND',
99
+ when: 'the theme file does not exist; for a bare theme name or a path written with backslashes, the suggestions name the theme sources that exist',
100
+ },
98
101
  {
99
102
  code: 'ERR_THEME_LOAD',
100
- when: 'the file cannot be loaded or parsed into a defineTheme() result',
103
+ when: 'the file cannot be loaded or parsed into a defineTheme() result, or its extension is not one a theme source has (.mjs, .js, .mts, .ts, .tsx, .jsx, .cjs, .cts), which is refused before loading',
101
104
  },
102
105
  {
103
106
  code: 'ERR_THEME_INVALID',
104
- when: 'the resolved theme is invalid, for example it has no name, a custom Heading type has no standalone rule with a declaration the compiler can emit, or its icon registry cannot be preserved through an import (also rejected in check mode); or an output would replace the theme source, two outputs share one path, or the file is itself an output of a build',
107
+ when: 'the resolved theme is invalid, for example it has no name, a custom Heading type has no standalone rule with a declaration the compiler can emit, or its icon registry cannot be preserved through an import (also rejected in check mode); or an output would replace the theme source, two outputs share one path, or the file is itself an output of a build, whatever its extension (refused before loading, naming the source it was built from)',
105
108
  },
106
109
  {
107
110
  code: 'ERR_FILE_EXISTS',
@@ -30,8 +30,8 @@ export const doc = {
30
30
  name: 'options.targetPath',
31
31
  type: 'string',
32
32
  description:
33
- 'Destination directory for ejected files. Must resolve within cwd.',
34
- default: "'src/themes/<slug>'",
33
+ 'Destination directory for ejected files, relative to cwd. Must resolve within the project (the nearest folder above cwd with a package.json).',
34
+ default: "'src/themes/<slug>' in the project root",
35
35
  },
36
36
  {
37
37
  name: 'options.overwrite',
@@ -43,7 +43,7 @@ export const doc = {
43
43
  name: 'options.cwd',
44
44
  type: 'string',
45
45
  description:
46
- 'Project directory used for integration discovery and target paths.',
46
+ 'Working directory: integration discovery and the project root start here, a relative targetPath resolves from it, and outputDir is relative to it.',
47
47
  },
48
48
  {
49
49
  name: 'options.package',
@@ -40,7 +40,7 @@ export const doc = {
40
40
  name: 'filter',
41
41
  type: 'string',
42
42
  description:
43
- 'A component name (exact, case-insensitive), or a substring of a target key, class or component. Omit for the whole surface.',
43
+ 'A component name (exact, case-insensitive), or a substring of a target key, class or component. A class selector as the output prints it (`.astryx-switch`) reads without its dot, and surrounding spaces are ignored. Omit for the whole surface.',
44
44
  },
45
45
  {
46
46
  name: 'ctx.cwd',
@@ -1,6 +1,15 @@
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
+ * `how`, run at the project root like the other editor commands, so a
6
+ * subfolder finds the app's themes. A picture named from the subfolder
7
+ * keeps pointing where it was named.
8
+ * @param {string} subject
9
+ * @param {import('./theme-edit.type.mjs').ThemeEditHowOptions} [options]
10
+ * @returns {Promise<import('./theme-edit.type.mjs').ThemeEditHowResponse>}
11
+ */
12
+ export function themeEditHow(subject: string, options?: import("./theme-edit.type.mjs").ThemeEditHowOptions): Promise<import("./theme-edit.type.mjs").ThemeEditHowResponse>;
4
13
  /**
5
14
  * The project a command acts on: the Astryx project at or above `cwd`, found
6
15
  * as `upgrade` finds it (the nearest package that declares an Astryx package
@@ -12,8 +21,42 @@
12
21
  * @param {string} cwd
13
22
  */
14
23
  export function projectRoot(cwd: string): string;
15
- export function isHowPicture(word: string, cwd?: string): boolean;
16
- export function fileExists(file: string, cwd?: string): boolean;
24
+ /**
25
+ * A clearer refusal for a theme the editor made, named to list, add, use,
26
+ * remove or eject: those commands work on package themes, and the editor
27
+ * theme is used by importing its module. Null for any other refusal.
28
+ * @param {AstryxError} err
29
+ * @param {string} cwd
30
+ * @returns {AstryxError | null}
31
+ */
32
+ export function editorThemeRefusal(err: AstryxError, cwd: string): AstryxError | null;
33
+ /**
34
+ * A refusal before `compile` runs on an editor theme's files, or null: the
35
+ * editor's generated settings are not a theme source, `--family` does not
36
+ * take an editor theme, and `--check` checks an editor theme by the editor's
37
+ * own rules (waiting for a change in progress).
38
+ * @param {string[]} files
39
+ * @param {{cwd: string, check?: boolean, family?: boolean}} options
40
+ * @returns {Promise<AstryxError | null>}
41
+ */
42
+ export function editorCompileProblem(files: string[], { cwd, check, family }: {
43
+ cwd: string;
44
+ check?: boolean;
45
+ family?: boolean;
46
+ }): Promise<AstryxError | null>;
47
+ /**
48
+ * Hold the theme lock of every editor theme among the files while
49
+ * `compile` builds or checks them, so it never reads a change half
50
+ * written. Resolves to the release.
51
+ * @param {string[]} files
52
+ * @param {{cwd: string}} options
53
+ * @returns {Promise<() => Promise<void>>}
54
+ */
55
+ export function editorThemeHold(files: string[], { cwd }: {
56
+ cwd: string;
57
+ }): Promise<() => Promise<void>>;
58
+ export { parsePoints } from "./_how.mjs";
59
+ export function builtInThemes(): string[];
17
60
  /** @type {typeof edit.themeEditNew} */
18
61
  export const themeEditNew: typeof edit.themeEditNew;
19
62
  /** @type {typeof edit.themeEditSet} */
@@ -35,6 +78,6 @@ export const themeEditPreviewApp: typeof preview.themeEditPreviewApp;
35
78
  export const themeEditPreviewList: typeof preview.themeEditPreviewList;
36
79
  /** @type {typeof preview.themeEditPreviewRemove} */
37
80
  export const themeEditPreviewRemove: typeof preview.themeEditPreviewRemove;
81
+ import { AstryxError } from '../error.mjs';
38
82
  import * as edit from './_edit.mjs';
39
83
  import * as preview from './_preview-app.mjs';
40
- export { themeEditHow, parsePoints } from "./_how.mjs";