@astryxdesign/cli 0.7.9-canary.ef3db95 → 0.7.9-canary.f384e62
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/api/component/__fixtures__/resolutions/modules.txt +1 -1
- package/api/search/_candidate-score.mjs +25 -23
- package/api/search/_words.d.mts +44 -7
- package/api/search/_words.mjs +113 -21
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +24 -1
- package/api/swizzle/copy/copy.mjs +9 -4
- package/api/theme/build/build.mjs +21 -1
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/tree/calendar-systems.doc.mjs +146 -0
- package/assets/docs/tree/calendars.doc.mjs +46 -0
- package/assets/docs/tree/i18n-calendars.doc.mjs +51 -0
- package/assets/docs/tree/internationalization.doc.mjs +3 -3
- package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +19 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +68 -0
- package/clients/cli/commands/ensure-core-built.mjs +399 -43
- package/foundation/config/project.mjs +27 -9
- package/foundation/discovery/component-discovery.mjs +56 -10
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/foundation/integrations/manifest-writer.d.mts +3 -4
- package/foundation/integrations/manifest-writer.mjs +5 -3
- package/foundation/text/levenshtein.d.mts +4 -1
- package/foundation/text/levenshtein.mjs +44 -1
- package/package.json +9 -9
- package/api/swizzle/_github.d.mts +0 -8
- package/api/swizzle/_github.mjs +0 -22
|
@@ -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/
|
|
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
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
* "cable" is not "table".
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
-
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
39
38
|
import {
|
|
40
39
|
stem,
|
|
41
|
-
wordForms,
|
|
42
40
|
sameWord,
|
|
43
|
-
|
|
41
|
+
sameTermWord,
|
|
42
|
+
startsATermWordOf,
|
|
43
|
+
termWords,
|
|
44
44
|
wordsOf,
|
|
45
45
|
joined,
|
|
46
|
-
|
|
46
|
+
typoDistance,
|
|
47
47
|
} from './_words.mjs';
|
|
48
48
|
import {pluralOf} from './_query.mjs';
|
|
49
49
|
|
|
@@ -79,14 +79,14 @@ function spellsOut(term, name, description) {
|
|
|
79
79
|
/**
|
|
80
80
|
* Whether a one-word term is a name's last word and every word before it is a
|
|
81
81
|
* single letter: Stack in VStack and HStack.
|
|
82
|
-
* @param {
|
|
82
|
+
* @param {import('./_words.mjs').TermWords} t
|
|
83
83
|
* @param {string} name
|
|
84
84
|
*/
|
|
85
|
-
function headOfLetters(
|
|
85
|
+
function headOfLetters(t, name) {
|
|
86
86
|
const parts = wordsOf(name);
|
|
87
87
|
return (
|
|
88
88
|
parts.length >= 2 &&
|
|
89
|
-
|
|
89
|
+
sameTermWord(t, parts[parts.length - 1]) &&
|
|
90
90
|
parts.slice(0, -1).every(p => p.length === 1)
|
|
91
91
|
);
|
|
92
92
|
}
|
|
@@ -97,14 +97,14 @@ const FAMILY_MEMBERS = 3;
|
|
|
97
97
|
/**
|
|
98
98
|
* A derived name's score for a term: 60 for the same word, 40 for a word the
|
|
99
99
|
* term starts, else 0.
|
|
100
|
-
* @param {
|
|
100
|
+
* @param {import('./_words.mjs').TermWords} t - The lowercased search term.
|
|
101
101
|
* @param {string} kw - The derived name as authored.
|
|
102
102
|
* @returns {number}
|
|
103
103
|
*/
|
|
104
|
-
function weakKeywordScore(
|
|
104
|
+
function weakKeywordScore(t, kw) {
|
|
105
105
|
const kwLower = String(kw).toLowerCase();
|
|
106
|
-
if (kwLower === term ||
|
|
107
|
-
return
|
|
106
|
+
if (kwLower === t.term || sameTermWord(t, kwLower)) return 60;
|
|
107
|
+
return startsATermWordOf(t, kw) ? 40 : 0;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
@@ -147,6 +147,8 @@ export function scoreCandidate(
|
|
|
147
147
|
_family,
|
|
148
148
|
_familyIndex,
|
|
149
149
|
} = candidate;
|
|
150
|
+
// The term's forms, worked out once for every word below.
|
|
151
|
+
const t = termWords(term);
|
|
150
152
|
let best = 0;
|
|
151
153
|
let reason = '';
|
|
152
154
|
/** @type {'partial' | 'keyword' | false} */
|
|
@@ -209,23 +211,23 @@ export function scoreCandidate(
|
|
|
209
211
|
// outranks the Token component for `tokens`.
|
|
210
212
|
consider(99, 'plural of the name');
|
|
211
213
|
} else {
|
|
212
|
-
if (
|
|
214
|
+
if (sameTermWord(t, nameLower)) consider(95, `name "${candidateName}"`);
|
|
213
215
|
// The term is a word of the name, or starts one: "input" in TextInput.
|
|
214
216
|
else if (
|
|
215
217
|
!part &&
|
|
216
218
|
domain !== 'doc' &&
|
|
217
219
|
domain !== 'theme' &&
|
|
218
|
-
headOfLetters(
|
|
220
|
+
headOfLetters(t, candidateName)
|
|
219
221
|
) {
|
|
220
222
|
// The whole query is the name's head word after single letters (Stack
|
|
221
223
|
// in VStack, HStack): a variant named by its head, as a keyword is.
|
|
222
224
|
consider(90, `name "${candidateName}" ends in "${term}"`);
|
|
223
|
-
} else if (
|
|
225
|
+
} else if (startsATermWordOf(t, candidateName)) {
|
|
224
226
|
consider(60, `name contains "${term}"`);
|
|
225
227
|
}
|
|
226
228
|
if (fuzzy) {
|
|
227
|
-
const dist =
|
|
228
|
-
if (
|
|
229
|
+
const dist = typoDistance(term, nameLower);
|
|
230
|
+
if (dist != null) {
|
|
229
231
|
consider(
|
|
230
232
|
dist === 1 ? 80 : dist === 2 ? 40 : 20,
|
|
231
233
|
`similar name (distance ${dist})`,
|
|
@@ -274,14 +276,14 @@ export function scoreCandidate(
|
|
|
274
276
|
consider(90, `keyword "${kw}"`, 'keyword');
|
|
275
277
|
continue;
|
|
276
278
|
}
|
|
277
|
-
if (
|
|
279
|
+
if (sameTermWord(t, kwLower)) {
|
|
278
280
|
consider(88, `keyword "${kw}"`);
|
|
279
281
|
continue;
|
|
280
282
|
}
|
|
281
|
-
if (
|
|
283
|
+
if (startsATermWordOf(t, kw)) consider(70, `keyword "${kw}"`);
|
|
282
284
|
if (fuzzy) {
|
|
283
|
-
const dist =
|
|
284
|
-
if (
|
|
285
|
+
const dist = typoDistance(term, kwLower);
|
|
286
|
+
if (dist != null && dist <= 2) {
|
|
285
287
|
consider(dist === 1 ? 70 : 30, `keyword "${kw}" (distance ${dist})`);
|
|
286
288
|
}
|
|
287
289
|
}
|
|
@@ -295,9 +297,9 @@ export function scoreCandidate(
|
|
|
295
297
|
// A bound skips the read when no name the page can yield matches the term,
|
|
296
298
|
// and then no weak keyword can match it either.
|
|
297
299
|
const bound = candidate.weakKeywordBound;
|
|
298
|
-
if (!bound || bound.some(kw => weakKeywordScore(
|
|
300
|
+
if (!bound || bound.some(kw => weakKeywordScore(t, kw) > 0)) {
|
|
299
301
|
for (const kw of candidate.weakKeywords ?? []) {
|
|
300
|
-
const score = weakKeywordScore(
|
|
302
|
+
const score = weakKeywordScore(t, kw);
|
|
301
303
|
if (score > 0) consider(score, `renders ${kw}`);
|
|
302
304
|
}
|
|
303
305
|
}
|
|
@@ -308,7 +310,7 @@ export function scoreCandidate(
|
|
|
308
310
|
if (term.length >= 3) {
|
|
309
311
|
// Any form of the term, with any common suffix: `spacing` finds
|
|
310
312
|
// "space" and "spaces", `tables` finds "table".
|
|
311
|
-
const roots = [...new Set([stem(term), ...
|
|
313
|
+
const roots = [...new Set([stem(term), ...t.forms])]
|
|
312
314
|
.filter(f => f.length >= 3)
|
|
313
315
|
.map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
314
316
|
const re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
|
package/api/search/_words.d.mts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* @file Word matching for search: stems and word forms, word starts,
|
|
6
|
-
* identifier spelling, joined names, and typo tolerance.
|
|
7
|
-
*/
|
|
8
4
|
/**
|
|
9
5
|
* Light stemmer: strips common English suffixes so "charts"/"charting" and
|
|
10
6
|
* "chart" share a root. Deliberately crude (no Porter) — good enough to bridge
|
|
@@ -14,9 +10,7 @@
|
|
|
14
10
|
*/
|
|
15
11
|
export function stem(w: string): string;
|
|
16
12
|
/**
|
|
17
|
-
* The forms of a word that count as the same word
|
|
18
|
-
* singular when it ends in a plural suffix — so "tables" is "table",
|
|
19
|
-
* "statuses" is "status", and "filtering" is "filter".
|
|
13
|
+
* The forms of a word that count as the same word (see someForm).
|
|
20
14
|
* @param {string} w - Lowercase word.
|
|
21
15
|
* @returns {Set<string>}
|
|
22
16
|
*/
|
|
@@ -28,6 +22,23 @@ export function wordForms(w: string): Set<string>;
|
|
|
28
22
|
* @returns {boolean}
|
|
29
23
|
*/
|
|
30
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;
|
|
31
42
|
/**
|
|
32
43
|
* The lowercase words of a name or keyword: split at non-alphanumerics and at
|
|
33
44
|
* camelCase boundaries, so "TextInput" is ["text", "input"] and
|
|
@@ -45,6 +56,13 @@ export function wordsOf(text: string): string[];
|
|
|
45
56
|
* @returns {boolean}
|
|
46
57
|
*/
|
|
47
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;
|
|
48
66
|
/**
|
|
49
67
|
* A query with its camelCase and PascalCase identifiers spelled as words, so
|
|
50
68
|
* `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
|
|
@@ -61,4 +79,23 @@ export function spellIdentifiers(query: string): string;
|
|
|
61
79
|
* @returns {string}
|
|
62
80
|
*/
|
|
63
81
|
export function joined(text: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* The edit distance between two words when it counts as a typo (isTypo), or
|
|
84
|
+
* null. The shorter word's length caps the distance that can count. A pair
|
|
85
|
+
* the cap rules out needs no distance table, and the others compute only the
|
|
86
|
+
* cells within the cap.
|
|
87
|
+
* @param {string} a
|
|
88
|
+
* @param {string} b
|
|
89
|
+
* @returns {1 | 2 | 3 | null}
|
|
90
|
+
*/
|
|
91
|
+
export function typoDistance(a: string, b: string): 1 | 2 | 3 | null;
|
|
64
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
|
+
};
|
package/api/search/_words.mjs
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* identifier spelling, joined names, and typo tolerance.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {levenshteinDistance} from '../../foundation/text/levenshtein.mjs';
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Light stemmer: strips common English suffixes so "charts"/"charting" and
|
|
10
12
|
* "chart" share a root. Deliberately crude (no Porter) — good enough to bridge
|
|
@@ -24,27 +26,47 @@ export function stem(w) {
|
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* "
|
|
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".
|
|
30
33
|
* @param {string} w - Lowercase word.
|
|
31
|
-
* @
|
|
34
|
+
* @param {(form: string) => boolean} visit
|
|
35
|
+
* @returns {boolean} whether a visit returned true
|
|
32
36
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (w.length > 3 && w.endsWith('s')
|
|
36
|
-
if (w.length > 4 && w.endsWith('es')
|
|
37
|
-
if (w.length > 4 && w.endsWith('ies')
|
|
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
|
+
}
|
|
38
44
|
// A gerund keeps its verb: "spacing" lost a final e ("space"), and
|
|
39
45
|
// "dragging" doubled a consonant ("drag"). A past participle does not: it
|
|
40
46
|
// usually describes a state ("archived notes"), not the action a catalog
|
|
41
47
|
// word names.
|
|
42
48
|
if (w.length >= 6 && w.endsWith('ing')) {
|
|
43
49
|
const base = w.slice(0, -3);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
}
|
|
47
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
|
+
});
|
|
48
70
|
return forms;
|
|
49
71
|
}
|
|
50
72
|
|
|
@@ -72,8 +94,38 @@ function singulars(w) {
|
|
|
72
94
|
export function sameWord(a, b) {
|
|
73
95
|
if (a === b) return true;
|
|
74
96
|
const forms = wordForms(a);
|
|
75
|
-
|
|
76
|
-
|
|
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));
|
|
77
129
|
}
|
|
78
130
|
|
|
79
131
|
/**
|
|
@@ -101,17 +153,33 @@ export function wordsOf(text) {
|
|
|
101
153
|
* @returns {boolean}
|
|
102
154
|
*/
|
|
103
155
|
export function startsAWordOf(term, text) {
|
|
104
|
-
if (term
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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;
|
|
110
168
|
return wordsOf(text).some(
|
|
111
|
-
w => starts.some(f => w.startsWith(f)) ||
|
|
169
|
+
w => t.starts.some(f => w.startsWith(f)) || sameTermWord(t, w),
|
|
112
170
|
);
|
|
113
171
|
}
|
|
114
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
|
+
|
|
115
183
|
/**
|
|
116
184
|
* A query with its camelCase and PascalCase identifiers spelled as words, so
|
|
117
185
|
* `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
|
|
@@ -155,3 +223,27 @@ export const isTypo = (a, b, dist) =>
|
|
|
155
223
|
dist <= 3 &&
|
|
156
224
|
Math.min(a.length, b.length) >=
|
|
157
225
|
TYPO_MIN_LENGTH[/** @type {1 | 2 | 3} */ (dist)];
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The edit distance between two words when it counts as a typo (isTypo), or
|
|
229
|
+
* null. The shorter word's length caps the distance that can count. A pair
|
|
230
|
+
* the cap rules out needs no distance table, and the others compute only the
|
|
231
|
+
* cells within the cap.
|
|
232
|
+
* @param {string} a
|
|
233
|
+
* @param {string} b
|
|
234
|
+
* @returns {1 | 2 | 3 | null}
|
|
235
|
+
*/
|
|
236
|
+
export function typoDistance(a, b) {
|
|
237
|
+
const shorter = Math.min(a.length, b.length);
|
|
238
|
+
const cap =
|
|
239
|
+
shorter >= TYPO_MIN_LENGTH[3]
|
|
240
|
+
? 3
|
|
241
|
+
: shorter >= TYPO_MIN_LENGTH[2]
|
|
242
|
+
? 2
|
|
243
|
+
: shorter >= TYPO_MIN_LENGTH[1]
|
|
244
|
+
? 1
|
|
245
|
+
: 0;
|
|
246
|
+
if (cap === 0) return null;
|
|
247
|
+
const dist = levenshteinDistance(a, b, cap);
|
|
248
|
+
return dist >= 1 && dist <= cap ? /** @type {1 | 2 | 3} */ (dist) : null;
|
|
249
|
+
}
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Whether an executable `gh` is on `PATH` (with a `PATHEXT` extension on
|
|
6
|
+
* Windows), found without running it. The copy receipt offers its
|
|
7
|
+
* `gh issue create` line on it. Running `gh` would make every copy wait on a
|
|
8
|
+
* process start, and for `gh auth status` on GitHub, before it reports.
|
|
9
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
10
|
+
* @param {NodeJS.Platform} [platform]
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
export function checkGhCli(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
|
|
4
14
|
/**
|
|
5
15
|
* The integration component that replaces the Core component `name`
|
|
6
16
|
* (spec:AST-035 FR11), or undefined when none does.
|
package/api/swizzle/_adapter.mjs
CHANGED
|
@@ -8,14 +8,37 @@
|
|
|
8
8
|
* of swizzlable components: `list` returns the names directly, `copy` uses them
|
|
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
|
-
* (ERR_CORE_NOT_FOUND) when core can't be located.
|
|
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
13
|
*/
|
|
13
14
|
|
|
15
|
+
import {executablesOnSearchPath} from '../../foundation/env/search-path.mjs';
|
|
14
16
|
import {findProjectCoreDir, listComponents} from '../../foundation/fs/paths.mjs';
|
|
15
17
|
import {resolveComponentReplacements} from '../../foundation/discovery/component-replacement.mjs';
|
|
16
18
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
17
19
|
import {AstryxError} from '../error.mjs';
|
|
18
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Whether an executable `gh` is on `PATH` (with a `PATHEXT` extension on
|
|
23
|
+
* Windows), found without running it. The copy receipt offers its
|
|
24
|
+
* `gh issue create` line on it. Running `gh` would make every copy wait on a
|
|
25
|
+
* process start, and for `gh auth status` on GitHub, before it reports.
|
|
26
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
27
|
+
* @param {NodeJS.Platform} [platform]
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
export function checkGhCli(env = process.env, platform = process.platform) {
|
|
31
|
+
const names =
|
|
32
|
+
platform === 'win32'
|
|
33
|
+
? (env.PATHEXT ?? '.COM;.EXE;.BAT;.CMD')
|
|
34
|
+
.split(';')
|
|
35
|
+
.filter(Boolean)
|
|
36
|
+
.map(extension => `gh${extension.toLowerCase()}`)
|
|
37
|
+
: ['gh'];
|
|
38
|
+
const searchPath = env.PATH ?? env.Path ?? '';
|
|
39
|
+
return executablesOnSearchPath(names, {searchPath, platform}).length > 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
19
42
|
/** The package that owns Core's components, hooks, and codemods. */
|
|
20
43
|
export {CORE_PROVIDER_ID as CORE_PACKAGE} from '../../foundation/identity/providers.mjs';
|
|
21
44
|
|
|
@@ -15,9 +15,12 @@
|
|
|
15
15
|
|
|
16
16
|
import * as fs from 'node:fs';
|
|
17
17
|
import * as path from 'node:path';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
checkGhCli,
|
|
20
|
+
resolveComponentReplacement,
|
|
21
|
+
resolveCore,
|
|
22
|
+
} from '../_adapter.mjs';
|
|
19
23
|
import {assertWithin, sanitizeName, PathSafetyError} from '../../../foundation/fs/path-safety.mjs';
|
|
20
|
-
import {checkGhCli} from '../_github.mjs';
|
|
21
24
|
import {Project} from '../../../foundation/config/project.mjs';
|
|
22
25
|
import {
|
|
23
26
|
CORE_PACKAGE,
|
|
@@ -299,6 +302,10 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
299
302
|
const outputBase = confineWrite(output, cwd, {label: 'output directory'});
|
|
300
303
|
const outputDir = path.join(outputBase, dirName);
|
|
301
304
|
|
|
305
|
+
// The receipt's feedback first: a swizzle that fails must fail before it
|
|
306
|
+
// writes anything.
|
|
307
|
+
const feedback = buildFeedback(dirName, owner.issuesUrl);
|
|
308
|
+
|
|
302
309
|
// Pre-flight path and overwrite checks before any mkdir/writeFile.
|
|
303
310
|
const sourceFiles = fs.readdirSync(componentDir).filter(file => {
|
|
304
311
|
if (isExcludedFromCopy(file)) return false;
|
|
@@ -380,8 +387,6 @@ export async function swizzleCopy(component, options = {}) {
|
|
|
380
387
|
!isExcludedFromCopy(f) &&
|
|
381
388
|
fs.statSync(path.join(componentDir, f)).isFile(),
|
|
382
389
|
);
|
|
383
|
-
const feedback = buildFeedback(dirName, owner.issuesUrl);
|
|
384
|
-
|
|
385
390
|
/** @type {import('../swizzle.type.mjs').SwizzleCopyResponse['data']} */
|
|
386
391
|
const data = {
|
|
387
392
|
component: dirName,
|
|
@@ -2844,12 +2844,29 @@ async function themeBuildInternal(
|
|
|
2844
2844
|
let themeExportName;
|
|
2845
2845
|
/** Paths through the load that interception could not fully observe. */
|
|
2846
2846
|
let loadDegradation;
|
|
2847
|
+
/**
|
|
2848
|
+
* The theme file's bytes as loaded: read before and after the load, and the
|
|
2849
|
+
* registry scan below reads these rather than the file again. An editor's
|
|
2850
|
+
* in-place save truncates before it writes, so a later read can find an
|
|
2851
|
+
* empty file the load never saw; a file that changed while it loaded is not
|
|
2852
|
+
* built from.
|
|
2853
|
+
* @type {string}
|
|
2854
|
+
*/
|
|
2855
|
+
let themeSource;
|
|
2847
2856
|
try {
|
|
2857
|
+
const before = fs.readFileSync(filePath, 'utf8');
|
|
2848
2858
|
const loaded = await extractThemeDefinition(
|
|
2849
2859
|
filePath,
|
|
2850
2860
|
interception,
|
|
2851
2861
|
options.__familyLoader,
|
|
2852
2862
|
);
|
|
2863
|
+
const after = fs.readFileSync(filePath, 'utf8');
|
|
2864
|
+
if (before !== after || before === '') {
|
|
2865
|
+
throw new Error(
|
|
2866
|
+
`${filePath} changed while it was loading. Build again once it is saved.`,
|
|
2867
|
+
);
|
|
2868
|
+
}
|
|
2869
|
+
themeSource = before;
|
|
2853
2870
|
themeDef = loaded.theme;
|
|
2854
2871
|
themeExportName = loaded.exportName;
|
|
2855
2872
|
loadDegradation = loaded.degraded;
|
|
@@ -2939,7 +2956,10 @@ async function themeBuildInternal(
|
|
|
2939
2956
|
: []),
|
|
2940
2957
|
];
|
|
2941
2958
|
const iconResolution = {
|
|
2942
|
-
readSource: (/** @type {string} */ file) =>
|
|
2959
|
+
readSource: (/** @type {string} */ file) =>
|
|
2960
|
+
path.resolve(file) === path.resolve(filePath)
|
|
2961
|
+
? themeSource
|
|
2962
|
+
: fs.readFileSync(file, 'utf8'),
|
|
2943
2963
|
resolveModule: resolveThemeModule,
|
|
2944
2964
|
reservedNames: reservedNames(functionEntries),
|
|
2945
2965
|
functionEntries,
|