@astryxdesign/cli 0.7.14-canary.g7deca33 → 0.7.14-canary.g92e660a

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 (140) hide show
  1. package/api/component/_adapter.d.mts +15 -0
  2. package/api/component/_adapter.mjs +76 -0
  3. package/api/component/component.mjs +8 -1
  4. package/api/doctor/_adapter.d.mts +1 -0
  5. package/api/doctor/_adapter.mjs +8 -0
  6. package/api/doctor/_authoring-audit.d.mts +42 -0
  7. package/api/doctor/_authoring-audit.mjs +106 -0
  8. package/api/doctor/doctor.mjs +4 -39
  9. package/api/search/_candidate-score.mjs +63 -9
  10. package/api/search/_named-keywords.d.mts +31 -0
  11. package/api/search/_named-keywords.mjs +177 -0
  12. package/api/search/_words.mjs +26 -6
  13. package/api/search/search-index.mjs +8 -1
  14. package/api/search/search.d.mts +6 -1
  15. package/api/search/search.mjs +49 -8
  16. package/api/theme/_adapter.d.mts +33 -0
  17. package/api/theme/_adapter.mjs +352 -16
  18. package/api/theme/build/build.mjs +261 -10
  19. package/api/theme/eject/eject.mjs +13 -1
  20. package/api/theme/list/list.mjs +11 -2
  21. package/api/theme/palette/generate/color.d.mts +2 -0
  22. package/api/theme/palette/generate/color.mjs +1 -1
  23. package/api/theme/template/template.mjs +139 -6
  24. package/api/theme/theme.type.d.mts +15 -1
  25. package/api/theme/theme.type.mjs +9 -3
  26. package/api/theme/themeAdd.doc.mjs +1 -1
  27. package/api/theme/themeBuild.doc.mjs +10 -2
  28. package/api/theme/themeEject.doc.mjs +2 -2
  29. package/api/theme/themeListAvailable.doc.mjs +1 -1
  30. package/api/theme/themeRemove.doc.mjs +1 -1
  31. package/api/theme/themeTemplate.doc.mjs +8 -0
  32. package/api/theme/themeUse.doc.mjs +1 -1
  33. package/api/theme-edit/_adapter.d.mts +36 -2
  34. package/api/theme-edit/_adapter.mjs +371 -12
  35. package/api/theme-edit/_check.d.mts +28 -25
  36. package/api/theme-edit/_check.mjs +847 -539
  37. package/api/theme-edit/_color.d.mts +53 -4
  38. package/api/theme-edit/_color.mjs +406 -79
  39. package/api/theme-edit/_compiler.d.mts +14 -5
  40. package/api/theme-edit/_compiler.mjs +105 -58
  41. package/api/theme-edit/_context.d.mts +15 -5
  42. package/api/theme-edit/_context.mjs +50 -7
  43. package/api/theme-edit/_edit.mjs +572 -75
  44. package/api/theme-edit/_how-commands.d.mts +99 -0
  45. package/api/theme-edit/_how-commands.mjs +320 -0
  46. package/api/theme-edit/_how-question.d.mts +61 -0
  47. package/api/theme-edit/_how-question.mjs +3096 -0
  48. package/api/theme-edit/_how.d.mts +25 -17
  49. package/api/theme-edit/_how.mjs +743 -305
  50. package/api/theme-edit/_palette.d.mts +153 -19
  51. package/api/theme-edit/_palette.mjs +1548 -384
  52. package/api/theme-edit/_parts.mjs +61 -5
  53. package/api/theme-edit/_png.d.mts +17 -5
  54. package/api/theme-edit/_png.mjs +136 -24
  55. package/api/theme-edit/_preview-app.d.mts +26 -7
  56. package/api/theme-edit/_preview-app.mjs +2222 -345
  57. package/api/theme-edit/_preview.d.mts +7 -3
  58. package/api/theme-edit/_preview.mjs +41 -20
  59. package/api/theme-edit/_settings.d.mts +136 -8
  60. package/api/theme-edit/_settings.mjs +832 -98
  61. package/api/theme-edit/_tables.d.mts +7 -12
  62. package/api/theme-edit/_tables.mjs +86 -98
  63. package/api/theme-edit/theme-edit.type.d.mts +41 -20
  64. package/api/theme-edit/theme-edit.type.mjs +29 -18
  65. package/api/theme-edit/themeEditHow.doc.mjs +13 -3
  66. package/api/theme-edit/themeEditNew.doc.mjs +8 -2
  67. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +18 -5
  68. package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -9
  69. package/api/theme-edit/themeEditPreviewList.doc.mjs +11 -2
  70. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +33 -3
  71. package/api/theme-edit/themeEditSet.doc.mjs +9 -3
  72. package/api/theme-edit/themeEditShow.doc.mjs +7 -2
  73. package/api/theme-edit/themeEditUndo.doc.mjs +8 -3
  74. package/api/upgrade/_adapter.d.mts +1 -0
  75. package/assets/codemods/run-codemod.mjs +53 -0
  76. package/assets/codemods/runner.mjs +5 -4
  77. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  78. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  79. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  80. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  81. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  82. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  83. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  84. package/assets/docs.generated.json +2 -0
  85. package/assets/preview-app/gitignore +3 -0
  86. package/assets/self-audit.generated.json +1 -0
  87. package/assets/templates/components.generated.json +1 -0
  88. package/clients/cli/bin/astryx.mjs +37 -5
  89. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  90. package/clients/cli/commands/experimental/theme.mjs +293 -36
  91. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +15 -6
  92. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -1
  93. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
  94. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  95. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +3 -3
  96. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
  97. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -8
  98. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
  99. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  100. package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
  101. package/clients/cli/commands/experimental-theme.doc.mjs +2 -2
  102. package/clients/cli/commands/manifest.mjs +5 -2
  103. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  104. package/clients/cli/commands/theme-eject.doc.mjs +3 -3
  105. package/clients/cli/commands/theme-remove.doc.mjs +2 -2
  106. package/clients/cli/commands/theme-template.doc.mjs +11 -4
  107. package/clients/cli/commands/theme.mjs +104 -40
  108. package/clients/cli/commands.generated.json +1 -0
  109. package/clients/cli/index.mjs +100 -6
  110. package/clients/cli/lib/json-shim.mjs +29 -1
  111. package/clients/cli/lib/manifest.mjs +33 -0
  112. package/clients/cli/lib/resolve-theme.mjs +2 -1
  113. package/clients/cli/manifest.generated.json +1 -0
  114. package/foundation/config/project.d.mts +16 -2
  115. package/foundation/config/project.mjs +40 -6
  116. package/foundation/config/theme-state.d.mts +9 -0
  117. package/foundation/config/theme-state.mjs +20 -1
  118. package/foundation/discovery/module-exports.mjs +16 -2
  119. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  120. package/foundation/discovery/stored-self-audit.mjs +119 -0
  121. package/foundation/discovery/template-adapter.d.mts +12 -1
  122. package/foundation/discovery/template-adapter.mjs +24 -1
  123. package/foundation/discovery/template-needs.d.mts +7 -0
  124. package/foundation/discovery/template-needs.mjs +117 -8
  125. package/foundation/discovery/template-source-tree.d.mts +5 -1
  126. package/foundation/discovery/template-source-tree.mjs +6 -4
  127. package/foundation/discovery/theme-discovery.d.mts +14 -3
  128. package/foundation/discovery/theme-discovery.mjs +45 -12
  129. package/foundation/doc-compiler/import.mjs +70 -4
  130. package/foundation/doc-compiler/stored-docs.d.mts +33 -0
  131. package/foundation/doc-compiler/stored-docs.mjs +98 -0
  132. package/foundation/fs/fs-error.d.mts +17 -0
  133. package/foundation/fs/fs-error.mjs +34 -0
  134. package/foundation/fs/module-loader.mjs +7 -1
  135. package/foundation/integrations/validate-contributions.mjs +24 -11
  136. package/foundation/response/error-codes.d.mts +2 -1
  137. package/foundation/response/error-codes.doc.mjs +7 -1
  138. package/foundation/response/error-codes.mjs +6 -1
  139. package/foundation/response/response-types.doc.mjs +1 -1
  140. package/package.json +6 -6
