@astryxdesign/cli 0.7.17 → 0.7.18-canary.g6dfc0b6

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 (213) hide show
  1. package/README.md +1 -1
  2. package/api/discover/_adapter.d.mts +7 -5
  3. package/api/discover/_adapter.mjs +12 -11
  4. package/api/doctor/_adapter.d.mts +11 -62
  5. package/api/doctor/_adapter.mjs +242 -472
  6. package/api/doctor/doctor.d.mts +1 -1
  7. package/api/doctor/doctor.mjs +1 -1
  8. package/api/doctor/theme-checks.mjs +37 -45
  9. package/api/error.d.mts +21 -0
  10. package/api/error.mjs +89 -0
  11. package/api/hook/list/list.d.mts +1 -1
  12. package/api/icon/icon.doc.mjs +1 -1
  13. package/api/icon/icon.type.mjs +1 -1
  14. package/api/icon/search/search.d.mts +4 -1
  15. package/api/icon/search/search.mjs +41 -4
  16. package/api/render/_adapter.mjs +233 -40
  17. package/api/render/render.type.d.mts +1 -1
  18. package/api/render/render.type.mjs +1 -1
  19. package/api/search/ORDERING.md +2 -2
  20. package/api/search/_candidate-score.mjs +32 -8
  21. package/api/search/_cards.json +1 -1
  22. package/api/search/_compound.d.mts +0 -1
  23. package/api/search/_compound.mjs +93 -2
  24. package/api/search/_lexical.mjs +177 -17
  25. package/api/search/_order.d.mts +3 -1
  26. package/api/search/_order.mjs +16 -5
  27. package/api/search/_result.d.mts +9 -0
  28. package/api/search/_result.mjs +10 -0
  29. package/api/search/_score.mjs +21 -3
  30. package/api/swizzle/_moduleGraph.d.mts +8 -0
  31. package/api/swizzle/_moduleGraph.mjs +61 -3
  32. package/api/template/copy/copy.mjs +5 -3
  33. package/api/theme/_adapter.mjs +48 -12
  34. package/api/theme/build/build.d.mts +4 -0
  35. package/api/theme/build/build.mjs +69 -18
  36. package/api/theme/build/style-keys.mjs +4 -5
  37. package/api/theme/build/theme-object.mjs +5 -0
  38. package/api/theme/palette/generate/color.d.mts +47 -0
  39. package/api/theme/palette/generate/color.mjs +58 -1
  40. package/api/theme/palette/generate/derive-look.d.mts +293 -0
  41. package/api/theme/palette/generate/derive-look.mjs +1362 -0
  42. package/api/theme/palette/generate/editor-look.d.mts +62 -0
  43. package/api/theme/palette/generate/editor-look.mjs +550 -0
  44. package/api/theme/palette/generate/mapping.d.mts +94 -9
  45. package/api/theme/palette/generate/mapping.mjs +94 -22
  46. package/api/theme-edit/_adapter.mjs +10 -1
  47. package/api/theme-edit/_catalog.d.mts +13 -13
  48. package/api/theme-edit/_catalog.mjs +38 -16
  49. package/api/theme-edit/_check.d.mts +82 -6
  50. package/api/theme-edit/_check.mjs +1230 -223
  51. package/api/theme-edit/_color.d.mts +74 -0
  52. package/api/theme-edit/_color.mjs +168 -3
  53. package/api/theme-edit/_compiler.d.mts +3 -5
  54. package/api/theme-edit/_compiler.mjs +122 -23
  55. package/api/theme-edit/_context.d.mts +46 -5
  56. package/api/theme-edit/_context.mjs +97 -49
  57. package/api/theme-edit/_css.d.mts +11 -0
  58. package/api/theme-edit/_css.mjs +40 -0
  59. package/api/theme-edit/_edit.d.mts +13 -0
  60. package/api/theme-edit/_edit.mjs +1450 -128
  61. package/api/theme-edit/_how-commands.d.mts +12 -0
  62. package/api/theme-edit/_how-commands.mjs +96 -14
  63. package/api/theme-edit/_how-question.d.mts +73 -29
  64. package/api/theme-edit/_how-question.mjs +8131 -1209
  65. package/api/theme-edit/_how-sides.d.mts +22 -0
  66. package/api/theme-edit/_how-sides.mjs +173 -0
  67. package/api/theme-edit/_how-steps.d.mts +42 -0
  68. package/api/theme-edit/_how-steps.mjs +208 -0
  69. package/api/theme-edit/_how-values.d.mts +29 -0
  70. package/api/theme-edit/_how-values.mjs +111 -0
  71. package/api/theme-edit/_how-words.d.mts +15 -0
  72. package/api/theme-edit/_how-words.mjs +239 -0
  73. package/api/theme-edit/_how.d.mts +1 -1
  74. package/api/theme-edit/_how.mjs +412 -37
  75. package/api/theme-edit/_missed.d.mts +2 -1
  76. package/api/theme-edit/_missed.mjs +125 -13
  77. package/api/theme-edit/_normal.d.mts +5 -3
  78. package/api/theme-edit/_normal.mjs +54 -14
  79. package/api/theme-edit/_palette.d.mts +204 -4
  80. package/api/theme-edit/_palette.mjs +901 -25
  81. package/api/theme-edit/_part-pieces.d.mts +54 -0
  82. package/api/theme-edit/_part-pieces.mjs +179 -0
  83. package/api/theme-edit/_part-words.mjs +33 -5
  84. package/api/theme-edit/_parts.d.mts +133 -0
  85. package/api/theme-edit/_parts.mjs +599 -10
  86. package/api/theme-edit/_picture-traits.d.mts +259 -0
  87. package/api/theme-edit/_picture-traits.mjs +1030 -0
  88. package/api/theme-edit/_preview.d.mts +84 -4
  89. package/api/theme-edit/_preview.mjs +260 -24
  90. package/api/theme-edit/_project.d.mts +14 -4
  91. package/api/theme-edit/_project.mjs +95 -26
  92. package/api/theme-edit/_set-line.d.mts +29 -0
  93. package/api/theme-edit/_set-line.mjs +100 -0
  94. package/api/theme-edit/_settings.d.mts +625 -28
  95. package/api/theme-edit/_settings.mjs +4587 -880
  96. package/api/theme-edit/_tables.d.mts +25 -1
  97. package/api/theme-edit/_tables.mjs +115 -11
  98. package/api/theme-edit/_text-looks.d.mts +78 -0
  99. package/api/theme-edit/_text-looks.mjs +376 -0
  100. package/api/theme-edit/_vet.d.mts +3 -26
  101. package/api/theme-edit/_vet.mjs +5 -89
  102. package/api/theme-edit/how/how.d.mts +1 -1
  103. package/api/theme-edit/how/how.mjs +1 -1
  104. package/api/theme-edit/theme-edit.type.d.mts +54 -1
  105. package/api/theme-edit/theme-edit.type.mjs +17 -2
  106. package/api/theme-edit/themeEditHow.doc.mjs +3 -3
  107. package/api/theme-edit/themeEditNew.doc.mjs +4 -0
  108. package/api/theme-edit/themeEditSet.doc.mjs +6 -2
  109. package/api/theme-edit/themeEditShow.doc.mjs +4 -0
  110. package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
  111. package/assets/component-list.generated.json +1 -1
  112. package/assets/docs/author-a-theme.doc.mjs +7 -4
  113. package/assets/docs/tree/export-pages.doc.mjs +1 -1
  114. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  115. package/assets/docs/use-a-theme.doc.mjs +89 -17
  116. package/assets/docs-routes.generated.json +1 -1
  117. package/assets/docs.generated.json +2 -2
  118. package/assets/icons/definitions/article.doc.mjs +9 -0
  119. package/assets/icons/template-icons.json +5 -0
  120. package/assets/search-catalog.generated.json +2 -2
  121. package/assets/self-audit.generated.json +1 -1
  122. package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
  123. package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
  124. package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
  125. package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
  126. package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
  127. package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
  128. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
  129. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
  130. package/assets/templates/components.generated.json +1 -1
  131. package/assets/templates/pages/ide/page.tsx +5 -10
  132. package/assets/templates/pages/payment-form/page.tsx +16 -60
  133. package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
  134. package/authoring/debug/parse.d.mts +1 -1
  135. package/authoring/doctypes/_schema.d.mts +13 -13
  136. package/authoring/gap-report/parse.d.mts +1 -1
  137. package/clients/cli/build-id.generated.json +1 -1
  138. package/clients/cli/commands/ensure-core-built.mjs +17 -10
  139. package/clients/cli/commands/experimental/theme.mjs +46 -6
  140. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  141. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  142. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
  143. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
  144. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  145. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  146. package/clients/cli/commands/hook.mjs +7 -0
  147. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  148. package/clients/cli/index.mjs +6 -2
  149. package/clients/cli/lib/hook-format.mjs +41 -1
  150. package/clients/cli/lib/json-shim.mjs +34 -14
  151. package/clients/cli/lib/other-cli-words.mjs +7 -0
  152. package/clients/cli/lib/unknown-command.mjs +345 -46
  153. package/clients/cli/manifest.generated.json +1 -1
  154. package/foundation/agent-docs/agent-docs.d.mts +11 -2
  155. package/foundation/agent-docs/agent-docs.mjs +51 -8
  156. package/foundation/config/project.d.mts +11 -1
  157. package/foundation/config/project.mjs +11 -2
  158. package/foundation/discovery/component-replacement.d.mts +5 -8
  159. package/foundation/discovery/component-replacement.mjs +12 -14
  160. package/foundation/discovery/core-augmentation-points.d.mts +35 -0
  161. package/foundation/discovery/core-augmentation-points.mjs +410 -9
  162. package/foundation/discovery/core-elements.d.mts +6 -0
  163. package/foundation/discovery/core-elements.mjs +10 -2
  164. package/foundation/discovery/core-prop-types.d.mts +5 -0
  165. package/foundation/discovery/core-prop-types.mjs +10 -3
  166. package/foundation/discovery/core-props.d.mts +8 -0
  167. package/foundation/discovery/core-props.mjs +29 -13
  168. package/foundation/discovery/official-list.d.mts +17 -0
  169. package/foundation/discovery/official-list.mjs +77 -0
  170. package/foundation/discovery/unknown-core-props.d.mts +130 -0
  171. package/foundation/discovery/unknown-core-props.mjs +601 -0
  172. package/foundation/discovery/written-prop-values.d.mts +35 -0
  173. package/foundation/discovery/written-prop-values.mjs +258 -0
  174. package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
  175. package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
  176. package/foundation/fs/package-name.d.mts +10 -0
  177. package/foundation/fs/package-name.mjs +37 -0
  178. package/foundation/fs/project-source-files.d.mts +27 -0
  179. package/foundation/fs/project-source-files.mjs +115 -0
  180. package/foundation/fs/project-sources.d.mts +25 -0
  181. package/foundation/fs/project-sources.mjs +83 -0
  182. package/foundation/fs/read-record.d.mts +18 -0
  183. package/foundation/fs/read-record.mjs +36 -2
  184. package/foundation/integrations/integration-warnings.d.mts +39 -7
  185. package/foundation/integrations/integration-warnings.mjs +141 -19
  186. package/foundation/integrations/missing-dependency.d.mts +11 -0
  187. package/foundation/integrations/missing-dependency.mjs +20 -5
  188. package/foundation/release/folder-lock.d.mts +5 -2
  189. package/foundation/release/folder-lock.mjs +9 -3
  190. package/foundation/release/notices.mjs +2 -8
  191. package/foundation/render/cut-short.d.mts +8 -2
  192. package/foundation/render/cut-short.mjs +50 -5
  193. package/foundation/render/drawn-contrast.d.mts +38 -0
  194. package/foundation/render/drawn-contrast.mjs +237 -0
  195. package/foundation/render/file-header.mjs +4 -0
  196. package/foundation/render/layers.d.mts +2 -1
  197. package/foundation/render/layers.mjs +22 -1
  198. package/foundation/render/page-worker.mjs +83 -18
  199. package/foundation/render/part-boxes.d.mts +27 -0
  200. package/foundation/render/part-boxes.mjs +45 -0
  201. package/foundation/render/picture-chrome.mjs +36 -4
  202. package/foundation/render/picture-playwright.mjs +26 -2
  203. package/foundation/render/picture-window.d.mts +29 -2
  204. package/foundation/render/picture-window.mjs +99 -1
  205. package/foundation/render/render-page.d.mts +39 -6
  206. package/foundation/render/render-page.mjs +26 -10
  207. package/foundation/render/ts-paths.mjs +2 -1
  208. package/foundation/response/error-codes.doc.mjs +1 -1
  209. package/foundation/response/error-codes.mjs +1 -1
  210. package/foundation/response/response-types.doc.mjs +1 -1
  211. package/foundation/text/written-string.d.mts +4 -1
  212. package/foundation/text/written-string.mjs +4 -1
  213. package/package.json +8 -7
