@astryxdesign/cli 0.7.5-canary.d8e3b38 → 0.7.5-canary.fccd771

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 (214) hide show
  1. package/README.md +18 -18
  2. package/api/component/_adapter.mjs +16 -1
  3. package/api/component/component.test.mjs +31 -0
  4. package/api/discover/_adapter.d.mts +1 -1
  5. package/api/docs/_adapter.d.mts +5 -2
  6. package/api/docs/_adapter.mjs +24 -16
  7. package/api/docs/docs.test.mjs +18 -0
  8. package/api/docs/integrationDocs.test.mjs +2 -2
  9. package/api/experimental.d.mts +5 -0
  10. package/api/experimental.mjs +15 -0
  11. package/api/hook/list/list.d.mts +1 -1
  12. package/api/icon/_adapter.d.mts +3 -2
  13. package/api/icon/_adapter.mjs +16 -3
  14. package/api/icon/_authoring.d.mts +5 -1
  15. package/api/icon/_authoring.mjs +478 -63
  16. package/api/icon/_options.d.mts +11 -0
  17. package/api/icon/_options.mjs +39 -4
  18. package/api/icon/_records.d.mts +19 -0
  19. package/api/icon/_records.mjs +25 -0
  20. package/api/icon/add/add.d.mts +3 -3
  21. package/api/icon/add/add.mjs +227 -14
  22. package/api/icon/all-or-nothing.test.mjs +283 -0
  23. package/api/icon/detail/detail.mjs +2 -13
  24. package/api/icon/error-codes.test.mjs +14 -7
  25. package/api/icon/icon.d.mts +2 -2
  26. package/api/icon/icon.doc.mjs +30 -2
  27. package/api/icon/icon.mjs +57 -8
  28. package/api/icon/icon.test.mjs +133 -1
  29. package/api/icon/icon.type.d.mts +126 -1
  30. package/api/icon/icon.type.mjs +67 -3
  31. package/api/icon/iconAdd.doc.mjs +22 -6
  32. package/api/icon/iconMap.doc.mjs +24 -8
  33. package/api/icon/iconNewDefinition.doc.mjs +2 -2
  34. package/api/icon/iconNewSet.doc.mjs +30 -2
  35. package/api/icon/iconUse.doc.mjs +4 -1
  36. package/api/icon/map/map.d.mts +4 -4
  37. package/api/icon/map/map.mjs +134 -9
  38. package/api/icon/new-definition/new-definition.mjs +6 -2
  39. package/api/icon/new-set/new-set.mjs +2 -2
  40. package/api/icon/new-set/new-set.test.mjs +60 -10
  41. package/api/icon/option-pairs.test.mjs +368 -0
  42. package/api/icon/search/search.d.mts +10 -0
  43. package/api/icon/search/search.mjs +55 -14
  44. package/api/icon/use/use.mjs +2 -13
  45. package/api/integration/add-helpers.d.mts +15 -1
  46. package/api/integration/add-helpers.mjs +1 -1
  47. package/api/integration/validate-integration.type.d.mts +3 -2
  48. package/api/integration/validate-integration.type.mjs +3 -2
  49. package/api/render/_adapter.d.mts +28 -0
  50. package/api/render/_adapter.mjs +540 -0
  51. package/api/render/render.d.mts +15 -0
  52. package/api/render/render.doc.d.mts +9 -0
  53. package/api/render/render.doc.mjs +112 -0
  54. package/api/render/render.mjs +113 -0
  55. package/api/render/render.test.mjs +1155 -0
  56. package/api/render/render.type.d.mts +74 -0
  57. package/api/render/render.type.mjs +64 -0
  58. package/api/search/_adapter.test.mjs +21 -2
  59. package/api/search/_result.d.mts +5 -5
  60. package/api/search/search.d.mts +1 -1
  61. package/api/template/template.mjs +3 -1
  62. package/api/template/template.type.d.mts +2 -1
  63. package/api/template/template.type.mjs +1 -1
  64. package/api/template/unknown-name.test.mjs +63 -0
  65. package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
  66. package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
  67. package/assets/docs/tree/icon-sets.doc.mjs +50 -20
  68. package/assets/docs/tree/render-pages.doc.mjs +94 -0
  69. package/assets/icons/definitions/activity.doc.mjs +1 -1
  70. package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
  71. package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
  72. package/assets/icons/definitions/alignStart.doc.mjs +10 -0
  73. package/assets/icons/definitions/archive.doc.mjs +1 -1
  74. package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
  75. package/assets/icons/definitions/attach.doc.mjs +1 -1
  76. package/assets/icons/definitions/audio.doc.mjs +1 -1
  77. package/assets/icons/definitions/cart.doc.mjs +1 -1
  78. package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
  79. package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
  80. package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
  81. package/assets/icons/definitions/close.doc.mjs +1 -1
  82. package/assets/icons/definitions/collapse.doc.mjs +1 -1
  83. package/assets/icons/definitions/compose.doc.mjs +1 -1
  84. package/assets/icons/definitions/conversation.doc.mjs +1 -1
  85. package/assets/icons/definitions/copy.doc.mjs +1 -1
  86. package/assets/icons/definitions/cpu.doc.mjs +9 -0
  87. package/assets/icons/definitions/database.doc.mjs +1 -1
  88. package/assets/icons/definitions/desktop.doc.mjs +1 -1
  89. package/assets/icons/definitions/discount.doc.mjs +1 -1
  90. package/assets/icons/definitions/download.doc.mjs +1 -1
  91. package/assets/icons/definitions/emoji.doc.mjs +1 -1
  92. package/assets/icons/definitions/error.doc.mjs +1 -1
  93. package/assets/icons/definitions/expand.doc.mjs +1 -1
  94. package/assets/icons/definitions/experiment.doc.mjs +1 -1
  95. package/assets/icons/definitions/externalLink.doc.mjs +7 -1
  96. package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
  97. package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
  98. package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
  99. package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
  100. package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
  101. package/assets/icons/definitions/gitFork.doc.mjs +9 -0
  102. package/assets/icons/definitions/info.doc.mjs +1 -1
  103. package/assets/icons/definitions/location.doc.mjs +1 -1
  104. package/assets/icons/definitions/mention.doc.mjs +1 -1
  105. package/assets/icons/definitions/menu.doc.mjs +1 -1
  106. package/assets/icons/definitions/microphone.doc.mjs +1 -1
  107. package/assets/icons/definitions/mobile.doc.mjs +1 -1
  108. package/assets/icons/definitions/money.doc.mjs +1 -1
  109. package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
  110. package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
  111. package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
  112. package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
  113. package/assets/icons/definitions/panelRight.doc.mjs +10 -0
  114. package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
  115. package/assets/icons/definitions/redo.doc.mjs +1 -1
  116. package/assets/icons/definitions/refresh.doc.mjs +1 -1
  117. package/assets/icons/definitions/rotate.doc.mjs +9 -0
  118. package/assets/icons/definitions/scale.doc.mjs +10 -0
  119. package/assets/icons/definitions/search.doc.mjs +1 -1
  120. package/assets/icons/definitions/send.doc.mjs +1 -1
  121. package/assets/icons/definitions/settings.doc.mjs +1 -1
  122. package/assets/icons/definitions/star.doc.mjs +1 -1
  123. package/assets/icons/definitions/stop.doc.mjs +1 -1
  124. package/assets/icons/definitions/success.doc.mjs +1 -1
  125. package/assets/icons/definitions/textCase.doc.mjs +9 -0
  126. package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
  127. package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
  128. package/assets/icons/definitions/trendDown.doc.mjs +7 -1
  129. package/assets/icons/definitions/trendUp.doc.mjs +1 -1
  130. package/assets/icons/definitions/undo.doc.mjs +1 -1
  131. package/assets/icons/definitions/upload.doc.mjs +1 -1
  132. package/assets/icons/definitions/userAdd.doc.mjs +1 -1
  133. package/assets/icons/definitions/warning.doc.mjs +1 -1
  134. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
  135. package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
  136. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
  137. package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
  138. package/authoring/debug/parse.d.mts +2 -2
  139. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
  140. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
  141. package/authoring/doctypes/icon-set/parse.d.mts +1 -0
  142. package/authoring/doctypes/icon-set/parse.mjs +1 -0
  143. package/authoring/doctypes/icon-set/type.ts +5 -0
  144. package/authoring/doctypes/template/template.doc.mjs +1 -1
  145. package/authoring/doctypes/template/type.ts +2 -1
  146. package/clients/cli/commands/doctor.mjs +16 -17
  147. package/clients/cli/commands/experimental/icon.mjs +167 -35
  148. package/clients/cli/commands/experimental/index.mjs +2 -0
  149. package/clients/cli/commands/experimental/render.mjs +113 -0
  150. package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
  151. package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
  152. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
  153. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
  154. package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
  155. package/clients/cli/commands/experimental-render.doc.mjs +60 -0
  156. package/clients/cli/commands/experimental.doc.mjs +4 -2
  157. package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
  158. package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
  159. package/clients/cli/commands/icon.test.mjs +1 -1
  160. package/clients/cli/commands/template.mjs +4 -1
  161. package/clients/cli/commands/text-json-parity.test.mjs +46 -0
  162. package/clients/cli/index.mjs +1 -0
  163. package/foundation/discovery/icon-set-checks.d.mts +43 -9
  164. package/foundation/discovery/icon-set-checks.mjs +296 -21
  165. package/foundation/discovery/icon-set-checks.test.mjs +125 -12
  166. package/foundation/discovery/icon-set-writer.d.mts +192 -3
  167. package/foundation/discovery/icon-set-writer.mjs +608 -34
  168. package/foundation/discovery/icon-set-writer.test.mjs +26 -0
  169. package/foundation/discovery/module-exports.mjs +82 -25
  170. package/foundation/discovery/module-exports.test.mjs +38 -1
  171. package/foundation/discovery/template-icons.d.mts +6 -0
  172. package/foundation/discovery/template-icons.mjs +98 -10
  173. package/foundation/discovery/template-icons.test.mjs +103 -0
  174. package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
  175. package/foundation/doc-compiler/import.mjs +81 -8
  176. package/foundation/doc-compiler/read.d.mts +4 -3
  177. package/foundation/doc-compiler/read.mjs +15 -10
  178. package/foundation/doc-compiler/read.test.mjs +59 -1
  179. package/foundation/doc-compiler/tree.mjs +3 -1
  180. package/foundation/fs/module-loader.d.mts +3 -2
  181. package/foundation/fs/module-loader.mjs +3 -2
  182. package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
  183. package/foundation/fs/read-record.d.mts +27 -0
  184. package/foundation/fs/read-record.mjs +83 -15
  185. package/foundation/fs/read-record.test.mjs +88 -1
  186. package/foundation/render/assets.d.mts +31 -0
  187. package/foundation/render/assets.mjs +102 -0
  188. package/foundation/render/component-map.d.mts +52 -0
  189. package/foundation/render/component-map.mjs +141 -0
  190. package/foundation/render/css-cut.d.mts +29 -0
  191. package/foundation/render/css-cut.mjs +144 -0
  192. package/foundation/render/embedded-files.d.mts +28 -0
  193. package/foundation/render/embedded-files.mjs +108 -0
  194. package/foundation/render/embedded-imports.d.mts +61 -0
  195. package/foundation/render/embedded-imports.mjs +315 -0
  196. package/foundation/render/html-reader.d.mts +37 -0
  197. package/foundation/render/html-reader.mjs +121 -0
  198. package/foundation/render/page-worker.d.mts +7 -0
  199. package/foundation/render/page-worker.mjs +519 -0
  200. package/foundation/render/rebuild.d.mts +19 -0
  201. package/foundation/render/rebuild.mjs +269 -0
  202. package/foundation/render/render-page.d.mts +85 -0
  203. package/foundation/render/render-page.mjs +612 -0
  204. package/foundation/render/render.test.mjs +117 -0
  205. package/foundation/render/source-block.d.mts +52 -0
  206. package/foundation/render/source-block.mjs +106 -0
  207. package/foundation/response/error-codes.d.mts +10 -1
  208. package/foundation/response/error-codes.doc.mjs +56 -0
  209. package/foundation/response/error-codes.mjs +61 -0
  210. package/foundation/response/response-types.doc.mjs +38 -1
  211. package/foundation/text/suggest-order.d.mts +17 -3
  212. package/foundation/text/suggest-order.mjs +58 -13
  213. package/foundation/text/suggest-order.test.mjs +53 -0
  214. package/package.json +14 -9