@@ -276,6 +276,21 @@ export function linkComponentResponse<R extends {
276
276
  package?: string;
277
277
  data?: any;
278
278
  }>(response: R, cwd: string): Promise<R>;
279
+ /**
280
+ * When `error` is the unknown-component error for a name that is an example
281
+ * block, returns the same error with the commands that show the block in its
282
+ * message: `astryx template <Block>`, and `astryx component <Parent> --blocks`
283
+ * for a component whose `--blocks` listing holds the block. The code and the
284
+ * matcher's suggestions stay. Returns `error` unchanged otherwise.
285
+ * @param {unknown} error
286
+ * @param {string} dirName
287
+ * @param {{coreDir: string, cwd: string}} context
288
+ * @returns {Promise<unknown>}
289
+ */
290
+ export function withExampleBlockPointer(error: unknown, dirName: string, { coreDir, cwd }: {
291
+ coreDir: string;
292
+ cwd: string;
293
+ }): Promise<unknown>;
279
294
  /**
280
295
  * Internal ambiguity marker. Single-component callers still receive the same
281
296
  * AstryxError code, message, and suggestions; batch callers can additionally
@@ -49,6 +49,10 @@ import {
49
49
  synonymMatches,
50
50
  } from '../../foundation/text/suggest-order.mjs';
51
51
  import {AstryxError, coreDirOrThrow} from '../error.mjs';
52
+ import {
53
+ discoverAll,
54
+ findRelatedBlocks,
55
+ } from '../../foundation/discovery/template-adapter.mjs';
52
56
  import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
53
57
  import {
54
58
  componentLinkProvider,
@@ -827,3 +831,75 @@ export async function linkComponentResponse(response, cwd) {
827
831
  }
828
832
  return {...response, data: {...response.data, components}};
829
833
  }
834
+
835
+ /**
836
+ * When `error` is the unknown-component error for a name that is an example
837
+ * block, returns the same error with the commands that show the block in its
838
+ * message: `astryx template <Block>`, and `astryx component <Parent> --blocks`
839
+ * for a component whose `--blocks` listing holds the block. The code and the
840
+ * matcher's suggestions stay. Returns `error` unchanged otherwise.
841
+ * @param {unknown} error
842
+ * @param {string} dirName
843
+ * @param {{coreDir: string, cwd: string}} context
844
+ * @returns {Promise<unknown>}
845
+ */
846
+ export async function withExampleBlockPointer(error, dirName, {coreDir, cwd}) {
847
+ if (
848
+ !(error instanceof AstryxError) ||
849
+ error.code !== ERROR_CODES.ERR_UNKNOWN_COMPONENT
850
+ ) {
851
+ return error;
852
+ }
853
+ // A block doc that fails to load must not replace the unknown-component
854
+ // error and its suggestions: the pointer is extra help, so a failed lookup
855
+ // keeps the original error.
856
+ try {
857
+ const typed = dirName.toLowerCase();
858
+ const block = (await discoverAll(cwd)).find(
859
+ template =>
860
+ template.type === 'block' && template.dirName.toLowerCase() === typed,
861
+ );
862
+ if (block == null) {
863
+ return error;
864
+ }
865
+ const parent = await listingParent(block, coreDir, cwd);
866
+ const listing = parent
867
+ ? `, and astryx component ${parent} --blocks lists it`
868
+ : '';
869
+ return new AstryxError(
870
+ `${error.message}. It is an example block: astryx template ${block.dirName} prints its source${listing}.`,
871
+ error.suggestions,
872
+ ERROR_CODES.ERR_UNKNOWN_COMPONENT,
873
+ );
874
+ } catch {
875
+ return error;
876
+ }
877
+ }
878
+
879
+ /**
880
+ * A component whose `component <Name> --blocks` listing holds `block`: one of
881
+ * the components the block uses, its own folder's component first, that
882
+ * resolves as a component and whose related blocks include the block.
883
+ * @param {{dirName: string, category?: string, componentsUsed?: string[]}} block
884
+ * @param {string} coreDir
885
+ * @param {string} cwd
886
+ * @returns {Promise<string | null>}
887
+ */
888
+ async function listingParent(block, coreDir, cwd) {
889
+ const used = block.componentsUsed ?? [];
890
+ const folder = path.basename(block.category ?? '');
891
+ const candidates = [
892
+ ...used.filter(name => name === folder),
893
+ ...used.filter(name => name !== folder),
894
+ ];
895
+ for (const name of candidates) {
896
+ if (findComponentReadme(coreDir, name) == null) {
897
+ continue;
898
+ }
899
+ const related = await findRelatedBlocks(name, cwd);
900
+ if (related.some(entry => entry.dirName === block.dirName)) {
901
+ return name;
902
+ }
903
+ }
904
+ return null;
905
+ }
@@ -31,6 +31,7 @@ import {
31
31
  legacyExternalKeeps,
32
32
  resolveCoreSourcePath,
33
33
  resolveUnscopedDoc,
34
+ withExampleBlockPointer,
34
35
  loadComponentDoc,
35
36
  scopeSubComponent,
36
37
  ComponentAmbiguityError,
@@ -623,7 +624,13 @@ async function componentRead(name, options = {}) {
623
624
  });
