@astryxdesign/cli 0.7.11 → 0.7.12-canary.0085c0f

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 (169) hide show
  1. package/api/build/blocks/blocks.d.mts +41 -0
  2. package/api/build/blocks/blocks.mjs +118 -68
  3. package/api/build/kit/rank.mjs +21 -4
  4. package/api/build/kit/words.d.mts +1 -0
  5. package/api/build/kit/words.mjs +1 -1
  6. package/api/component/__fixtures__/resolutions/modules.txt +5 -5
  7. package/api/docs/_adapter.d.mts +22 -0
  8. package/api/docs/_adapter.mjs +81 -3
  9. package/api/docs/docs.doc.mjs +5 -5
  10. package/api/docs/docs.type.d.mts +21 -0
  11. package/api/docs/docs.type.mjs +11 -0
  12. package/api/docs/list/list.d.mts +5 -1
  13. package/api/docs/list/list.mjs +72 -6
  14. package/api/docs/node/node.mjs +2 -40
  15. package/api/doctor/doctor.d.mts +4 -4
  16. package/api/doctor/doctor.mjs +248 -78
  17. package/api/icon/_adapter.d.mts +3 -2
  18. package/api/icon/_adapter.mjs +8 -2
  19. package/api/icon/_authoring.d.mts +1 -0
  20. package/api/icon/_authoring.mjs +594 -67
  21. package/api/icon/_default-look.d.mts +155 -0
  22. package/api/icon/_default-look.mjs +474 -0
  23. package/api/icon/_records.d.mts +1 -1
  24. package/api/icon/_records.mjs +1 -0
  25. package/api/icon/add/add.mjs +269 -43
  26. package/api/icon/icon.type.d.mts +46 -2
  27. package/api/icon/icon.type.mjs +12 -2
  28. package/api/icon/iconAdd.doc.mjs +2 -2
  29. package/api/icon/iconNewDefinition.doc.mjs +3 -2
  30. package/api/icon/iconNewSet.doc.mjs +4 -4
  31. package/api/icon/map/map.mjs +11 -4
  32. package/api/icon/search/search.mjs +10 -9
  33. package/api/index.d.mts +1 -0
  34. package/api/index.mjs +1 -0
  35. package/api/integration/add-helpers.d.mts +15 -1
  36. package/api/integration/add-helpers.mjs +5 -2
  37. package/api/integration/authoring-checks.d.mts +0 -2
  38. package/api/integration/authoring-checks.mjs +1 -6
  39. package/api/logger.mjs +2 -1
  40. package/api/render/_adapter.mjs +9 -0
  41. package/api/render/render.doc.mjs +3 -3
  42. package/api/render/render.type.d.mts +1 -1
  43. package/api/render/render.type.mjs +1 -1
  44. package/api/search/ORDERING.md +3 -0
  45. package/api/search/_adapter.d.mts +32 -3
  46. package/api/search/_adapter.mjs +50 -22
  47. package/api/search/_fit-order.d.mts +47 -0
  48. package/api/search/_fit-order.mjs +257 -0
  49. package/api/search/_main-searcher.mjs +15 -5
  50. package/api/search/exportSearchIndex.doc.d.mts +10 -0
  51. package/api/search/exportSearchIndex.doc.mjs +58 -0
  52. package/api/search/rankSearchIndex.doc.d.mts +10 -0
  53. package/api/search/rankSearchIndex.doc.mjs +79 -0
  54. package/api/search/search-index.d.mts +44 -0
  55. package/api/search/search-index.mjs +270 -0
  56. package/api/search/search.type.d.mts +28 -0
  57. package/api/search/search.type.mjs +17 -0
  58. package/api/swizzle/_adapter.d.mts +1 -0
  59. package/api/swizzle/_adapter.mjs +4 -1
  60. package/api/swizzle/_moduleGraph.d.mts +178 -0
  61. package/api/swizzle/_moduleGraph.mjs +903 -0
  62. package/api/swizzle/copy/copy.d.mts +2 -43
  63. package/api/swizzle/copy/copy.mjs +287 -315
  64. package/api/swizzle/swizzle.d.mts +0 -2
  65. package/api/swizzle/swizzle.doc.mjs +13 -4
  66. package/api/swizzle/swizzle.mjs +3 -7
  67. package/api/swizzle/swizzle.type.d.mts +7 -1
  68. package/api/swizzle/swizzle.type.mjs +4 -2
  69. package/api/template/skeleton/skeleton.mjs +1 -1
  70. package/api/template/template.mjs +1 -0
  71. package/assets/codemods/transforms/v0.1.0/drop-xds-prefix-imports.mjs +1 -1
  72. package/assets/codemods/transforms/v0.1.0/index.mjs +1 -1
  73. package/assets/discover/official-packages.json +40 -0
  74. package/assets/docs/browser-support.doc.mjs +2 -2
  75. package/assets/docs/styling-overview.doc.mjs +6 -2
  76. package/assets/docs/tree/icon-sets.doc.mjs +13 -7
  77. package/assets/docs/tree/render-pages.doc.mjs +3 -3
  78. package/assets/docs/tree/tailwind.doc.mjs +41 -1
  79. package/assets/docs/tree/type-scale.doc.mjs +19 -2
  80. package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.doc.mjs +14 -0
  81. package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.tsx +146 -0
  82. package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.doc.mjs +14 -0
  83. package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.tsx +173 -0
  84. package/assets/templates/blocks/components/Hooks/useInputStatusIconHookUsage.tsx +1 -0
  85. package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.doc.mjs +14 -0
  86. package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.tsx +56 -0
  87. package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.doc.mjs +2 -2
  88. package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.tsx +66 -10
  89. package/assets/templates/blocks/components/Link/useLinkifyHookUsage.doc.mjs +14 -0
  90. package/assets/templates/blocks/components/Link/useLinkifyHookUsage.tsx +39 -0
  91. package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.doc.mjs +14 -0
  92. package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.tsx +83 -0
  93. package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.doc.mjs +14 -0
  94. package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.tsx +41 -0
  95. package/assets/templates/blocks/components/Table/TableRowIndexTable.doc.mjs +1 -1
  96. package/assets/templates/blocks/components/Table/TableRowIndexTable.tsx +2 -2
  97. package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.doc.mjs +14 -0
  98. package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.tsx +97 -0
  99. package/assets/templates/pages/course-detail/page.tsx +699 -0
  100. package/assets/templates/pages/course-detail/template.doc.mjs +37 -0
  101. package/assets/templates/pages/file-explorer/page.tsx +103 -79
  102. package/assets/templates/pages/table-filter/page.tsx +15 -23
  103. package/assets/templates/pages/table-grouped/page.tsx +190 -262
  104. package/assets/templates/pages/table-grouped/template.doc.mjs +0 -2
  105. package/assets/templates/pages/table-inbox/page.tsx +3 -6
  106. package/assets/templates/pages/theme-showcase/page.tsx +724 -792
  107. package/assets/templates/pages/theme-showcase/template.doc.mjs +4 -5
  108. package/assets/templates/themes/butter/butterTheme.ts +2 -2
  109. package/assets/templates/themes/gothic/gothicTheme.ts +16 -0
  110. package/assets/templates/themes/matcha/matchaTheme.ts +1 -1
  111. package/assets/templates/themes/neutral/neutralTheme.ts +6 -0
  112. package/assets/templates/themes/stone/stoneTheme.ts +1 -1
  113. package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +1 -1
  114. package/assets/templates/themes/y2k/y2kTheme.ts +2 -2
  115. package/authoring/doctypes/template/type.ts +1 -0
  116. package/clients/cli/commands/docs.doc.mjs +5 -1
  117. package/clients/cli/commands/docs.mjs +30 -2
  118. package/clients/cli/commands/experimental/icon.mjs +56 -14
  119. package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
  120. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +2 -1
  121. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
  122. package/clients/cli/commands/experimental-render.doc.mjs +1 -1
  123. package/clients/cli/commands/swizzle.doc.mjs +12 -3
  124. package/clients/cli/commands/swizzle.mjs +33 -9
  125. package/clients/cli/commands/template.mjs +204 -181
  126. package/clients/cli/lib/resolve-theme.mjs +16 -7
  127. package/foundation/discovery/component-discovery.mjs +1 -1
  128. package/foundation/discovery/component-loader.d.mts +1 -1
  129. package/foundation/discovery/doc-types.mjs +9 -2
  130. package/foundation/discovery/hook-discovery.mjs +31 -8
  131. package/foundation/discovery/icon-ranking.d.mts +27 -3
  132. package/foundation/discovery/icon-ranking.mjs +125 -8
  133. package/foundation/discovery/icon-set-checks.mjs +44 -35
  134. package/foundation/discovery/icon-set-discovery.d.mts +13 -0
  135. package/foundation/discovery/icon-set-discovery.mjs +25 -0
  136. package/foundation/discovery/icon-set-writer.d.mts +258 -20
  137. package/foundation/discovery/icon-set-writer.mjs +785 -87
  138. package/foundation/discovery/module-exports.d.mts +3 -2
  139. package/foundation/discovery/module-exports.mjs +167 -37
  140. package/foundation/discovery/template-adapter.mjs +2 -2
  141. package/foundation/doc-compiler/import.d.mts +5 -1
  142. package/foundation/doc-compiler/import.mjs +40 -6
  143. package/foundation/fs/import-url.d.mts +20 -0
  144. package/foundation/fs/import-url.mjs +22 -0
  145. package/foundation/fs/module-loader.d.mts +24 -3
  146. package/foundation/fs/module-loader.mjs +69 -47
  147. package/foundation/fs/paths.d.mts +2 -1
  148. package/foundation/fs/paths.mjs +3 -4
  149. package/foundation/render/charts.d.mts +59 -0
  150. package/foundation/render/charts.mjs +216 -0
  151. package/foundation/render/embedded-imports.d.mts +7 -7
  152. package/foundation/render/embedded-imports.mjs +63 -54
  153. package/foundation/render/page-host.d.mts +4 -0
  154. package/foundation/render/page-host.mjs +45 -0
  155. package/foundation/render/page-worker.mjs +350 -57
  156. package/foundation/render/render-page.d.mts +11 -6
  157. package/foundation/render/render-page.mjs +164 -54
  158. package/foundation/render/ts-paths.d.mts +63 -0
  159. package/foundation/render/ts-paths.mjs +138 -0
  160. package/foundation/response/error-codes.doc.mjs +3 -3
  161. package/foundation/response/error-codes.mjs +3 -2
  162. package/foundation/text/levenshtein.d.mts +6 -1
  163. package/foundation/text/levenshtein.mjs +25 -9
  164. package/foundation/text/shell-arg.d.mts +14 -0
  165. package/foundation/text/shell-arg.mjs +17 -0
  166. package/foundation/text/suggest-order.d.mts +8 -1
  167. package/foundation/text/suggest-order.mjs +72 -6
  168. package/foundation/xle/registry-core.mjs +1 -1
  169. package/package.json +7 -6