@@ -719,7 +719,7 @@ export type DoctorContext = {
719
719
  * the project reads no Core or the scan failed.
720
720
  */
721
721
  coreProps?: {
722
- found: import("./_adapter.mjs").UnknownCoreProp[];
722
+ found: import("../../foundation/discovery/unknown-core-props.mjs").UnknownCoreProp[];
723
723
  uses: number;
724
724
  skipped: string | null;
725
725
  } | null | undefined;
@@ -228,7 +228,7 @@ import {
228
228
  * Each file in the project's own source with icon imports that do not
229
229
  * match its icon sets, read only when the placeholders are; null otherwise.
230
230
  * Experimental: may change or be removed in a patch release.
231
- * @property {{found: import('./_adapter.mjs').UnknownCoreProp[], uses: number, skipped: string | null}|null} [coreProps]
231
+ * @property {{found: import('../../foundation/discovery/unknown-core-props.mjs').UnknownCoreProp[], uses: number, skipped: string | null}|null} [coreProps]
232
232
  * The props the project's own source gives Core components that they do
233
233
  * not take, with how many props it read, or why it checked none; null when
234
234
  * the project reads no Core or the scan failed.
@@ -28,6 +28,8 @@ import {
28
28
  isLocalThemeOwner,
29
29
  listDoctorThemePackages,
30
30
  listProjectSourceFiles,
31
+ projectImportsModule,
32
+ specifierTargets,
31
33
  planThemeAppWrite,
32
34
  readPackageJson,
33
35
  readTextFile,
@@ -36,7 +38,6 @@ import {
36
38
  resolveDoctorThemeImports,
37
39
  resolveRecordedTheme,
38
40
  resolveThemeModule,
39
- SOURCE_EXTENSIONS,
40
41
  doctorStylesheetImportFile,
41
42
  fileMark,
42
43
  generatedSourceCommand,
@@ -253,42 +254,6 @@ export function moduleSpecifiers(source, options = {}) {
253
254
  return values;
254
255
  }
255
256
 
256
- /** @param {string} specifier @param {string} fromFile @param {string} target */
257
- function specifierTargets(specifier, fromFile, target) {
258
- if (!specifier.startsWith('.')) return false;
259
- const base = path.resolve(path.dirname(fromFile), specifier);
260
- const candidates = [
261
- base,
262
- ...[...SOURCE_EXTENSIONS].map(extension => `${base}${extension}`),
263
- ...[...SOURCE_EXTENSIONS].map(extension =>
264
- path.join(base, `index${extension}`),
265
- ),
266
- ];
267
- return candidates.some(
268
- candidate => path.resolve(candidate) === path.resolve(target),
269
- );
270
- }
271
-
272
- /** @param {string} root @param {string} generatedModule */
273
- function sourceImportEvidence(root, generatedModule) {
274
- let parseFailures = 0;
275
- for (const file of listProjectSourceFiles(root, generatedModule)) {
276
- try {
277
- const source = readTextFile(file);
278
- if (
279
- [...moduleSpecifiers(source)].some(specifier =>
280
- specifierTargets(specifier, file, generatedModule),
281
- )
282
- ) {
283
- return {found: true, parseFailures};
284
- }
285
- } catch {
286
- parseFailures += 1;
287
- }
288
- }
289
- return {found: false, parseFailures};
290
- }
291
-
292
257
  /**
293
258
  * Whether the file's leading comment says the CLI generated it: a theme
294
259
  * build, or a file of the theme editor (its settings module, its app copy).
@@ -620,7 +585,8 @@ function namedThemeFonts(files) {
620
585
  * local `@import`s (a relative file, or a package's stylesheet such as
621
586
  * `@fontsource/inter/index.css`), and the families the `family` parameters
622
587
  * of a font service URL it imports name; `external` when it imports a URL
623
- * (http, https, `//`), which may load families doctor cannot read.
588
+ * (http, https, `//`) that names no families doctor can read; `serviced`
589
+ * when it imports a font service URL that names its families.
624
590
  * @param {string} css
625
591
  * @param {string} [file] the stylesheet's path, to resolve local imports
626
592
  * @param {Set<string>} [seen]
@@ -629,17 +595,21 @@ function fontStylesheetEvidence(css, file, seen = new Set()) {
629
595
  const loaded = new Set();
630
596
  let external = false;
631
597
  let unread = false;
598
+ let serviced = false;
632
599
  const root = postcss().parse(css);
633
600
  root.walkAtRules(atRule => {
634
601
  if (atRule.name.toLowerCase() === 'import') {
635
602
  const spec = [...doctorStylesheetImports(`@import ${atRule.params};`)][0];
636
603
  if (!spec || /^(?:https?:)?\/\//i.test(spec)) {
637
604
  // A family the request names counts as loaded, as an @font-face rule
638
- // does: the stylesheet asks the service for it.
639
- for (const family of fontServiceFamilies(spec ?? '')) {
640
- loaded.add(family);
641
- }
642
- external = true;
605
+ // does: the stylesheet asks the service for it. A font service URL
606
+ // that names its families loads only those, so a family it does not
607
+ // name has no loader there; any other URL may load families doctor
608
+ // cannot read.
609
+ const named = fontServiceFamilies(spec ?? '');
610
+ for (const family of named) loaded.add(family);
611
+ if (named.size === 0) external = true;
612
+ else serviced = true;
643
613
  return;
644
614
  }
645
615
  const target = file ? doctorStylesheetImportFile(spec, file) : null;
@@ -664,6 +634,7 @@ function fontStylesheetEvidence(css, file, seen = new Set()) {
664
634
  );
665
635
  for (const name of inner.loaded) loaded.add(name);
666
636
  external ||= inner.external;
637
+ serviced ||= inner.serviced;
667
638
  unread ||= inner.unread;
668
639
  } catch {
669
640
  unread = true;
@@ -675,7 +646,7 @@ function fontStylesheetEvidence(css, file, seen = new Set()) {
675
646
  loaded.add(normalizeFontName(declaration.value).toLowerCase());
676
647
  });
677
648
  });
678
- return {loaded, external, unread};
649
+ return {loaded, external, unread, serviced};
679
650
  }
680
651
 
681
652
  /** @param {import('postcss').Rule} rule @param {string} slug */
@@ -1678,7 +1649,7 @@ export async function checkAppThemes(cwd) {
1678
1649
  });
1679
1650
  }
1680
1651
 
1681
- const importEvidence = sourceImportEvidence(
1652
+ const importEvidence = projectImportsModule(
1682
1653
  state.projectDir,
1683
1654
  state.module.file,
1684
1655
  );
@@ -2178,6 +2149,10 @@ export async function checkAppThemes(cwd) {
2178
2149
 
2179
2150
  const fontFailures = [];
2180
2151
  const externalFontWarnings = [];
2152
+ /** @type {string[]} */
2153
+ const unnamedFontWarnings = [];
2154
+ /** @type {string[]} */
2155
+ const unnamedFamilies = [];
2181
2156
  /** Families behind a local font import doctor could not follow. */
2182
2157
  const unreadFontWarnings = [];
2183
2158
  const missingFontWarnings = [];
@@ -2267,6 +2242,11 @@ export async function checkAppThemes(cwd) {
2267
2242
  if (missing.length === 0) continue;
2268
2243
  if (evidence.external) {
2269
2244
  externalFontWarnings.push(`${theme.slug}: ${missing.join(', ')}`);
2245
+ } else if (evidence.serviced) {
2246
+ // (AST-050 FR11 item 9: a font service URL that does not name the
2247
+ // family is a warning that names it, never a failure.)
2248
+ unnamedFontWarnings.push(`${theme.slug}: ${missing.join(', ')}`);
2249
+ unnamedFamilies.push(...missing);
2270
2250
  } else if (evidence.unread) {
2271
2251
  unreadFontWarnings.push(`${theme.slug}: ${missing.join(', ')}`);
2272
2252
  } else {
@@ -2305,6 +2285,18 @@ export async function checkAppThemes(cwd) {
2305
2285
  `Font imports doctor could not follow prevent proof for ${unreadFontWarnings.join('; ')}.`,
2306
2286
  );
2307
2287
  }
2288
+ if (unnamedFontWarnings.length > 0) {
2289
+ fontWarningMessages.push(
2290
+ `The font service stylesheet each theme imports does not name ${unnamedFontWarnings.join('; ')}.`,
2291
+ );
2292
+ const install = await fontPackagesInstallLine(
2293
+ state.projectDir,
2294
+ unnamedFamilies,
2295
+ );
2296
+ fontWarningFixes.push(
2297
+ `Add each named family to the font service URL${install.line ? `, or install the packages that load them (${install.line})` : ''}, or load it another way.`,
2298
+ );
2299
+ }
2308
2300
  if (externalFontWarnings.length > 0) {
2309
2301
  fontWarningMessages.push(
2310
2302
  `External font imports prevent proof for ${externalFontWarnings.join('; ')}.`,
package/api/error.d.mts CHANGED
@@ -34,6 +34,27 @@ export function writeFailed(target: string, cwd: string, cause: unknown, unresto
34
34
  outcome?: string;
35
35
  next?: string;
36
36
  }): AstryxError;
37
+ /**
38
+ * The refusal for a failure that is a broken install: an installed package
39
+ * (one in a node_modules folder, such as a package the CLI uses) needs a
40
+ * package it declares, and that package is not installed. The command's own
41
+ * subject (a theme, a page) is not at fault, so the refusal names both
42
+ * packages and how to install them again. When the run uses a CLI copy of
43
+ * its own (global, a package runner's or the release cache's) and the app's
44
+ * install does not hold the package that needs the missing one, the package
45
+ * is that copy's: installing the copy again repairs it and the app's install
46
+ * does not, so the refusal names the copy (a release-cache copy is installed
47
+ * again once its folder is gone). Otherwise the refusal names the app's
48
+ * install command. A missing import in the app's own files is not a broken
49
+ * install: it stays the caller's failure.
50
+ *
51
+ * @param {unknown} cause the error the load threw
52
+ * @param {string} cwd project root, for its install and package manager
53
+ * @param {string} [outcome] what the command left as it was
54
+ * @param {string} [cliRoot] the running CLI package's folder
55
+ * @returns {AstryxError | null} null when the cause is not a broken install
56
+ */
57
+ export function brokenInstallError(cause: unknown, cwd: string, outcome?: string, cliRoot?: string): AstryxError | null;
37
58
  /**
38
59
  * Locate the Core a command answers from (`requireCoreDir` in
39
60
  * foundation/fs/paths.mjs), raising its coded failure as an AstryxError:
package/api/error.mjs CHANGED
@@ -12,6 +12,19 @@
12
12
  */
13
13
 
14
14
  import {ERROR_CODES} from '../foundation/response/error-codes.mjs';
15
+ import {
16
+ explainPackageManager,
17
+ installDependenciesCommand,
18
+ } from '../foundation/env/package-manager.mjs';
19
+ import {relativeWithin, samePath} from '../foundation/fs/path-compare.mjs';
20
+ import {
21
+ CLI_ROOT,
22
+ findNodeModulesPackage,
23
+ realDir,
24
+ } from '../foundation/fs/paths.mjs';
25
+ import {installPlaceOf, isGlobalCopy} from '../foundation/release/choose.mjs';
26
+ import {isInReleaseCache} from '../foundation/release/cache.mjs';
27
+ import {brokenInstall} from '../foundation/integrations/missing-dependency.mjs';
15
28
  import * as path from 'node:path';
16
29
 
17
30
  export class AstryxError extends Error {
@@ -91,6 +104,82 @@ export function writeFailed(target, cwd, cause, unrestored = [], say = {}) {
91
104
  );
92
105
  }
93
106
 
107
+ /**
108
+ * The refusal for a failure that is a broken install: an installed package
109
+ * (one in a node_modules folder, such as a package the CLI uses) needs a
110
+ * package it declares, and that package is not installed. The command's own
111
+ * subject (a theme, a page) is not at fault, so the refusal names both
112
+ * packages and how to install them again. When the run uses a CLI copy of
113
+ * its own (global, a package runner's or the release cache's) and the app's
114
+ * install does not hold the package that needs the missing one, the package
115
+ * is that copy's: installing the copy again repairs it and the app's install
116
+ * does not, so the refusal names the copy (a release-cache copy is installed
117
+ * again once its folder is gone). Otherwise the refusal names the app's
118
+ * install command. A missing import in the app's own files is not a broken
119
+ * install: it stays the caller's failure.
120
+ *
121
+ * @param {unknown} cause the error the load threw
122
+ * @param {string} cwd project root, for its install and package manager
123
+ * @param {string} [outcome] what the command left as it was
124
+ * @param {string} [cliRoot] the running CLI package's folder
125
+ * @returns {AstryxError | null} null when the cause is not a broken install
126
+ */
127
+ export function brokenInstallError(cause, cwd, outcome, cliRoot = CLI_ROOT) {
128
+ const found = brokenInstall(
129
+ cause instanceof Error ? cause.message : String(cause),
130
+ );
131
+ if (!found || !found.importer.split(/[\\/]/).includes('node_modules'))
132
+ return null;
133
+ const done = outcome ? ` ${outcome}` : '';
134
+ const what = `${found.requiredBy} needs ${found.name}, which is missing or incomplete`;
135
+ const cli = realDir(cliRoot);
136
+ const cached = isInReleaseCache(cli);
137
+ const place = installPlaceOf(cli);
138
+ if (
139
+ (cached || place.runner || isGlobalCopy(cli)) &&
140
+ !appLinks(cwd, found.requiredBy, found.importer)
141
+ )
142
+ return new AstryxError(
143
+ cached
144
+ ? `The CLI release this run uses is not fully installed: ${what}. Remove ${place.owner ?? cli} so the next run installs that release again, then run the command again.${done}`
145
+ : `The CLI copy this run uses (${cli}) is not fully installed: ${what}. The app's install does not hold ${found.requiredBy}, so install that copy of the CLI again, then run the command again.${done}`,
146
+ undefined,
147
+ ERROR_CODES.ERR_DEP_MISSING,
148
+ );
149
+ const install = installDependenciesCommand(cwd);
150
+ return new AstryxError(
151
+ `The app's packages are not fully installed: ${what} in node_modules. Run ${install} to install them again, then run the command again.${done}`,
152
+ [
153
+ {
154
+ name: install,
155
+ reason: `install the app's packages again: ${found.requiredBy} needs ${found.name}`,
156
+ },
157
+ ],
158
+ ERROR_CODES.ERR_DEP_MISSING,
159
+ );
160
+ }
161
+
162
+ /**
163
+ * Whether the app's own install holds the package `name` that `importer` is
164
+ * in: the importer is in the app's folder, or the app resolves `name` to
165
+ * that same folder, wherever its package manager keeps it.
166
+ * @param {string} cwd
167
+ * @param {string} name
168
+ * @param {string} importer
169
+ * @returns {boolean}
170
+ */
171
+ function appLinks(cwd, name, importer) {
172
+ const app = explainPackageManager(cwd).dir ?? cwd;
173
+ const at = realDir(path.dirname(importer));
174
+ if (relativeWithin(realDir(app), at) !== null) return true;
175
+ // Found in node_modules only, never through NODE_PATH or Node's global
176
+ // folders, which can hold the CLI copy itself.
177
+ const folder = findNodeModulesPackage(app, name)?.packageDir;
178
+ if (!folder) return false;
179
+ const linked = realDir(folder);
180
+ return samePath(linked, at) || relativeWithin(linked, at) !== null;
181
+ }
182
+
94
183
  /**
95
184
  * Locate the Core a command answers from (`requireCoreDir` in
96
185
  * foundation/fs/paths.mjs), raising its coded failure as an AstryxError:
@@ -13,7 +13,7 @@
13
13
  export function list({ cwd, category, detail, zh, lang, }?: {
14
14
  cwd?: string | undefined;
15
15
  category?: string | undefined;
16
- detail?: "names" | "compact" | "full" | "brief" | undefined;
16
+ detail?: "compact" | "full" | "names" | "brief" | undefined;
17
17
  zh?: boolean | undefined;
18
18
  lang?: string | null | undefined;
19
19
  }): Promise<import("../hook.type.mjs").HookListResponse>;
@@ -69,7 +69,7 @@ export const doc = {
69
69
  {
70
70
  type: 'icon.search',
71
71
  description:
72
- "The query, how many icons matched, and the ranked matches, each with its set, id, package, module, export, import line, words, filled names, variants, reason, and score, plus `relatives` (the other definitions in the groups of the ones it draws) when there are any. A replaced definition's old name answers like its successor's name. A match that a definition names also has `meaningImport`: the import line that names the icon by that meaning (`import {TrashIcon as DeleteIcon} from '…'`), so app code keeps the name when another set draws it. No match is an empty list. When the project picks a look (`experimental.iconVariant`), a match from a set in the project's list has the module, export, and import of that look; one whose icon lacks the look keeps its own and names both looks in `look` ({asked, used}). With no icon set installed, `reason` says so, `definitions` lists the Astryx icon definitions that match ({name, builtIn, description}, plus `group` and `relatives` for a definition in a group), built-in ones first, since Core draws those by name, and `next` says how to get a set.",
72
+ "The query, how many icons matched, and the ranked matches, each with its set, id, package, module, export, import line, words, filled names, variants, reason, and score, plus `relatives` (the other definitions in the groups of the ones it draws) when there are any. A replaced definition's old name answers like its successor's name. A match that a definition names also has `meaningImport`: the import line that names the icon by that meaning (`import {TrashIcon as DeleteIcon} from '…'`), so app code keeps the name when another set draws it. No match is an empty list. When the project picks a look (`experimental.iconVariant`), a match from a set in the project's list has the module, export, and import of that look; one whose icon lacks the look keeps its own and names both looks in `look` ({asked, used}). With no icon set installed, `reason` says so, `definitions` lists the Astryx icon definitions that match ({name, builtIn, description}, plus `group` and `relatives` for a definition in a group), built-in ones first, since Core draws those by name; a matching definition that Core does not draw brings the built-in that draws in its place (`help` brings `info`) unless a match ranked above it has none, and `next` says how to get a set.",
73
73
  },
74
74
  {
75
75
  type: 'icon.detail',
@@ -88,7 +88,7 @@
88
88
  * @property {number} data.matchCount - Every match, before `limit`.
89
89
  * @property {IconMatchEntry[]} data.matches - The ranked matches, at most `limit`.
90
90
  * @property {string} [data.reason] - Present when no icon set is installed: why nothing matches.
91
- * @property {IconSearchDefinition[]} [data.definitions] - Present when no icon set is installed: the Astryx icon definitions that match, built-in ones first, at most `limit`.
91
+ * @property {IconSearchDefinition[]} [data.definitions] - Present when no icon set is installed: the Astryx icon definitions that match, built-in ones first, with the built-in that draws in place of a matching definition Core does not draw (`help` brings `info`) unless a match ranked above it has none, at most `limit`.
92
92
  * @property {string} [data.next] - Present when no icon set is installed: how to get one.
93
93
  */
94
94
 
@@ -41,7 +41,10 @@ export function projectLooks(choice: import("../../../foundation/discovery/icon-
41
41
  * names for its set when its icon has that look, and a match that a
42
42
  * definition names also has its meaning import. With no set installed, not
43
43
  * even a withdrawn one, the answer names the Astryx icon definitions that
44
- * match, built-in ones first, and how to get a set.
44
+ * match, built-in ones first, with the built-in that draws in place of a
45
+ * matching definition Core does not draw (unless a match ranked above it has
46
+ * none),
47
+ * and how to get a set.
45
48
  * @param {Parameters<typeof rankIcons>[0]} sets in tie order
46
49
  * @param {Array<{name: string, package: string, reason: string}>} withdrawn
47
50
  * @param {string} query
@@ -19,6 +19,7 @@ import {
19
19
  iconSetKey,
20
20
  importLine,
21
21
  loadIconSets,
22
+ meaningWithFallbacks,
22
23
  missingIconLook,
23
24
  noIconSetNext,
24
25
  } from '../_adapter.mjs';
@@ -186,7 +187,10 @@ export function projectLooks(choice) {
186
187
  * names for its set when its icon has that look, and a match that a
187
188
  * definition names also has its meaning import. With no set installed, not
188
189
  * even a withdrawn one, the answer names the Astryx icon definitions that
189
- * match, built-in ones first, and how to get a set.
190
+ * match, built-in ones first, with the built-in that draws in place of a
191
+ * matching definition Core does not draw (unless a match ranked above it has
192
+ * none),
193
+ * and how to get a set.
190
194
  * @param {Parameters<typeof rankIcons>[0]} sets in tie order
191
195
  * @param {Array<{name: string, package: string, reason: string}>} withdrawn
192
196
  * @param {string} query
@@ -289,7 +293,9 @@ function inLook(match, sets, looks) {
289
293
  /**
290
294
  * The answer when no icon set is installed: no icon matches, so it names
291
295
  * the Astryx icon definitions that do, built-in ones first (Core draws those
292
- * by name with no set), and how to get a set.
296
+ * by name with no set) with the built-in that draws in place of a matching
297
+ * definition Core does not draw, unless a match ranked above it has none,
298
+ * and how to get a set.
293
299
  * @param {string} query
294
300
  * @param {number} limit
295
301
  * @param {boolean} discoverListsPacks
@@ -297,11 +303,42 @@ function inLook(match, sets, looks) {
297
303
  */
298
304
  function noIconSet(query, limit, discoverListsPacks) {
299
305
  const docs = astryxIconDefinitions().definitions.map(each => each.doc);
306
+ const byName = new Map(docs.map(doc => [doc.name, doc]));
300
307
  const found = definitionMatches(query).map(match => match.doc);
301
- const ordered = [
308
+ const matched = new Set(
309
+ found.filter(doc => doc.builtIn).map(doc => doc.name),
310
+ );
311
+ // With no set, Core draws only the built-in definitions, so a matching
312
+ // definition that Core does not draw lists the built-in that draws in its
313
+ // place (FR23's fallback). Only the ones that rank above every matching
314
+ // definition with no such built-in count: a match ranked above that Core
315
+ // cannot draw at all is what the ask names (`settings`), not a weaker
316
+ // match's fallback. A built-in the query matches too takes the better of
317
+ // its own place and theirs; one that only a fallback brings comes after
318
+ // the built-ins that match.
319
+ /** @param {(typeof docs)[number]} doc */
320
+ const drawnAs = doc =>
321
+ meaningWithFallbacks(doc.name)
322
+ .map(name => byName.get(name))
323
+ .find(each => each?.builtIn);
324
+ const end = found.findIndex(doc => !drawnAs(doc));
325
+ const counted = end < 0 ? found : found.slice(0, end);
326
+ const builtIns = [
327
+ ...counted.flatMap(doc => {
328
+ const drawn = drawnAs(doc);
329
+ return drawn && matched.has(drawn.name) ? [drawn] : [];
330
+ }),
302
331
  ...found.filter(doc => doc.builtIn),
303
- ...found.filter(doc => !doc.builtIn),
304
332
  ];
333
+ const brought = counted.flatMap(doc => {
334
+ const drawn = doc.builtIn ? undefined : drawnAs(doc);
335
+ return drawn && !matched.has(drawn.name) ? [drawn] : [];
336
+ });
337
+ const ordered = [
338
+ ...builtIns,
339
+ ...brought,
340
+ ...found.filter(doc => !doc.builtIn),
341
+ ].filter((doc, i, list) => list.findIndex(o => o.name === doc.name) === i);
305
342
  return {
306
343
  type: 'icon.search',
307
344
  data: {