624
625
  }
625
626
 
626
- const resolved = await resolveUnscopedDoc(dirName, {coreDir, cwd, name});
627
+ const resolved = await resolveUnscopedDoc(dirName, {
628
+ coreDir,
629
+ cwd,
630
+ name,
631
+ }).catch(async error => {
632
+ throw await withExampleBlockPointer(error, dirName, {coreDir, cwd});
633
+ });
627
634
  const docs = await loadComponentDoc(resolved.readmePath, docOpts);
628
635
 
629
636
  // ── Blocks mode ──────────────────────────────────────────────
@@ -264,3 +264,4 @@ import { stateLockHolder } from '../../foundation/release/global-state.mjs';
264
264
  import { displayHomePath } from '../../foundation/agent-docs/computer-agent-text.mjs';
265
265
  export { isLocalThemeOwner, planThemeAppWrite, readThemeState, resolveThemeModule } from "../../foundation/config/theme-state.mjs";
266
266
  export { themeBuild, validateThemePrivateInputs } from "../theme/build/build.mjs";
267
+ export { AUTHORING_AUDIT, authoringAudit, authoringAuditData } from "./_authoring-audit.mjs";
@@ -70,6 +70,14 @@ export {themeBuild, validateThemePrivateInputs} from '../theme/build/build.mjs';
70
70
  export {resolveRecordedTheme} from '../theme/theme.mjs';