@@ -0,0 +1,270 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file A stored search index: the candidates `search` gathers in a folder, as
5
+ * plain JSON, and the ranking of stored candidates with search's own tree.
6
+ *
7
+ * Gathering reads every package's docs and loads its manifest, which runs the
8
+ * package's code. A catalog that lists packages it must not load (a web page
9
+ * that lists every published integration) stores each package's index once,
10
+ * where loading is safe, and ranks the stored indexes per query.
11
+ * @position api/search; search.mjs is the folder-reading search.
12
+ */
13
+
14
+ import {
15
+ docPackageManager,
16
+ runWithDocPackageManager,
17
+ } from '../../foundation/env/package-manager.mjs';
18
+ import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
19
+ import {cliVersion} from '../../foundation/release/run-context.mjs';
20
+ import {runTree} from '../../foundation/route/route.mjs';
21
+ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
22
+ import {linkSearchResponse} from '../component/_adapter.mjs';
23
+ import {AstryxError} from '../error.mjs';
24
+ import {
25
+ gatherCandidates,
26
+ loadSearchData,
27
+ resolveSearchCore,
28
+ } from './_adapter.mjs';
29
+ import {checkSearchArgs} from './_result.mjs';
30
+ import {SEARCH_TREE} from './tree.mjs';
31
+
32
+ /**
33
+ * Fields a gathered candidate holds that point into the folder it was read
34
+ * from. They decide ownership while gathering and never rank, so an index
35
+ * leaves them out and reads the same wherever it was made.
36
+ */
37
+ const LOCAL_FIELDS = ['_docPath'];
38
+
39
+ /**
40
+ * A component candidate's description as `search` prints it: its inline
41
+ * `{@link}`, `{@pm}` and `{@command}` tokens resolved in the folder the index
42
+ * is made in. The raw description stays the one that is scored.
43
+ */
44
+ const DISPLAY_FIELD = '_displayDescription';
45
+
46
+ /** Stands for the Core the indexes were made with, which ranking never reads. */
47
+ const STORED_CORE = 'stored-index';
48
+
49
+ /**
50
+ * @param {Record<string, unknown>} candidate
51
+ * @returns {Record<string, unknown>}
52
+ */
53
+ function portable(candidate) {
54
+ /** @type {Record<string, unknown>} */
55
+ const out = JSON.parse(JSON.stringify(candidate));
56
+ for (const field of LOCAL_FIELDS) delete out[field];
57
+ return out;
58
+ }
59
+
60
+ /**
61
+ * The candidates `search` ranks in a folder, as plain JSON: store it, and rank
62
+ * it later with {@link rankSearchIndex}.
63
+ *
64
+ * Experimental (spec:AST-017 FR27): may change or be removed in a patch
65
+ * release.
66
+ * @experimental
67
+ * @param {object} [options]
68
+ * @param {string} [options.cwd] - The folder to gather from, as `search` reads it.
69
+ * @param {string} [options.package] - Keep only the candidates this npm package
70
+ * owns (its components, templates, themes, and doc parts).
71
+ * @returns {Promise<import('./search.type.mjs').SearchIndex>}
72
+ */
73
+ export async function exportSearchIndex(options = {}) {
74
+ const {cwd = process.cwd(), package: owner} = options;
75
+ if (owner != null && (typeof owner !== 'string' || owner.trim() === '')) {
76
+ throw new AstryxError(
77
+ `Invalid package "${owner}". Pass an npm package name.`,
78
+ undefined,
79
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
80
+ );
81
+ }
82
+ return runWithDocPackageManager(docPackageManager(cwd), () =>
83
+ withListingCache(async () => {
84
+ const gathered = await gatherCandidates({cwd});
85
+ const kept =
86
+ owner == null
87
+ ? gathered.all
88
+ : gathered.all.filter(candidate => candidate._package === owner);
89
+ const candidates = kept.map(candidate =>
90
+ portable(/** @type {Record<string, unknown>} */ (candidate)),
91
+ );
92
+ await addDisplayDescriptions(candidates, cwd);
93
+ return {
94
+ version: cliVersion(),
95
+ candidates,
96
+ ...(gathered.coreSkipped == null
97
+ ? {}
98
+ : {
99
+ coreSkipped: gathered.coreSkipped,
100
+ ...(gathered.coreSkippedCode == null
101
+ ? {}
102
+ : {coreSkippedCode: gathered.coreSkippedCode}),
103
+ }),
104
+ };
105
+ }),
106
+ );
107
+ }
108
+
109
+ /**
110
+ * Resolves each component description's inline tokens as `search` does for
111
+ * the results it prints, and keeps the printed text beside the scored one.
112
+ * @param {Record<string, unknown>[]} candidates
113
+ * @param {string} cwd
114
+ */
115
+ async function addDisplayDescriptions(candidates, cwd) {
116
+ const linkable = candidates.filter(
117
+ candidate =>
118
+ candidate.domain === 'component' &&
119
+ typeof candidate.description === 'string' &&
120
+ candidate.description.includes('{@'),
121
+ );
122
+ if (linkable.length === 0) return;
123
+ const response = await linkSearchResponse(
124
+ /** @type {any} */ ({
125
+ type: 'search',
126
+ data: {
127
+ results: linkable.map(candidate => ({
128
+ domain: 'component',
129
+ package: candidate._package,
130
+ description: candidate.description,
131
+ })),
132
+ },
133
+ }),
134
+ cwd,
135
+ );
136
+ response.data.results.forEach(
137
+ (/** @type {any} */ result, /** @type {number} */ i) => {
138
+ if (result.description !== linkable[i].description)
139
+ linkable[i][DISPLAY_FIELD] = result.description;
140
+ },
141
+ );
142
+ }
143
+
144
+ /**
145
+ * Ranks stored indexes with search's tree. An index made in one folder answers
146
+ * as `search(query)` does there (a theme result's command is the in-project
147
+ * `theme add`). Indexes made in separate folders, such as one per package
148
+ * (made with `package`) and one for Core, are ranked together as one list; a
149
+ * doc that one package replaces or extends in another is not merged across
150
+ * them. Every index must come from this CLI's version, since the tree reads
151
+ * the candidates' shape. When every index was made where Core could not be
152
+ * had, the answer carries `meta.partial`, as `search` does.
153
+ *
154
+ * Experimental (spec:AST-017 FR27): may change or be removed in a patch
155
+ * release.
156
+ * @experimental
157
+ * @param {string} query - Free-text search term.
158
+ * @param {import('./search.type.mjs').SearchIndex | import('./search.type.mjs').SearchIndex[]} indexes
159
+ * @param {object} [options]
160
+ * @param {import('./search.type.mjs').SearchDomain} [options.type] - Restrict to one domain.
161
+ * @param {number} [options.limit] - Max results (default 20).
162
+ * @returns {Promise<import('./search.type.mjs').SearchResponse>}
163
+ */
164
+ export async function rankSearchIndex(query, indexes, options = {}) {
165
+ checkSearchArgs(query, options);
166
+ const list = Array.isArray(indexes) ? indexes : [indexes];
167
+ const version = cliVersion();
168
+ /** @type {any[]} */
169
+ const all = [];
170
+ for (const index of list) {
171
+ if (index == null || !Array.isArray(index.candidates)) {
172
+ throw new AstryxError(
173
+ 'A search index is {version, candidates}, as exportSearchIndex() returns it.',
174
+ undefined,
175
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
176
+ );
177
+ }
178
+ if (index.version !== version) {
179
+ throw new AstryxError(
180
+ `This search index was made by CLI ${index.version}; this is CLI ${version}. Make it again with this version's exportSearchIndex().`,
181
+ undefined,
182
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
183
+ );
184
+ }
185
+ all.push(...index.candidates);
186
+ }
187
+ const {type} = options;
188
+ const wanted =
189
+ type == null ? all : all.filter(candidate => candidate.domain === type);
190
+ const {searchedComponents, coreSkipped} = coreFlags(list, type);
191
+ const response = /** @type {import('./search.type.mjs').SearchResponse} */ (
192
+ await runTree(
193
+ SEARCH_TREE,
194
+ {query, options: {type, limit: options.limit}},
195
+ {
196
+ all: wanted,
197
+ components: wanted.filter(
198
+ candidate => candidate.domain === 'component',
199
+ ),
200
+ searchedComponents,
201
+ outside: false,
202
+ coreSkipped,
203
+ coreSkippedCode: null,
204
+ data: loadSearchData(),
205
+ },
206
+ )
207
+ );
208
+ return withDisplayDescriptions(response, wanted);
209
+ }
210
+
211
+ /**
212
+ * The catalog flags `search` derives from Core for a request of `type`, by
213
+ * search's own rule (`resolveSearchCore`). Core is missing only when no index
214
+ * had it. An open search then names what it skipped. A docs or themes search
215
+ * never reads Core. A Core domain asked for by name throws the error that
216
+ * `search` throws.
217
+ * @param {import('./search.type.mjs').SearchIndex[]} list
218
+ * @param {import('./search.type.mjs').SearchDomain | undefined} type
219
+ * @returns {{searchedComponents: boolean, coreSkipped: string | null}}
220
+ */
221
+ function coreFlags(list, type) {
222
+ const missing =
223
+ list.length > 0 &&
224
+ list.every(index => typeof index.coreSkipped === 'string');
225
+ const lookup = () => {
226
+ if (!missing) return STORED_CORE;
227
+ throw Object.assign(
228
+ new Error(/** @type {string} */ (list[0].coreSkipped)),
229
+ {
230
+ code: list[0].coreSkippedCode ?? ERROR_CODES.ERR_CORE_NOT_FOUND,
231
+ },
232
+ );
233
+ };
234
+ const {coreSkipped, wants} = resolveSearchCore(type, lookup, STORED_CORE);
235
+ return {searchedComponents: wants('component'), coreSkipped};
236
+ }
237
+
238
+ /**
239
+ * The response with each component result's description as `search` prints
240
+ * it, from the text the index stored when it was made.
241
+ * @param {import('./search.type.mjs').SearchResponse} response
242
+ * @param {any[]} candidates
243
+ * @returns {import('./search.type.mjs').SearchResponse}
244
+ */
245
+ function withDisplayDescriptions(response, candidates) {
246
+ /** @type {Map<string, string>} */
247
+ const display = new Map();
248
+ for (const candidate of candidates) {
249
+ if (
250
+ candidate.domain === 'component' &&
251
+ typeof candidate[DISPLAY_FIELD] === 'string'
252
+ )
253
+ display.set(
254
+ `${candidate._package}\u0000${candidate._resultName ?? candidate.name}`,
255
+ candidate[DISPLAY_FIELD],
256
+ );
257
+ }
258
+ if (display.size === 0) return response;
259
+ return {
260
+ ...response,
261
+ data: {
262
+ ...response.data,
263
+ results: response.data.results.map(result => {
264
+ if (result.domain !== 'component') return result;
265
+ const text = display.get(`${result.package}\u0000${result.name}`);
266
+ return text == null ? result : {...result, description: text};
267
+ }),
268
+ },
269
+ };
270
+ }
@@ -95,6 +95,34 @@ export type SearchResponse = {
95
95
  };