package/README.md CHANGED
@@ -96,24 +96,24 @@ Each command declares what it does in a folder outside any project, and `astryx
96
96
 
97
97
  <!-- BEGIN GENERATED: commands -->
98
98
 
99
- | Command | Description | Outside a project |
100
- | -------------- | ----------------------------------------------------------------------------- | ----------------- |
101
- | `blog` | Read the Astryx blog from the published feed | `same` |
102
- | `build` | Build a page: the template to start from, or the workflow playbook (no query) | `same` |
103
- | `component` | List components or print component docs | `same` |
104
- | `discover` | Browse and search integrations: the ones you have and the ones you could add | `same` |
105
- | `docs` | Print reference docs | `same` |
106
- | `doctor` | Diagnose Astryx projects and integration packages | `own` |
107
- | `experimental` | [experimental] Try features that may change or be removed in a patch release | by subcommand |
108
- | `gap-report` | Report a missing component or feature to the package that owns it | `same` |
109
- | `hook` | List hooks or print hook docs | `same` |
110
- | `init` | Initialize the design system in your project | `own` |
111
- | `integration` | Author and verify an Astryx integration package | by subcommand |
112
- | `search` | Search components, hooks, docs, templates, and themes in one ranked list | `same` |
113
- | `swizzle` | Copy component source for customization | `refuse` |
114
- | `template` | List, show, or scaffold page and block templates | `same` |
115
- | `theme` | Add, switch, build, and author themes | by subcommand |
116
- | `upgrade` | Update your code after upgrading Astryx, and refresh ShadCN-copied components | `own` |
99
+ | Command | Description | Outside a project |
100
+ | -------------- | ----------------------------------------------------------------------------------------------------------------- | ----------------- |
101
+ | `blog` | Read the Astryx blog from the published feed | `same` |
102
+ | `build` | Build a page: the template to start from, or the workflow playbook (no query) | `same` |
103
+ | `component` | List components or print component docs | `same` |
104
+ | `discover` | Browse and search integrations: the ones you have and the ones you could add | `same` |
105
+ | `docs` | Print reference docs | `same` |
106
+ | `doctor` | Diagnose Astryx projects and integration packages | `own` |
107
+ | `experimental` | [experimental] Try features that may change in a patch release: icon sets (find icons, build an icon-set package) | by subcommand |
108
+ | `gap-report` | Report a missing component or feature to the package that owns it | `same` |
109
+ | `hook` | List hooks or print hook docs | `same` |
110
+ | `init` | Initialize the design system in your project | `own` |
111
+ | `integration` | Author and verify an Astryx integration package | by subcommand |
112
+ | `search` | Search components, hooks, docs, templates, and themes in one ranked list | `same` |
113
+ | `swizzle` | Copy component source for customization | `refuse` |
114
+ | `template` | List, show, or scaffold page and block templates | `same` |
115
+ | `theme` | Add, switch, build, and author themes | by subcommand |
116
+ | `upgrade` | Update your code after upgrading Astryx, and refresh ShadCN-copied components | `own` |
117
117
 
118
118
  <!-- END GENERATED: commands -->
119
119
  <!-- Generated by scripts/generate-cli-readme.mjs from `astryx manifest`. Run `pnpm -F @astryxdesign/cli readme`. -->
@@ -49,12 +49,16 @@ import {
49
49
  synonymMatches,
50
50
  } from '../../foundation/text/suggest-order.mjs';
51
51
  import {AstryxError, coreDirOrThrow} from '../error.mjs';
52
+ import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
52
53
  import {
53
54
  componentLinkProvider,
54
55
  linkComponentDoc,
55
56
  loadDocsCatalog,
56
57
  } from '../docs/_adapter.mjs';
57
58
 
59
+ /** How far below the first suggestion's score a later one may be. */
60
+ const NEAR_FIRST = 10;
61
+
58
62
  /** @type {Record<string, {synonyms?: string[]}> | undefined} */
59
63
  let cards;
60
64
  /**
@@ -503,9 +507,20 @@ export async function resolveUnscopedDoc(dirName, {coreDir, cwd, name}) {
503
507
  Object.values(components).flat(),
504
508
  synonymMatches(dirName, searchCards()),
505
509
  ).slice(0, count);
510
+ // Past the first two suggestions, only the ones about as close as
511
+ // the first (within NEAR_FIRST points), or a close spelling of the
512
+ // whole typed name (a typo): a weaker match after a strong one reads
513
+ // as noise. The list only gets shorter and keeps at least two.
514
+ const typed = dirName.toLowerCase();
515
+ const nearFirst = candidates.filter(
516
+ (c, i) =>
517
+ i < 2 ||
518
+ c.score >= candidates[0].score - NEAR_FIRST ||
519
+ levenshteinDistance(c.name.toLowerCase(), typed) <= 2,
520
+ );
506
521
  throw new AstryxError(
507
522
  `No component named "${name}"`,
508
- candidates.map(c => ({name: c.name, reason: c.reason})),
523
+ nearFirst.map(c => ({name: c.name, reason: c.reason})),
509
524
  ERROR_CODES.ERR_UNKNOWN_COMPONENT,
510
525
  );
511
526
  }
@@ -499,3 +499,34 @@ describe('component dispatcher — detail levels on single component (text only)
499
499
  SLOW,
500
500
  );
501
501
  });
502
+
503
+ describe('component not-found suggestions', () => {
504
+ const suggested = async (/** @type {string} */ name) => {
505
+ const error = await component(name, {cwd}).catch(e => e);
506
+ expect(error).toBeInstanceOf(AstryxError);
507
+ expect(error.code).toBe('ERR_UNKNOWN_COMPONENT');
508
+ return error.suggestions.map((/** @type {{name: string}} */ s) => s.name);
509
+ };
510
+
511
+ it(
512
+ 'leaves out a weaker match after a strong first suggestion',
513
+ async () => {
514
+ // FieldLabel is another name for it; past the second suggestion, the
515
+ // matches on one word of the name ("input", "label") are weaker and add
516
+ // only noise.
517
+ const names = await suggested('InputLabel');
518
+ expect(names[0]).toBe('FieldLabel');
519
+ expect(names).toHaveLength(2);
520
+ },
521
+ SLOW,
522
+ );
523
+
524
+ it(
525
+ 'keeps a close spelling of the whole name after a stronger first match',
526
+ async () => {
527
+ expect(await suggested('Blockqoute')).toContain('Blockquote');
528
+ expect(await suggested('TextrAea')).toContain('TextArea');
529
+ },
530
+ SLOW,
531
+ );
532
+ });
@@ -216,7 +216,7 @@ export const OFFICIAL_LIST_FILE: string;
216
216
  */
217
217
  export const EXPERIMENTAL_KINDS: readonly ["icon-set"];
218
218
  /** The item kinds every project reads: the catalog kinds, less experimental ones. */
219
- export const STABLE_KINDS: ("component" | "theme" | "codemod" | "agent-doc" | "doc" | "template" | "icon-set")[];
219
+ export const STABLE_KINDS: ("template" | "component" | "theme" | "codemod" | "agent-doc" | "doc" | "icon-set")[];
220
220
  /** The list and detail entry fields for each item kind, in display order. */
221
221
  export const KIND_FIELDS: readonly [readonly ["component", "components"], readonly ["template", "templates"], readonly ["doc", "docs"], readonly ["theme", "themes"], readonly ["codemod", "codemods"], readonly ["agent-doc", "agentDocs"], readonly ["icon-set", "iconSets"]];
222
222
  export type ScannedPackage = import("./_package-scanner.mjs").ScannedPackage;
@@ -335,8 +335,11 @@ export function holdsOwnName(tree: DocsTree, catalog: DocsCatalog, entry: import
335
335
  export function routeOwner(tree: DocsTree, entry: import("../../foundation/discovery/docs-discovery.mjs").DocsTopicEntry): TreeNode | null;
336
336
  /**
337
337
  * The error for a docs argument that names nothing. For a route, it suggests
338
- * the children of the deepest namespace the route reaches; otherwise, every
339
- * topic and every top-level namespace.
338
+ * every child of the deepest namespace the route reaches, closest first.
339
+ * Otherwise it suggests the docs the argument names in another spelling, or
340
+ * failing that the topics and top-level namespaces, closest first and cut
341
+ * where the matches get weaker (every one of them when none shares a word
342
+ * with the argument).
340
343
  * @param {unknown} topic
341
344
  * @param {DocsCatalog} catalog
342
345
  * @returns {Promise<AstryxError>}
@@ -77,6 +77,7 @@ import {
77
77
  discoverIntegrationTemplatesForOne,
78
78
  } from '../../foundation/discovery/template-adapter.mjs';
79
79
  import {findCoreDir} from '../../foundation/fs/paths.mjs';
80
+ import {reusedWhileUnchanged} from '../../foundation/fs/read-record.mjs';
80
81
  import {AstryxError} from '../error.mjs';
81
82
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
82
83
  import {orderRouteSuggestions} from '../../foundation/text/suggest-order.mjs';
@@ -393,8 +394,8 @@ export function projectTree(catalog, {fresh = false} = {}) {
393
394
  return tree;
394
395
  }
395
396
 
396
- /** @type {ReturnType<typeof loadTreeInputs> | undefined} */
397
- let cliTreeInputs;
397
+ /** The CLI's own tree files, loaded again after one of them changes. */
398
+ const cliTreeInputs = reusedWhileUnchanged(() => loadTreeInputs());
398
399
 
399
400
  /**
400
401
  * Every flat topic in the catalog, as the tree's topic levels read it.
@@ -441,8 +442,7 @@ async function flatTopicInputs(catalog) {
441
442
  */
442
443
  async function buildProjectTree(catalog, fresh) {
443
444
  const added = catalog.treeInputs;
444
- if (fresh || !cliTreeInputs) cliTreeInputs = loadTreeInputs();
445
- const cli = await cliTreeInputs;
445
+ const cli = await cliTreeInputs({fresh});
446
446
  const result = buildDocsTree({
447
447
  namespaces: [...cli.namespaces, ...added.flatMap(each => each.namespaces)],
448
448
  docs: [...cli.docs, ...added.flatMap(each => each.guides)],
@@ -573,11 +573,15 @@ function identitiesOf(tree) {
573
573
  /**
574
574
  * The CLI's authoring docs, by kind and name. The field reference under
575
575
  * `astryx docs authoring` reads each as one section keyed by its name, so a
576
- * link to one opens that section. Loaded once per process, like the CLI's
577
- * tree files.
578
- * @type {Promise<Map<string, any>> | undefined}
576
+ * link to one opens that section. Loaded again after one of them changes,
577
+ * like the CLI's tree files.
579
578
  */
580
- let authoringDocs;
579
+ const authoringDocs = reusedWhileUnchanged(() =>
580
+ loadAuthoringSelfDocs().then(
581
+ ({loaded}) =>
582
+ new Map(loaded.map(({doc}) => [`${doc.type}\u0000${doc.name}`, doc])),
583
+ ),
584
+ );
581
585
 
582
586
  /**
583
587
  * The CLI authoring doc a link names. The `authoring` namespace is the CLI's
@@ -587,11 +591,7 @@ let authoringDocs;
587
591
  * @returns {Promise<any | null>}
588
592
  */
589
593
  async function authoringDoc(kind, name) {
590
- authoringDocs ??= loadAuthoringSelfDocs().then(
591
- ({loaded}) =>
592
- new Map(loaded.map(({doc}) => [`${doc.type}\u0000${doc.name}`, doc])),
593
- );
594
- return (await authoringDocs).get(`${kind}\u0000${name}`) ?? null;
594
+ return (await authoringDocs()).get(`${kind}\u0000${name}`) ?? null;
595
595
  }
596
596
 
597
597
  /**
@@ -1844,8 +1844,11 @@ function movedRoute(topic, tree) {
1844
1844
 
1845
1845
  /**
1846
1846
  * The error for a docs argument that names nothing. For a route, it suggests
1847
- * the children of the deepest namespace the route reaches; otherwise, every
1848
- * topic and every top-level namespace.
1847
+ * every child of the deepest namespace the route reaches, closest first.
1848
+ * Otherwise it suggests the docs the argument names in another spelling, or
1849
+ * failing that the topics and top-level namespaces, closest first and cut
1850
+ * where the matches get weaker (every one of them when none shares a word
1851
+ * with the argument).
1849
1852
  * @param {unknown} topic
1850
1853
  * @param {DocsCatalog} catalog
1851
1854
  * @returns {Promise<AstryxError>}
@@ -1854,6 +1857,8 @@ export async function unknownTopicError(topic, catalog) {
1854
1857
  const tree = await projectTree(catalog);
1855
1858
  /** @type {Array<{name: string, reason: string}>} */
1856
1859
  let suggestions = [];
1860
+ // Route children stay whole (spec:AST-046); only the other lists are cut.
1861
+ let routeChildren = false;
1857
1862
  if (typeof topic === 'string' && topic.includes('/')) {
1858
1863
  const parts = topic.split('/');
1859
1864
  for (
@@ -1863,6 +1868,7 @@ export async function unknownTopicError(topic, catalog) {
1863
1868
  ) {
1864
1869
  const near = tree.get(parts.slice(0, depth).join('/'));
1865
1870
  if (near) {
1871
+ routeChildren = true;
1866
1872
  suggestions = near.slots.flatMap(slot =>
1867
1873
  slot.children.map(route => ({
1868
1874
  name: route,
@@ -1894,7 +1900,9 @@ export async function unknownTopicError(topic, catalog) {
1894
1900
  ];
1895
1901
  }
1896
1902
  if (typeof topic === 'string') {
1897
- suggestions = orderRouteSuggestions(topic, suggestions);
1903
+ suggestions = orderRouteSuggestions(topic, suggestions, {
1904
+ closest: !routeChildren,
1905
+ });
1898
1906
  }
1899
1907
  // A route that moved names where it went, ahead of the usual suggestions
1900
1908
  // (spec:AST-046 FR9, FR6).
@@ -254,6 +254,24 @@ describe('docs() dispatcher routing', () => {
254
254
  );
255
255
  }, SLOW);
256
256
 
257
+ it('an unknown route keeps every child of its namespace, closest first', async () => {
258
+ const error = await docs('tokens/usage').catch(e => e);
259
+ expect(error.code).toBe('ERR_UNKNOWN_TOPIC');
260
+ const names = error.suggestions.map(s => s.name);
261
+ expect(names[0]).toBe('tokens/tokens-usage');
262
+ const none = await docs('tokens/zzzz-nope').catch(e => e);
263
+ expect([...names].sort()).toEqual(none.suggestions.map(s => s.name).sort());
264
+ }, SLOW);
265
+
266
+ it('an unknown flat topic is cut where the matches get weaker', async () => {
267
+ const error = await docs('authoring-at-meta').catch(e => e);
268
+ expect(error.suggestions.map(s => s.name)).toEqual(['authoring']);
269
+ // One-letter words do not narrow it: `a11y` keeps the whole browse list.
270
+ const browse = await docs('zzzz-nope').catch(e => e);
271
+ const a11y = await docs('a11y').catch(e => e);
272
+ expect(a11y.suggestions.length).toBe(browse.suggestions.length);
273
+ }, SLOW);
274
+
257
275
  it('a section no guide of a namespace has -> ERR_UNKNOWN_SECTION, naming its guides', async () => {
258
276
  const err = await docs('cli', 'zzzz-nope').catch(e => e);
259
277
  expect(err).toBeInstanceOf(AstryxError);
@@ -450,11 +450,11 @@ describe('integration-contributed topics', () => {
450
450
 
451
451
  it('offers the contributed topics as suggestions on an unknown one', async () => {
452
452
  scaffold({'deploying.doc.mjs': topic()});
453
- await expect(docs('nope-not-a-topic', undefined, {cwd: tmpDir, full: true})).rejects.toBeInstanceOf(
453
+ await expect(docs('zzqx-qqzz', undefined, {cwd: tmpDir, full: true})).rejects.toBeInstanceOf(
454
454
  AstryxError,
455
455
  );
456
456
  try {
457
- await docs('nope-not-a-topic', undefined, {cwd: tmpDir, full: true});
457
+ await docs('zzqx-qqzz', undefined, {cwd: tmpDir, full: true});
458
458
  } catch (err) {
459
459
  expect(err.suggestions.map(s => s.name)).toContain('deploying');
460
460
  }
@@ -0,0 +1,5 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ export { render } from "./render/render.mjs";
5
+ export * from "./render/render.type.mjs";
@@ -0,0 +1,15 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `@astryxdesign/cli/api/experimental`: the CLI's experimental
5
+ * functions (spec:AST-017 FR21, FR27). Nothing here is part of the stable
6
+ * `@astryxdesign/cli/api`; each function and type may change or be removed in
7
+ * a patch release.
8
+ *
9
+ * @position api — the experimental entry beside api/index.mjs
10
+ */
11
+
12
+ export {render} from './render/render.mjs';
13
+
14
+ // Types (runtime no-ops; tsc carries them into api/experimental.d.mts).
15
+ export * from './render/render.type.mjs';
@@ -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?: "compact" | "full" | "names" | "brief" | undefined;
16
+ detail?: "names" | "compact" | "full" | "brief" | undefined;
17
17
  zh?: boolean | undefined;
18
18
  lang?: string | null | undefined;
19
19
  }): Promise<import("../hook.type.mjs").HookListResponse>;
@@ -11,7 +11,8 @@
11
11
  */
12
12
  export function refuseOutsideProject(cwd: string, command: string, where: string): void;
13
13
  /**
14
- * Run one authoring step, turning its errors into AstryxErrors.
14
+ * Run one authoring command so its writes are all or nothing, turning its
15
+ * errors into AstryxErrors.
15
16
  * @template T
16
17
  * @param {() => T | Promise<T>} step
17
18
  * @returns {Promise<T>}
@@ -50,5 +51,5 @@ export { iconSetKey } from "../../foundation/discovery/icon-set-discovery.mjs";
50
51
  export { setConfigString } from "../../foundation/config/config-writer.mjs";
51
52
  export { exportValueKind } from "../../foundation/discovery/module-exports.mjs";
52
53
  export { iconRecord, importLine, leadingReading, matchIcon, rankIcons, scoreIcon } from "../../foundation/discovery/icon-ranking.mjs";
53
- export { assertIconExport, checkNewDefinition, definitionFile, findLocalIconSet, writeDefinitionFile, iconIdOf, closestNames, libraryIcons, mappableDefinitions, resolveIconSource, generatedModulePath, generatedNamesOf, iconExportName, iconNaming, modulePrefix, setModuleNote, variantExportName, writeGeneratedIcons, writeIconSetData, THEME_MAP_NAME } from "../../foundation/discovery/icon-set-writer.mjs";
54
+ export { assertIconExport, checkNewDefinition, definitionFile, findLocalIconSet, writeDefinitionFile, iconIdOf, closestNames, libraryIcons, mappableDefinitions, resolveIconSource, generatedModulePath, generatedNamesOf, generatedOrigins, iconModulePackage, sameIconModule, iconExportName, iconNaming, modulePrefix, setModuleNote, variantExportName, writeGeneratedIcons, writeIconSetData, definitionNameOf, iconIdIn, iconsWithWord, localSourceNote, THEME_MAP_NAME } from "../../foundation/discovery/icon-set-writer.mjs";
54
55
  export { addIconDefinition, addIconSet } from "./_authoring.mjs";
@@ -15,7 +15,10 @@ import * as path from 'node:path';
15
15
  import {Project} from '../../foundation/config/project.mjs';
16
16
  import {AstryxError} from '../error.mjs';
17
17
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
18
- import {IconSetAuthoringError} from '../../foundation/discovery/icon-set-writer.mjs';
18
+ import {
19
+ IconSetAuthoringError,
20
+ allOrNothing,
21
+ } from '../../foundation/discovery/icon-set-writer.mjs';
19
22
  import {PathSafetyError} from '../../foundation/fs/path-safety.mjs';
20
23
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
21
24
  import {projectIconSetCliWarning} from '../../foundation/integrations/cli-requirement.mjs';
@@ -44,6 +47,9 @@ export {
44
47
  resolveIconSource,
45
48
  generatedModulePath,
46
49
  generatedNamesOf,
50
+ generatedOrigins,
51
+ iconModulePackage,
52
+ sameIconModule,
47
53
  iconExportName,
48
54
  iconNaming,
49
55
  modulePrefix,
@@ -51,6 +57,10 @@ export {
51
57
  variantExportName,
52
58
  writeGeneratedIcons,
53
59
  writeIconSetData,
60
+ definitionNameOf,
61
+ iconIdIn,
62
+ iconsWithWord,
63
+ localSourceNote,
54
64
  THEME_MAP_NAME,
55
65
  } from '../../foundation/discovery/icon-set-writer.mjs';
56
66
  export {exportValueKind} from '../../foundation/discovery/module-exports.mjs';
@@ -87,14 +97,17 @@ function hasPackageJsonAbove(dir) {
87
97
  }
88
98
 
89
99
  /**
90
- * Run one authoring step, turning its errors into AstryxErrors.
100
+ * Run one authoring command so its writes are all or nothing, turning its
101
+ * errors into AstryxErrors.
91
102
  * @template T
92
103
  * @param {() => T | Promise<T>} step
93
104
  * @returns {Promise<T>}
94
105
  */
95
106
  export async function authoring(step) {
96
107
  try {
97
- return await step();
108
+ // All or nothing: a failure after some writes puts every file back
109
+ // (AST-084 FR13).
110
+ return await allOrNothing(step);
98
111
  } catch (error) {
99
112
  if (error instanceof IconSetAuthoringError) {
100
113
  throw new AstryxError(
@@ -8,7 +8,7 @@
8
8
  * discoverable; `integration check` then names every built-in icon
9
9
  * definition it still has to map.
10
10
  * @param {string} name icon set name (kebab-case)
11
- * @param {{cwd?: string, dryRun?: boolean, from?: string, exclude?: string[] | string}} options
11
+ * @param {{cwd?: string, dryRun?: boolean, from?: string, exclude?: string[] | string, variants?: string[] | string, defaultVariant?: string, displayName?: string, description?: string}} options
12
12
  * @returns {Promise<{type: 'integration.add', data: import('./icon.type.mjs').IconNewData}>}
13
13
  */
14
14
  export function addIconSet(name: string, options: {
@@ -16,6 +16,10 @@ export function addIconSet(name: string, options: {
16
16
  dryRun?: boolean;
17
17
  from?: string;
18
18
  exclude?: string[] | string;
19
+ variants?: string[] | string;
20
+ defaultVariant?: string;
21
+ displayName?: string;
22
+ description?: string;
19
23
  }): Promise<{
20
24
  type: "integration.add";
21
25
  data: import("./icon.type.mjs").IconNewData;