71
71
  export {collectUnloadedFonts} from '../theme/build/font-warning.mjs';
72
72
 
73
+ // What the authoring-docs check reads (./_authoring-audit.mjs), reached only
74
+ // through this adapter.
75
+ export {
76
+ AUTHORING_AUDIT,
77
+ authoringAudit,
78
+ authoringAuditData,
79
+ } from './_authoring-audit.mjs';
80
+
73
81
  /**
74
82
  * Package written to the generated app record for one discovered theme.
75
83
  * @param {import('../../foundation/discovery/theme-discovery.mjs').DiscoveredTheme} theme
@@ -0,0 +1,42 @@
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
+ /**
5
+ * What the authoring-docs check reads: the self-docs audit, the field
6
+ * reference's section keys, and the authoring-surface audit. They read only
7
+ * the CLI's own files, so `prepack` stores them for the published package
8
+ * (scripts/generate-self-audit.mjs).
9
+ * @param {{root?: string, sources?: string[], topicKeys?: Set<string> | null}} [options]
10
+ * @returns {Promise<AuthoringAuditData>}
11
+ */
12
+ export function authoringAuditData(options?: {
13
+ root?: string;
14
+ sources?: string[];
15
+ topicKeys?: Set<string> | null;
16
+ }): Promise<AuthoringAuditData>;
17
+ /**
18
+ * The authoring-docs check's data: as stored at publish while what it read is
19
+ * unchanged, else read now. Another tree, list or topic index (tests) is
20
+ * always read now.
21
+ * @param {{root?: string, sources?: string[], topicKeys?: Set<string> | null}} [options]
22
+ * @returns {Promise<AuthoringAuditData>}
23
+ */
24
+ export function authoringAudit(options?: {
25
+ root?: string;
26
+ sources?: string[];
27
+ topicKeys?: Set<string> | null;
28
+ }): Promise<AuthoringAuditData>;
29
+ /** The name the authoring-docs check's data is stored under. */
30
+ export const AUTHORING_AUDIT: "authoring-docs";
31
+ export type AuthoringAuditData = {
32
+ audit: Awaited<ReturnType<typeof import("../../foundation/discovery/authoring-self-docs.mjs").auditAuthoringSelfDocs>>;
33
+ /**
34
+ * - The field
35
+ * reference's section keys, or why they could not be read.
36
+ */
37
+ topic: {
38
+ keys: Set<string> | null;
39
+ error?: string;
40
+ };
41
+ surface: Awaited<ReturnType<typeof import("../../foundation/discovery/authoring-surface.mjs").auditAuthoringSurface>>;
42
+ };
@@ -0,0 +1,106 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file What Doctor's authoring-docs check reads, kept apart from the public
5
+ * doctor API: api/doctor/doctor.mjs reports it, and
6
+ * scripts/generate-self-audit.mjs stores it at publish.
7
+ */
8
+
9
+ import {DocsCatalog} from '../../foundation/discovery/docs-discovery.mjs';
10
+ import {storedSelfAudit} from '../../foundation/discovery/stored-self-audit.mjs';
11
+ import {indexView} from '../../foundation/doc-compiler/lenses.mjs';
12
+ import {guideEntry, lowerTopic, projectTree} from '../docs/_adapter.mjs';
13
+
14
+ /**
15
+ * @typedef {object} AuthoringAuditData
16
+ * @property {Awaited<ReturnType<typeof import('../../foundation/discovery/authoring-self-docs.mjs').auditAuthoringSelfDocs>>} audit
17
+ * @property {{keys: Set<string> | null, error?: string}} topic - The field
18
+ * reference's section keys, or why they could not be read.
19
+ * @property {Awaited<ReturnType<typeof import('../../foundation/discovery/authoring-surface.mjs').auditAuthoringSurface>>} surface
20
+ */
21
+
22
+ /**
23
+ * The section keys the field reference lists (`astryx docs
24
+ * authoring/field-reference --index`), read the way that command reads them.
25
+ * @returns {Promise<{keys: Set<string>} | {keys: null, error: string}>}
26
+ */
27
+ async function authoringTopicKeys() {
28
+ try {
29
+ const {AUTHORING_REFERENCE_ROUTE} =
30
+ await import('../../foundation/discovery/authoring-self-docs.mjs');
31
+ const catalog = DocsCatalog.fromBuiltins();
32
+ const node = (await projectTree(catalog)).get(AUTHORING_REFERENCE_ROUTE);
33
+ if (!node?.ref?.topicFile) {
34
+ return {keys: null, error: 'the docs tree has no field reference'};
35
+ }
36
+ const index = indexView(await lowerTopic(catalog, guideEntry(node)));
37
+ return {keys: new Set(index.sections.map(section => section.id))};
38
+ } catch (err) {
39
+ return {
40
+ keys: null,
41
+ error: err instanceof Error ? err.message : String(err),
42
+ };
43
+ }
44
+ }
45
+
46
+ /**
47
+ * What the authoring-docs check reads: the self-docs audit, the field
48
+ * reference's section keys, and the authoring-surface audit. They read only
49
+ * the CLI's own files, so `prepack` stores them for the published package
50
+ * (scripts/generate-self-audit.mjs).
51
+ * @param {{root?: string, sources?: string[], topicKeys?: Set<string> | null}} [options]
52
+ * @returns {Promise<AuthoringAuditData>}
53
+ */
54
+ export async function authoringAuditData(options = {}) {
55
+ const {auditAuthoringSelfDocs} =
56
+ await import('../../foundation/discovery/authoring-self-docs.mjs');
57
+ const {auditAuthoringSurface} =
58
+ await import('../../foundation/discovery/authoring-surface.mjs');
59
+ const {root, sources} = options;
60
+ const audit = await auditAuthoringSelfDocs({root, sources});
61
+ const topic =
62
+ options.topicKeys === undefined
63
+ ? await authoringTopicKeys()
64
+ : {keys: options.topicKeys};
65
+ const surface = await auditAuthoringSurface({
66
+ root,
67
+ sources,
68
+ topicKeys: topic.keys,
69
+ });
70
+ return {audit, topic, surface};
71
+ }
72
+
73
+ /** The name the authoring-docs check's data is stored under. */
74
+ export const AUTHORING_AUDIT = 'authoring-docs';
75
+
76
+ /**
77
+ * The authoring-docs check's data as stored at publish, while the files it
78
+ * read are unchanged, else undefined.
79
+ * @returns {AuthoringAuditData | undefined}
80
+ */
81
+ function storedAuthoringAudit() {
82
+ const value = /** @type {any} */ (storedSelfAudit(AUTHORING_AUDIT));
83
+ if (!value) return undefined;
84
+ const {keys, ...rest} = value.topic;
85
+ return {
86
+ ...value,
87
+ topic: keys === null ? {keys: null, ...rest} : {keys: new Set(keys)},
88
+ };
89
+ }
90
+
91
+ /**
92
+ * The authoring-docs check's data: as stored at publish while what it read is
93
+ * unchanged, else read now. Another tree, list or topic index (tests) is
94
+ * always read now.
95
+ * @param {{root?: string, sources?: string[], topicKeys?: Set<string> | null}} [options]
96
+ * @returns {Promise<AuthoringAuditData>}
97
+ */
98
+ export async function authoringAudit(options = {}) {
99
+ const fresh =
100
+ options.root !== undefined ||
101
+ options.sources !== undefined ||
102
+ options.topicKeys !== undefined;
103
+ return (
104
+ (fresh ? undefined : storedAuthoringAudit()) ?? authoringAuditData(options)
105
+ );
106
+ }
@@ -73,12 +73,11 @@ import {
73
73
  compileTopic,
74
74
  docsLinkProblems,
75
75
  guideEntry,
76
- lowerTopic,
77
76
  overlayLanguages,
78
77
  projectTree,
79
78
  } from '../docs/_adapter.mjs';