96
96
  } | undefined;
97
97
  };
98
+ /**
99
+ * The candidates `search` ranks in a folder, as `exportSearchIndex()` returns them:
100
+ * plain JSON to store and rank later with `rankSearchIndex()`.
101
+ */
102
+ export type SearchIndex = {
103
+ /**
104
+ * - The CLI version that made it. `rankSearchIndex()`
105
+ * ranks only indexes made by its own version.
106
+ */
107
+ version: string;
108
+ /**
109
+ * - The gathered candidates,
110
+ * each the entry search scores. Their fields are the ranker's input, not a
111
+ * contract: they may change in any release, which is why `version` must match.
112
+ */
113
+ candidates: Record<string, unknown>[];
114
+ /**
115
+ * - Why Core could not be had where the index
116
+ * was made, when it could not: its components, hooks and templates are then
117
+ * missing, and `rankSearchIndex()` answers as `search` does without Core
118
+ * (`meta.partial` for an open search; refused for a domain that reads Core).
119
+ */
120
+ coreSkipped?: string | undefined;
121
+ /**
122
+ * - The error code that Core lookup gave.
123
+ */
124
+ coreSkippedCode?: string | undefined;
125
+ };
98
126
  /**
99
127
  * Options for `search()`.
100
128
  */
@@ -51,6 +51,23 @@
51
51
  * The results are the docs and themes.
