@astryxdesign/cli 0.7.9-canary.828bc9b → 0.7.9-canary.87ed8d0

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.
package/README.md CHANGED
@@ -499,7 +499,7 @@ Every response has a `type` discriminant. The full set is below (generated from
499
499
  | `build.help` | The how-to-build-a-page playbook, emitted when no query is given: `playbook: true`, a title, the ordered steps (title, commands, optional returns), the on-system rules, and related lookups. Commands are bare subcommands for the caller to render with its own invocation. |
500
500
  | `build.kit` | The template to start from and its kit: query, hasResults, matchCount (never a cap), directMatch, start {name, package, command, basis, reason, alternatives, ...} (the start and each alternative name the package that owns the template), pages (search's closest templates), blocks and domain as SearchResultEntry[] (each naming its package), frame and foundation (Core component names), and hint {reason, commands} when thin. |
501
501
  | `swizzle.list` | The names of swizzlable components discoverable from cwd's @astryxdesign/core. The envelope's package is @astryxdesign/core. |
502
- | `swizzle.copy` | An eject receipt: component name, owning package, output directory, files-copied count, the written file names, whether any file uses StyleX, and, when the owner has an issues URL, feedback ({issuesUrl, ghCommand?}): where to report the gap that led to swizzling. The envelope's package names the same owning package. |
502
+ | `swizzle.copy` | An eject receipt: component name, owning package, output directory, files-copied count, the copied file names (relative to the component folder; owner modules copied beside it start with ../), whether any file uses StyleX, and, when the owner has an issues URL, feedback ({issuesUrl, ghCommand?}): where to report the gap that led to swizzling. The envelope's package names the same owning package. |
503
503
  | `gap-report.categories` | The fixed gap category values and human-readable labels; when a loaded integration names its own issues URL, meta.destinations lists every destination ({to, default, issuesUrl}) and meta.ask tells an agent to ask the person. |
504
504
  | `gap-report.file` | An aggregate receipt: overall status, the selected package, issuesUrl (or null), deliveries in handler order, each {handlerType: project \| integration \| fallback, handler, audience, status, url, message}, and filedCount/routedOnlyCount totals; without --to, when a loaded integration names its own issues URL, destinations and ask as on gap-report.categories. |
505
505
  | `template.list` | The effective discovered TemplateListEntry[] for pages and blocks. A winning replacement entry includes optional `replaces`, naming the Core id omitted from the default list. |
@@ -264,7 +264,7 @@ useEndLaneReserve useEndLaneReserve Tokenizer/Tokenizer.doc.mjs Tokenizer/useEnd
264
264
  useFieldStatusAnnouncement useFieldStatusAnnouncement FieldStatus/FieldStatus.doc.mjs FieldStatus/useFieldStatusAnnouncement.ts
265
265
  useFocusReturnVisibility useFocusReturnVisibility hooks/useAnimatedLayout.doc.mjs hooks/useFocusReturnVisibility.ts
266
266
  useHighlightedOptionScroll useHighlightedOptionScroll hooks/useAnimatedLayout.doc.mjs hooks/useHighlightedOptionScroll.ts
267
- useIcon useIcon Icon/Icon.doc.mjs Icon/useIcon.ts
267
+ useIcon useIcon Icon/useIcon.doc.mjs Icon/useIcon.ts
268
268
  useIndicator useIndicator Indicator/Indicator.doc.mjs Indicator/useIndicator.ts
269
269
  useInternalConfig useInternalConfig PowerSearch/PowerSearch.doc.mjs PowerSearch/useInternalConfig.ts
270
270
  useIsHydrating useIsHydrating hooks/useAnimatedLayout.doc.mjs hooks/useIsHydrating.ts
@@ -37,9 +37,10 @@
37
37
 
38
38
  import {
39
39
  stem,
40
- wordForms,
41
40
  sameWord,
42
- startsAWordOf,
41
+ sameTermWord,
42
+ startsATermWordOf,
43
+ termWords,
43
44
  wordsOf,
44
45
  joined,
45
46
  typoDistance,
@@ -78,14 +79,14 @@ function spellsOut(term, name, description) {
78
79
  /**
79
80
  * Whether a one-word term is a name's last word and every word before it is a
80
81
  * single letter: Stack in VStack and HStack.
81
- * @param {string} term
82
+ * @param {import('./_words.mjs').TermWords} t
82
83
  * @param {string} name
83
84
  */
84
- function headOfLetters(term, name) {
85
+ function headOfLetters(t, name) {
85
86
  const parts = wordsOf(name);
86
87
  return (
87
88
  parts.length >= 2 &&
88
- sameWord(term, parts[parts.length - 1]) &&
89
+ sameTermWord(t, parts[parts.length - 1]) &&
89
90
  parts.slice(0, -1).every(p => p.length === 1)
90
91
  );
91
92
  }
@@ -96,14 +97,14 @@ const FAMILY_MEMBERS = 3;
96
97
  /**
97
98
  * A derived name's score for a term: 60 for the same word, 40 for a word the
98
99
  * term starts, else 0.
99
- * @param {string} term - Lowercased search term.
100
+ * @param {import('./_words.mjs').TermWords} t - The lowercased search term.
100
101
  * @param {string} kw - The derived name as authored.
101
102
  * @returns {number}
102
103
  */
103
- function weakKeywordScore(term, kw) {
104
+ function weakKeywordScore(t, kw) {
104
105
  const kwLower = String(kw).toLowerCase();
105
- if (kwLower === term || sameWord(term, kwLower)) return 60;
106
- return startsAWordOf(term, kw) ? 40 : 0;
106
+ if (kwLower === t.term || sameTermWord(t, kwLower)) return 60;
107
+ return startsATermWordOf(t, kw) ? 40 : 0;
107
108
  }
108
109
 
109
110
  /**
@@ -146,6 +147,8 @@ export function scoreCandidate(
146
147
  _family,
147
148
  _familyIndex,
148
149
  } = candidate;
150
+ // The term's forms, worked out once for every word below.
151
+ const t = termWords(term);
149
152
  let best = 0;
150
153
  let reason = '';
151
154
  /** @type {'partial' | 'keyword' | false} */
@@ -208,18 +211,18 @@ export function scoreCandidate(
208
211
  // outranks the Token component for `tokens`.
209
212
  consider(99, 'plural of the name');
210
213
  } else {
211
- if (sameWord(term, nameLower)) consider(95, `name "${candidateName}"`);
214
+ if (sameTermWord(t, nameLower)) consider(95, `name "${candidateName}"`);
212
215
  // The term is a word of the name, or starts one: "input" in TextInput.
213
216
  else if (
214
217
  !part &&
215
218
  domain !== 'doc' &&
216
219
  domain !== 'theme' &&
217
- headOfLetters(term, candidateName)
220
+ headOfLetters(t, candidateName)
218
221
  ) {
219
222
  // The whole query is the name's head word after single letters (Stack
220
223
  // in VStack, HStack): a variant named by its head, as a keyword is.
221
224
  consider(90, `name "${candidateName}" ends in "${term}"`);
222
- } else if (startsAWordOf(term, candidateName)) {
225
+ } else if (startsATermWordOf(t, candidateName)) {
223
226
  consider(60, `name contains "${term}"`);
224
227
  }
225
228
  if (fuzzy) {
@@ -273,11 +276,11 @@ export function scoreCandidate(
273
276
  consider(90, `keyword "${kw}"`, 'keyword');
274
277
  continue;
275
278
  }
276
- if (sameWord(term, kwLower)) {
279
+ if (sameTermWord(t, kwLower)) {
277
280
  consider(88, `keyword "${kw}"`);
278
281
  continue;
279
282
  }
280
- if (startsAWordOf(term, kw)) consider(70, `keyword "${kw}"`);
283
+ if (startsATermWordOf(t, kw)) consider(70, `keyword "${kw}"`);
281
284
  if (fuzzy) {
282
285
  const dist = typoDistance(term, kwLower);
283
286
  if (dist != null && dist <= 2) {
@@ -294,9 +297,9 @@ export function scoreCandidate(
294
297
  // A bound skips the read when no name the page can yield matches the term,
295
298
  // and then no weak keyword can match it either.
296
299
  const bound = candidate.weakKeywordBound;
297
- if (!bound || bound.some(kw => weakKeywordScore(term, kw) > 0)) {
300
+ if (!bound || bound.some(kw => weakKeywordScore(t, kw) > 0)) {
298
301
  for (const kw of candidate.weakKeywords ?? []) {
299
- const score = weakKeywordScore(term, kw);
302
+ const score = weakKeywordScore(t, kw);
300
303
  if (score > 0) consider(score, `renders ${kw}`);
301
304
  }
302
305
  }
@@ -307,7 +310,7 @@ export function scoreCandidate(
307
310
  if (term.length >= 3) {
308
311
  // Any form of the term, with any common suffix: `spacing` finds
309
312
  // "space" and "spaces", `tables` finds "table".
310
- const roots = [...new Set([stem(term), ...wordForms(term)])]
313
+ const roots = [...new Set([stem(term), ...t.forms])]
311
314
  .filter(f => f.length >= 3)
312
315
  .map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
313
316
  const re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
@@ -10,9 +10,7 @@
10
10
  */
11
11
  export function stem(w: string): string;
12
12
  /**
13
- * The forms of a word that count as the same word: itself, its stem, and its
14
- * singular when it ends in a plural suffix — so "tables" is "table",
15
- * "statuses" is "status", and "filtering" is "filter".
13
+ * The forms of a word that count as the same word (see someForm).
16
14
  * @param {string} w - Lowercase word.
17
15
  * @returns {Set<string>}
18
16
  */
@@ -24,6 +22,23 @@ export function wordForms(w: string): Set<string>;
24
22
  * @returns {boolean}
25
23
  */
26
24
  export function sameWord(a: string, b: string): boolean;
25
+ /**
26
+ * A search term's forms and the word starts it matches, worked out once for
27
+ * every word the term is compared with.
28
+ * @typedef {{term: string, forms: Set<string>, starts: string[]}} TermWords
29
+ */
30
+ /**
31
+ * @param {string} term - Lowercase term.
32
+ * @returns {TermWords}
33
+ */
34
+ export function termWords(term: string): TermWords;
35
+ /**
36
+ * Whether a lowercase word is the term's word, as sameWord answers.
37
+ * @param {TermWords} t
38
+ * @param {string} w
39
+ * @returns {boolean}
40
+ */
41
+ export function sameTermWord(t: TermWords, w: string): boolean;
27
42
  /**
28
43
  * The lowercase words of a name or keyword: split at non-alphanumerics and at
29
44
  * camelCase boundaries, so "TextInput" is ["text", "input"] and
@@ -41,6 +56,13 @@ export function wordsOf(text: string): string[];
41
56
  * @returns {boolean}
42
57
  */
43
58
  export function startsAWordOf(term: string, text: string): boolean;
59
+ /**
60
+ * startsAWordOf for a term whose words are already worked out.
61
+ * @param {TermWords} t
62
+ * @param {string} text - The name or keyword as authored.
63
+ * @returns {boolean}
64
+ */
65
+ export function startsATermWordOf(t: TermWords, text: string): boolean;
44
66
  /**
45
67
  * A query with its camelCase and PascalCase identifiers spelled as words, so
46
68
  * `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
@@ -68,3 +90,12 @@ export function joined(text: string): string;
68
90
  */
69
91
  export function typoDistance(a: string, b: string): 1 | 2 | 3 | null;
70
92
  export function isTypo(a: string, b: string, dist: number): boolean;
93
+ /**
94
+ * A search term's forms and the word starts it matches, worked out once for
95
+ * every word the term is compared with.
96
+ */
97
+ export type TermWords = {
98
+ term: string;
99
+ forms: Set<string>;
100
+ starts: string[];
101
+ };
@@ -26,27 +26,47 @@ export function stem(w) {
26
26
  }
27
27
 
28
28
  /**
29
- * The forms of a word that count as the same word: itself, its stem, and its
30
- * singular when it ends in a plural suffix — so "tables" is "table",
31
- * "statuses" is "status", and "filtering" is "filter".
29
+ * Visits the forms of a word that count as the same word, in order, until a
30
+ * visit returns true. The forms are the word, its stem, and its singular when
31
+ * it ends in a plural suffix. So "tables" is "table", "statuses" is "status",
32
+ * and "filtering" is "filter".
32
33
  * @param {string} w - Lowercase word.
33
- * @returns {Set<string>}
34
+ * @param {(form: string) => boolean} visit
35
+ * @returns {boolean} whether a visit returned true
34
36
  */
35
- export function wordForms(w) {
36
- const forms = new Set([w, stem(w)]);
37
- if (w.length > 3 && w.endsWith('s')) forms.add(w.slice(0, -1));
38
- if (w.length > 4 && w.endsWith('es')) forms.add(w.slice(0, -2));
39
- if (w.length > 4 && w.endsWith('ies')) forms.add(w.slice(0, -3) + 'y');
37
+ function someForm(w, visit) {
38
+ if (visit(w) || visit(stem(w))) return true;
39
+ if (w.length > 3 && w.endsWith('s') && visit(w.slice(0, -1))) return true;
40
+ if (w.length > 4 && w.endsWith('es') && visit(w.slice(0, -2))) return true;
41
+ if (w.length > 4 && w.endsWith('ies') && visit(w.slice(0, -3) + 'y')) {
42
+ return true;
43
+ }
40
44
  // A gerund keeps its verb: "spacing" lost a final e ("space"), and
41
45
  // "dragging" doubled a consonant ("drag"). A past participle does not: it
42
46
  // usually describes a state ("archived notes"), not the action a catalog
43
47
  // word names.
44
48
  if (w.length >= 6 && w.endsWith('ing')) {
45
49
  const base = w.slice(0, -3);
46
- forms.add(base);
47
- forms.add(`${base}e`);
48
- if (/([b-df-hj-np-tv-z])\1$/.test(base)) forms.add(base.slice(0, -1));
50
+ if (visit(base) || visit(`${base}e`)) return true;
51
+ if (/([b-df-hj-np-tv-z])\1$/.test(base) && visit(base.slice(0, -1))) {
52
+ return true;
53
+ }
49
54
  }
55
+ return false;
56
+ }
57
+
58
+ /**
59
+ * The forms of a word that count as the same word (see someForm).
60
+ * @param {string} w - Lowercase word.
61
+ * @returns {Set<string>}
62
+ */
63
+ export function wordForms(w) {
64
+ /** @type {Set<string>} */
65
+ const forms = new Set();
66
+ someForm(w, form => {
67
+ forms.add(form);
68
+ return false;
69
+ });
50
70
  return forms;
51
71
  }
52
72
 
@@ -74,8 +94,38 @@ function singulars(w) {
74
94
  export function sameWord(a, b) {
75
95
  if (a === b) return true;
76
96
  const forms = wordForms(a);
77
- for (const f of wordForms(b)) if (forms.has(f)) return true;
78
- return false;
97
+ return someForm(b, form => forms.has(form));
98
+ }
99
+
100
+ /**
101
+ * A search term's forms and the word starts it matches, worked out once for
102
+ * every word the term is compared with.
103
+ * @typedef {{term: string, forms: Set<string>, starts: string[]}} TermWords
104
+ */
105
+
106
+ /**
107
+ * @param {string} term - Lowercase term.
108
+ * @returns {TermWords}
109
+ */
110
+ export function termWords(term) {
111
+ return {
112
+ term,
113
+ forms: wordForms(term),
114
+ // The term or its singular may start the word: "tokens" starts
115
+ // "tokenizer" through "token". A singular needs five letters, so "stats"
116
+ // does not start "status".
117
+ starts: [term, ...singulars(term).filter(f => f.length >= 5)],
118
+ };
119
+ }
120
+
121
+ /**
122
+ * Whether a lowercase word is the term's word, as sameWord answers.
123
+ * @param {TermWords} t
124
+ * @param {string} w
125
+ * @returns {boolean}
126
+ */
127
+ export function sameTermWord(t, w) {
128
+ return w === t.term || someForm(w, form => t.forms.has(form));
79
129
  }
80
130
 
81
131
  /**
@@ -103,17 +153,33 @@ export function wordsOf(text) {
103
153
  * @returns {boolean}
104
154
  */
105
155
  export function startsAWordOf(term, text) {
106
- if (term.length < 4) return false;
107
- if (term.length / String(text).length < 0.5) return false;
108
- // The term or its singular may start the word: "tokens" starts
109
- // "tokenizer" through "token". A singular needs five letters, so "stats"
110
- // does not start "status".
111
- const starts = [term, ...singulars(term).filter(f => f.length >= 5)];
156
+ if (!coversHalf(term, text)) return false;
157
+ return startsATermWordOf(termWords(term), text);
158
+ }
159
+
160
+ /**
161
+ * startsAWordOf for a term whose words are already worked out.
162
+ * @param {TermWords} t
163
+ * @param {string} text - The name or keyword as authored.
164
+ * @returns {boolean}
165
+ */
166
+ export function startsATermWordOf(t, text) {
167
+ if (!coversHalf(t.term, text)) return false;
112
168
  return wordsOf(text).some(
113
- w => starts.some(f => w.startsWith(f)) || sameWord(term, w),
169
+ w => t.starts.some(f => w.startsWith(f)) || sameTermWord(t, w),
114
170
  );
115
171
  }
116
172
 
173
+ /**
174
+ * Whether a term is long enough to match inside `text`: four letters, and at
175
+ * least half of the text.
176
+ * @param {string} term
177
+ * @param {string} text
178
+ */
179
+ function coversHalf(term, text) {
180
+ return term.length >= 4 && term.length / String(text).length >= 0.5;
181
+ }
182
+
117
183
  /**
118
184
  * A query with its camelCase and PascalCase identifiers spelled as words, so
119
185
  * `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
@@ -25,8 +25,24 @@
25
25
  *
26
26
  * @param {string} content
27
27
  * @param {string} [ownerPackage]
28
+ * @param {(importPath: string) => boolean} [keep] Imports to leave relative:
29
+ * the modules the copy carries in the same layout (see `sharedModulesOf`).
28
30
  */
29
- export function rewriteImports(content: string, ownerPackage?: string): string;
31
+ export function rewriteImports(content: string, ownerPackage?: string, keep?: (importPath: string) => boolean): string;
32
+ /**
33
+ * The modules a copy carries beside the component, in the package's own
34
+ * layout under the output directory (`spec:AST-110` FR4): each private
35
+ * attribute owner module the component imports, and every unexported StyleX
36
+ * module such a carried module imports, transitively. The component's own
37
+ * imports of them, and theirs of each other, stay relative.
38
+ *
39
+ * @param {string} srcRoot the owner package's source root
40
+ * @param {string} componentDir
41
+ * @param {string[]} componentFiles files of the component that are copied
42
+ * @returns {Map<string, string>} module path (relative to srcRoot, no
43
+ * extension) -> its file path relative to srcRoot
44
+ */
45
+ export function sharedModulesOf(srcRoot: string, componentDir: string, componentFiles: string[]): Map<string, string>;
30
46
  /**
31
47
  * Copy one component's source into the consumer project for customization,
32
48
  * rewriting escaping relative imports to the owner package's subpaths.