80
79
  import {typedEdges} from '../docs/node/node.mjs';
81
- import {detailView, indexView} from '../../foundation/doc-compiler/lenses.mjs';
80
+ import {detailView} from '../../foundation/doc-compiler/lenses.mjs';
82
81
  import {isExperimentalTreeNode} from '../../foundation/doc-compiler/tree.mjs';
83
82
  import {
84
83
  semverCompare,
@@ -116,6 +115,7 @@ import {
116
115
  outsideProject,
117
116
  releaseFacts,
118
117
  builtIntegrationPackages,
118
+ authoringAudit,
119
119
  } from './_adapter.mjs';
120
120
  import {checkBuilt} from './built-checks.mjs';
121
121
 
@@ -1307,30 +1307,6 @@ function nameTypes(names) {
1307
1307
  : `${names.slice(0, NAMED_TYPES).join(', ')} and ${names.length - NAMED_TYPES} more`;
1308
1308
  }
1309
1309
 
1310
- /**
1311
- * The section keys the field reference lists (`astryx docs
1312
- * authoring/field-reference --index`), read the way that command reads them.
1313
- * @returns {Promise<{keys: Set<string>} | {keys: null, error: string}>}
1314
- */
1315
- async function authoringTopicKeys() {
1316
- try {
1317
- const {AUTHORING_REFERENCE_ROUTE} =
1318
- await import('../../foundation/discovery/authoring-self-docs.mjs');
1319
- const catalog = DocsCatalog.fromBuiltins();
1320
- const node = (await projectTree(catalog)).get(AUTHORING_REFERENCE_ROUTE);
1321
- if (!node?.ref?.topicFile) {
1322
- return {keys: null, error: 'the docs tree has no field reference'};
1323
- }
1324
- const index = indexView(await lowerTopic(catalog, guideEntry(node)));
1325
- return {keys: new Set(index.sections.map(section => section.id))};
1326
- } catch (err) {
1327
- return {
1328
- keys: null,
1329
- error: err instanceof Error ? err.message : String(err),
1330
- };
1331
- }
1332
- }
1333
-
1334
1310
  /**
1335
1311
  * @param {Awaited<ReturnType<typeof import('../../foundation/discovery/authoring-surface.mjs').auditAuthoringSurface>>} surface
1336
1312
  * @returns {string[]}
@@ -1386,12 +1362,7 @@ export async function checkAuthoringDocs(_ctx, options = {}) {
1386
1362
  const id = 'authoring-docs';
1387
1363
  const label = 'Authoring docs';
1388
1364
  try {
1389
- const {auditAuthoringSelfDocs} =
1390
- await import('../../foundation/discovery/authoring-self-docs.mjs');
1391
- const {auditAuthoringSurface} =
1392
- await import('../../foundation/discovery/authoring-surface.mjs');
1393
- const {root, sources} = options;
1394
- const audit = await auditAuthoringSelfDocs({root, sources});
1365
+ const {audit, topic, surface: surfaceAudit} = await authoringAudit(options);
1395
1366
  const problems = [
1396
1367
  ...audit.unreachable.map(
1397
1368
  source =>
@@ -1405,19 +1376,13 @@ export async function checkAuthoringDocs(_ctx, options = {}) {
1405
1376
  `authoring section "${key}" is ${kilobytes(bytes)}, over the ${kilobytes(DOC_OUTPUT_BUDGET_BYTES)} one read may return`,
1406
1377
  ),
1407
1378
  ];
1408
- const topic =
1409
- options.topicKeys === undefined
1410
- ? await authoringTopicKeys()
1411
- : {keys: options.topicKeys};
1412
1379
  const surface = [
1413
1380
  ...('error' in topic
1414
1381
  ? [
1415
1382
  `\`${formatCliCommand('docs authoring/field-reference')}\` could not be read: ${topic.error}`,
1416
1383
  ]
1417
1384
  : []),
1418
- ...surfaceProblems(
1419
- await auditAuthoringSurface({root, sources, topicKeys: topic.keys}),
1420
- ),
1385
+ ...surfaceProblems(surfaceAudit),
1421
1386
  ];
1422
1387
  if (problems.length + surface.length > 0) {
1423
1388
  return {
@@ -94,6 +94,65 @@ function headOfLetters(t, name) {
94
94
  /** How many of a family's members a query naming the family lists. */
95
95
  const FAMILY_MEMBERS = 3;
96
96
 
97
+ /**
98
+ * The pattern that finds any form of a term as a whole word in prose, with
99
+ * any common suffix, built once per term: a search tests it against every
100
+ * candidate's description.
101
+ * @type {Map<string, RegExp>}
102
+ */
103
+ const mentionPatterns = new Map();
104
+
105
+ /**
106
+ * How many terms' patterns are kept before the cache starts over. A compiled
107
+ * pattern is several kilobytes and a long-running caller sees ever new
108
+ * terms, so this cache stays small; one search uses a handful of terms.
109
+ */
110
+ const MENTION_LIMIT = 1_000;
111
+
112
+ /**
113
+ * @param {string} term
114
+ * @param {ReturnType<typeof termWords>} t - the term's words
115
+ * @returns {RegExp}
116
+ */
117
+ function mentionPattern(term, t) {
118
+ let re = mentionPatterns.get(term);
119
+ if (!re) {
120
+ if (mentionPatterns.size >= MENTION_LIMIT) mentionPatterns.clear();
121
+ // Any form of the term, with any common suffix: `spacing` finds
122
+ // "space" and "spaces", `tables` finds "table".
123
+ const roots = [...new Set([stem(term), ...t.forms])]
124
+ .filter(f => f.length >= 3)
125
+ .map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
126
+ re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
127
+ mentionPatterns.set(term, re);
128
+ }
129
+ return re;
130
+ }
131
+
132
+ /**
133
+ * Each prose text lowercased once per process: a search reads every
134
+ * candidate's description for every term.
135
+ * @type {Map<string, string>}
136
+ */
137
+ const lowered = new Map();
138
+
139
+ /** How many texts are kept lowercased before the cache starts over. */
140
+ const CACHE_LIMIT = 100_000;
141
+
142
+ /**
143
+ * @param {string} text
144
+ * @returns {string}
145
+ */
146
+ function lower(text) {
147
+ let out = lowered.get(text);
148
+ if (out === undefined) {
149
+ if (lowered.size >= CACHE_LIMIT) lowered.clear();
150
+ out = text.toLowerCase();
151
+ lowered.set(text, out);
152
+ }
153
+ return out;
154
+ }
155
+
97
156
  /**
98
157
  * A derived name's score for a term: 60 for the same word, 40 for a word the
99
158
  * term starts, else 0.
@@ -308,18 +367,13 @@ export function scoreCandidate(
308
367
  // Match the term's stem as a whole word, tolerating plural/gerund suffixes
309
368
  // so "chart" matches "charts" and "filter" matches "filtering".
310
369
  if (term.length >= 3) {
311
- // Any form of the term, with any common suffix: `spacing` finds
312
- // "space" and "spaces", `tables` finds "table".
313
- const roots = [...new Set([stem(term), ...t.forms])]
314
- .filter(f => f.length >= 3)
315
- .map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
316
- const re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
317
- if (description && re.test(description.toLowerCase())) {
370
+ const re = mentionPattern(term, t);
371
+ if (description && re.test(lower(description))) {
318
372
  consider(50, `description mentions "${term}"`);
319
373
  } else {
320
374
  let matchedProse = false;
321
375
  for (const blob of prose) {
322
- if (blob && re.test(String(blob).toLowerCase())) {
376
+ if (blob && re.test(lower(String(blob)))) {
323
377
  consider(50, `docs mention "${term}"`);
324
378
  matchedProse = true;
325
379
  break;
@@ -330,7 +384,7 @@ export function scoreCandidate(
330
384
  // summary. Only consulted when nothing stronger matched.
331
385
  if (!matchedProse) {
332
386
  for (const blob of guidance) {
333
- if (blob && re.test(String(blob).toLowerCase())) {
387
+ if (blob && re.test(lower(String(blob)))) {
334
388
  consider(45, `guidance mentions "${term}"`);
335
389
  break;
336
390
  }
@@ -0,0 +1,31 @@
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
+ /**
5
+ * The catalog's component and hook entries, each with the keywords that name
6
+ * another entry left out (see the file comment). Entries with nothing left
7
+ * out are returned as they are.
8
+ * @param {import('./_lexical.mjs').Candidate[]} all
9
+ * @param {import('./_lexical.mjs').Candidate[]} [named] - the entries whose
10
+ * names count: `all` itself, unless the caller holds a wider catalog
11
+ * (`all` cut to one `type`)
12
+ * @returns {import('./_lexical.mjs').Candidate[]}
13
+ */
14
+ export function withoutOtherNames(all: import("./_lexical.mjs").Candidate[], named?: import("./_lexical.mjs").Candidate[]): import("./_lexical.mjs").Candidate[];
15
+ /**
16
+ * The gathered catalog as search reads it: its entries with
17
+ * {@link withoutOtherNames} applied. Names come from the catalog and from
18
+ * `others`, further gathered catalogs (a search for one `type` passes the
19
+ * other of components and hooks, so `type` never changes which keywords
20
+ * count). A reused gather, with the same others, gets the same view back.
21
+ * @template {{all: import('./_lexical.mjs').Candidate[], components: import('./_lexical.mjs').Candidate[]}} T
22
+ * @param {T} catalog
23
+ * @param {{all: import('./_lexical.mjs').Candidate[]}[]} [others]
24
+ * @returns {T}
25
+ */
26
+ export function searchView<T extends {
27
+ all: import("./_lexical.mjs").Candidate[];
28
+ components: import("./_lexical.mjs").Candidate[];
29
+ }>(catalog: T, others?: {
30
+ all: import("./_lexical.mjs").Candidate[];
31
+ }[]): T;