52
52
  */
53
53
 
54
+ /**
55
+ * The candidates `search` ranks in a folder, as `exportSearchIndex()` returns them:
56
+ * plain JSON to store and rank later with `rankSearchIndex()`.
57
+ * @experimental May change or be removed in a patch release.
58
+ * @typedef {object} SearchIndex
59
+ * @property {string} version - The CLI version that made it. `rankSearchIndex()`
60
+ * ranks only indexes made by its own version.
61
+ * @property {Record<string, unknown>[]} candidates - The gathered candidates,
62
+ * each the entry search scores. Their fields are the ranker's input, not a
63
+ * contract: they may change in any release, which is why `version` must match.
64
+ * @property {string} [coreSkipped] - Why Core could not be had where the index
65
+ * was made, when it could not: its components, hooks and templates are then
66
+ * missing, and `rankSearchIndex()` answers as `search` does without Core
67
+ * (`meta.partial` for an open search; refused for a domain that reads Core).
68
+ * @property {string} [coreSkippedCode] - The error code that Core lookup gave.
69
+ */
70
+
54
71
  /**
55
72
  * Options for `search()`.
56
73
  * @typedef {object} SearchOptions
@@ -30,3 +30,4 @@ export function resolveCore(cwd: string): {
30
30
  components: string[];
31
31
  };
32
32
  export { CORE_PROVIDER_ID as CORE_PACKAGE } from "../../foundation/identity/providers.mjs";
33
+ export { planCopy, relativeSpecifierBetween, renderFile } from "./_moduleGraph.mjs";
@@ -9,7 +9,8 @@
9
9
  * for its "component not found" suggestions. Resolving core + listing lives
10
10
  * here once so neither leaf re-walks the filesystem. Throws AstryxError
11
11
  * (ERR_CORE_NOT_FOUND) when core can't be located. The copy receipt's `gh`
12
- * lookup is here too, on the shared search-path walk.
12
+ * lookup is here too, on the shared search-path walk, and so is the copy's
13
+ * module graph (_moduleGraph.mjs), which reads the owner package's source.
13
14
  */
14
15
 
15
16
  import {executablesOnSearchPath} from '../../foundation/env/search-path.mjs';
@@ -18,6 +19,8 @@ import {resolveComponentReplacements} from '../../foundation/discovery/component
18
19
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
19
20
  import {AstryxError} from '../error.mjs';
20
21
 
22
+ export {planCopy, relativeSpecifierBetween, renderFile} from './_moduleGraph.mjs';
23
+
21
24
  /**
22
25
  * Whether an executable `gh` is on `PATH` (with a `PATHEXT` extension on
23
26
  * Windows), found without running it. The copy receipt offers its
@@ -0,0 +1,178 @@
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
+ * A specifier that is either fixed (a public subpath) or computed from where
6
+ * two copied files land.
7
+ * @typedef {string | {from: string, to: string}} SpecifierChoice
8
+ *
9
+ * @typedef {object} PlannedEdit
10
+ * @property {number} start
11
+ * @property {number} end
12
+ * @property {(specifierOf: (choice: SpecifierChoice) => string) => string} render
13
+ *
14
+ * @typedef {object} CopyPlan
15
+ * @property {Map<string, {code: string, edits: PlannedEdit[]}>} files every
16
+ * file the copy holds (absolute source path), with the edits its imports need
17
+ * @property {Map<string, Set<string>>} dependsOn file -> carried files its
18
+ * computed specifiers point at
19
+ * @property {Map<string, string>} otherPackages the source root of each other
20
+ * Astryx package the copy carries modules from, with its package name
21
+ * @property {Record<string, string>} dependencies each npm package the copied
22
+ * files import, other than the owner package and Node's built-in modules,
23
+ * with the range the owner package declares
24
+ */
25
+ /**
26
+ * Follow a component's module graph from its entry files and decide what the
27
+ * copy holds. A module inside the component folder is copied. A module
28
+ * outside it is reached through the owner package's public exports when every
29
+ * name taken from it is public there; otherwise the module that defines the
30
+ * name is copied, and imported by relative path. Tests, stories and docs are
31
+ * never reached, so they are never copied.
32
+ *
33
+ * @param {object} options
34
+ * @param {string} options.packageDir the owner package root
35
+ * @param {string} options.srcRoot its source root
36
+ * @param {string} options.componentDir
37
+ * @param {string} options.ownerPackage
38
+ * @param {string[]} options.entries absolute entry files of the component
39
+ * @returns {CopyPlan}
40
+ */
41
+ export function planCopy({ packageDir, srcRoot, componentDir, ownerPackage, entries, }: {
42
+ packageDir: string;
43
+ srcRoot: string;
44
+ componentDir: string;
45
+ ownerPackage: string;
46
+ entries: string[];
47
+ }): CopyPlan;
48
+ /**
49
+ * The source of a planned file with its edits applied.
50
+ * @param {{code: string, edits: PlannedEdit[]}} planned
51
+ * @param {(choice: SpecifierChoice) => string} specifierOf
52
+ */
53
+ export function renderFile(planned: {
54
+ code: string;
55
+ edits: PlannedEdit[];
56
+ }, specifierOf: (choice: SpecifierChoice) => string): string;
57
+ /**
58
+ * The relative specifier from one written file to another.
59
+ * @param {string} fromDest
60
+ * @param {string} toDest
61
+ */
62
+ export function relativeSpecifierBetween(fromDest: string, toDest: string): string;
63
+ export type ImportSpecifier = {
64
+ /**
65
+ * the exported name (`default` for a default import)
66
+ */
67
+ imported: string;
68
+ local: string;
69
+ typeOnly: boolean;
70
+ };
71
+ export type ModuleReference = {
72
+ kind: "named" | "namespace" | "sideEffect" | "dynamic" | "reexportAll" | "reexportNamed";
73
+ /**
74
+ * the specifier as written
75
+ */
76
+ source: string;
77
+ /**
78
+ * statement (or, for `import()`, string literal) start
79
+ */
80
+ start: number;
81
+ end: number;
82
+ /**
83
+ * the whole statement is `import type` / `export type`
84
+ */
85
+ typeOnly: boolean;
86
+ specifiers: ImportSpecifier[];
87
+ /**
88
+ * the local name of `* as X`
89
+ */
90
+ namespace?: string | undefined;
91
+ };
92
+ export type ParsedModule = {
93
+ code: string;
94
+ references: ModuleReference[];
95
+ /**
96
+ * names the module declares and exports
97
+ */
98
+ declares: Set<string>;
99
+ };
100
+ /**
101
+ * `value` reads runtime exports only;
102
+ * `type` reads type-only exports too
103
+ */
104
+ export type ExportKind = "value" | "type";
105
+ /**
106
+ * every name a module exports, with where it is declared
107
+ */
108
+ export type OriginsOf = (file: string, kind: ExportKind) => Map<string, {
109
+ file: string;
110
+ name: string;
111
+ }>;
112
+ /**
113
+ * `file#name` of a declaration -> the subpaths that export it, and as what
114
+ */
115
+ export type ExportersByOrigin = Map<string, Array<{
116
+ subpath: string;
117
+ name: string;
118
+ }>>;
119
+ export type PublicSurface = {
120
+ /**
121
+ * the subpaths
122
+ * that export each declaration as a value, and as a value or a type
123
+ */
124
+ byOrigin: Record<ExportKind, ExportersByOrigin>;
125
+ /**
126
+ * source file -> the subpath that
127
+ * exports exactly that file
128
+ */
129
+ byFile: Map<string, string>;
130
+ exportsField: Record<string, unknown> | undefined;
131
+ };
132
+ /**
133
+ * A specifier that is either fixed (a public subpath) or computed from where
134
+ * two copied files land.
135
+ */
136
+ export type SpecifierChoice = string | {
137
+ from: string;
138
+ to: string;
139
+ };
140
+ /**
141
+ * A specifier that is either fixed (a public subpath) or computed from where
142
+ * two copied files land.
143
+ */
144
+ export type PlannedEdit = {
145
+ start: number;
146
+ end: number;
147
+ render: (specifierOf: (choice: SpecifierChoice) => string) => string;
148
+ };
149
+ /**
150
+ * A specifier that is either fixed (a public subpath) or computed from where
151
+ * two copied files land.
152
+ */
153
+ export type CopyPlan = {
154
+ /**
155
+ * every
156
+ * file the copy holds (absolute source path), with the edits its imports need
157
+ */
158
+ files: Map<string, {
159
+ code: string;
160
+ edits: PlannedEdit[];
161
+ }>;
162
+ /**
163
+ * file -> carried files its
164
+ * computed specifiers point at
165
+ */
166
+ dependsOn: Map<string, Set<string>>;
167
+ /**
168
+ * the source root of each other
169
+ * Astryx package the copy carries modules from, with its package name
170
+ */
171
+ otherPackages: Map<string, string>;
172
+ /**
173
+ * each npm package the copied
174
+ * files import, other than the owner package and Node's built-in modules,
175
+ * with the range the owner package declares
176
+ */
177
+ dependencies: Record<string, string>;
178
+ };