@astryxdesign/cli 0.7.2-canary.4932317 → 0.7.2-canary.4a2f608
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 +62 -62
- package/api/discover/_adapter.d.mts +119 -12
- package/api/discover/_adapter.mjs +449 -10
- package/api/discover/_adapter.test.mjs +599 -17
- package/api/discover/_catalog-view.d.mts +16 -5
- package/api/discover/_catalog-view.mjs +32 -8
- package/api/discover/discover.d.mts +11 -0
- package/api/discover/discover.doc.mjs +7 -6
- package/api/discover/discover.mjs +107 -19
- package/api/discover/discover.type.d.mts +18 -7
- package/api/discover/discover.type.mjs +15 -7
- package/api/discover/list/list.d.mts +4 -3
- package/api/discover/list/list.mjs +17 -10
- package/api/doctor/theme-checks.test.mjs +136 -0
- package/api/gap-report/gap-report.d.mts +3 -0
- package/api/gap-report/gap-report.doc.mjs +11 -3
- package/api/gap-report/gap-report.mjs +152 -48
- package/api/gap-report/gap-report.test.mjs +233 -0
- package/api/gap-report/gap-report.type.d.mts +41 -0
- package/api/gap-report/gap-report.type.mjs +18 -0
- package/api/integration/_adapter.d.mts +20 -0
- package/api/integration/_adapter.mjs +26 -0
- package/api/integration/authoring-checks.mjs +34 -3
- package/api/integration/authoring-checks.test.mjs +476 -0
- package/api/integration/authoring-checks.type.d.mts +86 -0
- package/api/integration/authoring-checks.type.mjs +39 -1
- package/api/integration/integrationComponentConflicts.doc.mjs +9 -3
- package/api/integration/integrationDocConflicts.doc.mjs +19 -5
- package/api/integration/pack-check.mjs +292 -7
- package/api/integration/pack-check.test.mjs +341 -0
- package/api/integration/validateIntegration.doc.mjs +3 -1
- package/api/search/search.d.mts +9 -7
- package/api/search/search.mjs +90 -42
- package/api/search/search.test.mjs +11 -0
- package/api/upgrade/_adapter.d.mts +40 -2
- package/api/upgrade/_adapter.mjs +117 -4
- package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
- package/api/upgrade/run/run.mjs +30 -1
- package/api/upgrade/status/status.d.mts +21 -5
- package/api/upgrade/status/status.mjs +45 -8
- package/api/upgrade/upgrade.doc.mjs +5 -3
- package/api/upgrade/upgrade.type.d.mts +23 -0
- package/api/upgrade/upgrade.type.mjs +16 -1
- package/assets/codemods/runner.mjs +7 -1
- package/assets/discover/official-packages.json +367 -0
- package/assets/docs/author-a-theme.doc.mjs +2 -2
- package/assets/docs/browser-support.doc.mjs +1 -1
- package/assets/docs/styling-overview.doc.mjs +1 -1
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/check-the-props.doc.mjs +2 -2
- package/assets/docs/tree/check-your-docs.doc.mjs +11 -3
- package/assets/docs/tree/checks.doc.mjs +4 -4
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +25 -5
- package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
- package/assets/docs/tree/layout.doc.mjs +6 -6
- package/assets/docs/tree/migration-setup.doc.mjs +2 -2
- package/assets/docs/tree/publishing.doc.mjs +3 -3
- package/assets/docs/tree/quick-start.doc.mjs +3 -3
- package/assets/docs/tree/sections-and-placement.doc.mjs +2 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +5 -5
- package/assets/docs/tree/upgrading.doc.mjs +1 -1
- package/authoring/discover/discover.doc.mjs +1 -1
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
- package/clients/cli/commands/discover.doc.mjs +1 -1
- package/clients/cli/commands/discover.mjs +144 -93
- package/clients/cli/commands/discover.no-source.test.mjs +447 -33
- package/clients/cli/commands/discover.sources.test.mjs +20 -1
- package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -1
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +18 -5
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +60 -3
- package/clients/cli/commands/gap-report.doc.mjs +14 -2
- package/clients/cli/commands/gap-report.mjs +24 -2
- package/clients/cli/commands/gap-report.test.mjs +79 -0
- package/clients/cli/commands/integration-check.test.mjs +103 -0
- package/clients/cli/commands/integration.mjs +2 -3
- package/clients/cli/commands/json-contract.test.mjs +5 -1
- package/clients/cli/commands/upgrade.doc.mjs +14 -0
- package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
- package/foundation/discovery/copied-passages.d.mts +216 -0
- package/foundation/discovery/copied-passages.mjs +720 -0
- package/foundation/discovery/copied-passages.test.mjs +124 -0
- package/foundation/discovery/doc-fluff.d.mts +112 -0
- package/foundation/discovery/doc-fluff.mjs +328 -0
- package/foundation/discovery/doc-fluff.test.mjs +142 -0
- package/foundation/discovery/doc-types.d.mts +1 -1
- package/foundation/discovery/doc-types.mjs +3 -3
- package/foundation/discovery/doc-types.test.mjs +48 -0
- package/foundation/discovery/docs-discovery.d.mts +7 -0
- package/foundation/discovery/docs-discovery.mjs +26 -2
- package/foundation/discovery/project-typescript.d.mts +11 -2
- package/foundation/discovery/project-typescript.mjs +32 -4
- package/foundation/discovery/prop-drift.d.mts +1 -1
- package/foundation/discovery/prop-drift.mjs +2 -2
- package/foundation/discovery/prop-drift.test.mjs +55 -2
- package/foundation/discovery/type-text.mjs +1 -1
- package/foundation/discovery/type-text.test.mjs +1 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +14 -2
- package/foundation/env/package-manager.d.mts +32 -0
- package/foundation/env/package-manager.mjs +47 -0
- package/foundation/env/package-manager.test.mjs +194 -7
- package/foundation/fs/module-loader.d.mts +2 -1
- package/foundation/fs/module-loader.mjs +60 -4
- package/foundation/fs/module-loader.test.mjs +194 -0
- package/foundation/response/response-types.doc.mjs +7 -6
- package/package.json +11 -11
package/api/search/search.mjs
CHANGED
|
@@ -385,7 +385,7 @@ function joined(text) {
|
|
|
385
385
|
* A doc's name is a route or key, so docs are left out.
|
|
386
386
|
* @param {string[]} words - The query's words, stopwords included.
|
|
387
387
|
* @param {Candidate} candidate
|
|
388
|
-
* @returns {{score: number, reason: string, covered: Set<string>, alias?:
|
|
388
|
+
* @returns {{score: number, reason: string, covered: Set<string>, alias?: 'partial' | 'keyword', aliasWords?: number} | null}
|
|
389
389
|
* `covered` holds the run's words and every stretch of them joined. `alias`
|
|
390
390
|
* marks a hit on part of a name or on a keyword, not on the whole name.
|
|
391
391
|
*/
|
|
@@ -406,18 +406,21 @@ export function compoundHit(words, candidate) {
|
|
|
406
406
|
const keywords = (candidate.keywords ?? []).filter(k =>
|
|
407
407
|
/^[a-z0-9]+$/.test(String(k)),
|
|
408
408
|
);
|
|
409
|
-
/** @type {{score: number, reason: string, covered: Set<string>, alias?:
|
|
409
|
+
/** @type {{score: number, reason: string, covered: Set<string>, alias?: 'partial' | 'keyword', aliasWords?: number} | null} */
|
|
410
410
|
let best = null;
|
|
411
411
|
for (const {run, word} of queryRuns(words)) {
|
|
412
412
|
let score = 0;
|
|
413
413
|
let reason = '';
|
|
414
|
+
/** @type {'partial' | 'keyword' | null} */
|
|
415
|
+
let kind = null;
|
|
414
416
|
for (const {name, nameJoined, nameWords} of names) {
|
|
415
417
|
if (
|
|
416
418
|
nameJoined === word ||
|
|
417
419
|
pluralOf(word, nameJoined) ||
|
|
418
420
|
(candidate.domain === 'hook' && nameJoined === `use${word}`)
|
|
419
421
|
) {
|
|
420
|
-
if (score < 100)
|
|
422
|
+
if (score < 100)
|
|
423
|
+
[score, reason, kind] = [100, `name ${name} spelled`, null];
|
|
421
424
|
} else if (!partial) {
|
|
422
425
|
continue;
|
|
423
426
|
} else if (
|
|
@@ -426,7 +429,8 @@ export function compoundHit(words, candidate) {
|
|
|
426
429
|
) {
|
|
427
430
|
// Most of the name, cut short: `dropdown menu radio` is
|
|
428
431
|
// DropdownMenuRadioItem.
|
|
429
|
-
if (score < 95)
|
|
432
|
+
if (score < 95)
|
|
433
|
+
[score, reason, kind] = [95, `name ${name} spelled`, 'partial'];
|
|
430
434
|
} else if (
|
|
431
435
|
word.length / nameJoined.length >= 0.5 &&
|
|
432
436
|
run.every(
|
|
@@ -435,17 +439,29 @@ export function compoundHit(words, candidate) {
|
|
|
435
439
|
) {
|
|
436
440
|
// The name's leading words: `top nav mega` is TopNavMegaMenu.
|
|
437
441
|
if (score < 92)
|
|
438
|
-
[score, reason] = [
|
|
442
|
+
[score, reason, kind] = [
|
|
443
|
+
92,
|
|
444
|
+
`name ${name} starts "${run.join(' ')}"`,
|
|
445
|
+
'partial',
|
|
446
|
+
];
|
|
439
447
|
} else if (
|
|
440
448
|
word.length / nameJoined.length >= 0.5 &&
|
|
441
449
|
nameWords.some((_, k) => run.every((w, j) => nameWords[k + j] === w))
|
|
442
450
|
) {
|
|
443
451
|
if (score < 70)
|
|
444
|
-
[score, reason] = [
|
|
452
|
+
[score, reason, kind] = [
|
|
453
|
+
70,
|
|
454
|
+
`name ${name} holds "${run.join(' ')}"`,
|
|
455
|
+
'partial',
|
|
456
|
+
];
|
|
445
457
|
}
|
|
446
458
|
}
|
|
447
459
|
if (score < 90 && keywords.includes(word)) {
|
|
448
|
-
[score, reason] = [
|
|
460
|
+
[score, reason, kind] = [
|
|
461
|
+
90,
|
|
462
|
+
`keyword "${run.join(' ')}" spelled`,
|
|
463
|
+
'keyword',
|
|
464
|
+
];
|
|
449
465
|
}
|
|
450
466
|
if (score > (best?.score ?? 0)) {
|
|
451
467
|
// Each word of the run, and each identifier typed as several of its
|
|
@@ -456,7 +472,12 @@ export function compoundHit(words, candidate) {
|
|
|
456
472
|
covered.add(run.slice(a, b).join(''));
|
|
457
473
|
}
|
|
458
474
|
}
|
|
459
|
-
best = {
|
|
475
|
+
best = {
|
|
476
|
+
score,
|
|
477
|
+
reason,
|
|
478
|
+
covered,
|
|
479
|
+
...(kind ? {alias: kind, aliasWords: run.length} : {}),
|
|
480
|
+
};
|
|
460
481
|
}
|
|
461
482
|
}
|
|
462
483
|
return best;
|
|
@@ -927,7 +948,7 @@ export function titleInQuery(term, titles) {
|
|
|
927
948
|
* compoundHit); empty when the query names an entry outright.
|
|
928
949
|
* @param {{plain?: boolean}} [opts] - `plain`: score without matches on part
|
|
929
950
|
* of a name or a joined keyword.
|
|
930
|
-
* @returns {{score: number, reason: string, matched: number, total: number, alias?:
|
|
951
|
+
* @returns {{score: number, reason: string, matched: number, total: number, alias?: 'partial' | 'keyword', aliasWords?: number} | null}
|
|
931
952
|
* `matched`/`total` are the query concepts this candidate answered, out of
|
|
932
953
|
* the concepts the query had. Callers that must distinguish "matched one word
|
|
933
954
|
* of three" from "matched all three" — `build`, which gates its pages group
|
|
@@ -994,7 +1015,7 @@ export function scoreQuery(
|
|
|
994
1015
|
return asFull({
|
|
995
1016
|
score: full.score + 100,
|
|
996
1017
|
reason: full.reason,
|
|
997
|
-
...(full.alias ? {alias:
|
|
1018
|
+
...(full.alias ? {alias: full.alias, aliasWords: words.length} : {}),
|
|
998
1019
|
});
|
|
999
1020
|
}
|
|
1000
1021
|
|
|
@@ -1025,7 +1046,9 @@ export function scoreQuery(
|
|
|
1025
1046
|
// join, as strongly as the joined word matches (see compoundHit).
|
|
1026
1047
|
// Whether a counted word matched only through part of a name or a keyword
|
|
1027
1048
|
// read joined, not through the entry's own name or a word of it.
|
|
1049
|
+
/** @type {'partial' | 'keyword' | false} */
|
|
1028
1050
|
let alias = false;
|
|
1051
|
+
let aliasWords = 0;
|
|
1029
1052
|
for (const tok of tokens) {
|
|
1030
1053
|
let h = bestForToken(tok, candidate, {fuzzy});
|
|
1031
1054
|
if (
|
|
@@ -1033,7 +1056,10 @@ export function scoreQuery(
|
|
|
1033
1056
|
compound.score > (h?.score ?? 0)
|
|
1034
1057
|
) {
|
|
1035
1058
|
h = compound;
|
|
1036
|
-
if (compound.alias && compound.score >= MIN_TOKEN_SCORE)
|
|
1059
|
+
if (compound.alias && compound.score >= MIN_TOKEN_SCORE) {
|
|
1060
|
+
alias = alias === 'partial' ? alias : compound.alias;
|
|
1061
|
+
aliasWords = compound.aliasWords ?? 0;
|
|
1062
|
+
}
|
|
1037
1063
|
}
|
|
1038
1064
|
if (h && h.score >= MIN_TOKEN_SCORE) {
|
|
1039
1065
|
if (h.score > strongest) strongest = h.score;
|
|
@@ -1084,7 +1110,7 @@ export function scoreQuery(
|
|
|
1084
1110
|
reason,
|
|
1085
1111
|
matched,
|
|
1086
1112
|
total,
|
|
1087
|
-
...(alias ? {alias} : {}),
|
|
1113
|
+
...(alias ? {alias, aliasWords} : {}),
|
|
1088
1114
|
};
|
|
1089
1115
|
}
|
|
1090
1116
|
|
|
@@ -1110,7 +1136,13 @@ export function scoreQuery(
|
|
|
1110
1136
|
strongest + Math.min(matched - 1, 3) * 12 + coverage * 15,
|
|
1111
1137
|
);
|
|
1112
1138
|
if (full && full.score >= tokenScore) return asFull(full);
|
|
1113
|
-
return {
|
|
1139
|
+
return {
|
|
1140
|
+
score: tokenScore,
|
|
1141
|
+
reason,
|
|
1142
|
+
matched,
|
|
1143
|
+
total,
|
|
1144
|
+
...(alias ? {alias, aliasWords} : {}),
|
|
1145
|
+
};
|
|
1114
1146
|
}
|
|
1115
1147
|
|
|
1116
1148
|
/**
|
|
@@ -1130,8 +1162,8 @@ export function scoreQuery(
|
|
|
1130
1162
|
* @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
|
|
1131
1163
|
* @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
|
|
1132
1164
|
* @param {{fuzzy?: boolean, joins?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright.
|
|
1133
|
-
* @returns {{score: number, reason: string, alias?:
|
|
1134
|
-
* marks a hit that read the query's words joined.
|
|
1165
|
+
* @returns {{score: number, reason: string, alias?: 'partial' | 'keyword'} | null}
|
|
1166
|
+
* `alias` marks a hit that read the query's words joined.
|
|
1135
1167
|
*/
|
|
1136
1168
|
export function scoreCandidate(
|
|
1137
1169
|
term,
|
|
@@ -1149,11 +1181,13 @@ export function scoreCandidate(
|
|
|
1149
1181
|
) {
|
|
1150
1182
|
let best = 0;
|
|
1151
1183
|
let reason = '';
|
|
1184
|
+
/** @type {'partial' | 'keyword' | false} */
|
|
1152
1185
|
let alias = false;
|
|
1153
1186
|
/**
|
|
1154
1187
|
* @param {number} score
|
|
1155
1188
|
* @param {string} why
|
|
1156
|
-
* @param {
|
|
1189
|
+
* @param {'partial' | 'keyword' | false} [byAlias] - the hit reads the
|
|
1190
|
+
* query's words joined, into part of a name or into a keyword
|
|
1157
1191
|
*/
|
|
1158
1192
|
const consider = (score, why, byAlias = false) => {
|
|
1159
1193
|
if (score > best) {
|
|
@@ -1192,7 +1226,7 @@ export function scoreCandidate(
|
|
|
1192
1226
|
) {
|
|
1193
1227
|
// Most of the name typed as words, cut short: `complex select` is
|
|
1194
1228
|
// ComplexSelector, ahead of a one-word keyword elsewhere.
|
|
1195
|
-
consider(95, `name "${candidateName}" spelled`,
|
|
1229
|
+
consider(95, `name "${candidateName}" spelled`, 'partial');
|
|
1196
1230
|
} else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
|
|
1197
1231
|
// One point under the exact spelling, so the doc named `tokens` still
|
|
1198
1232
|
// outranks the Token component for `tokens`.
|
|
@@ -1234,7 +1268,7 @@ export function scoreCandidate(
|
|
|
1234
1268
|
/\s/.test(term) &&
|
|
1235
1269
|
String(kw) === termJoined
|
|
1236
1270
|
) {
|
|
1237
|
-
consider(90, `keyword "${kw}"`,
|
|
1271
|
+
consider(90, `keyword "${kw}"`, 'keyword');
|
|
1238
1272
|
continue;
|
|
1239
1273
|
}
|
|
1240
1274
|
if (sameWord(term, kwLower)) {
|
|
@@ -1269,7 +1303,7 @@ export function scoreCandidate(
|
|
|
1269
1303
|
// so "chart" matches "charts" and "filter" matches "filtering".
|
|
1270
1304
|
if (term.length >= 3) {
|
|
1271
1305
|
// Any form of the term, with any common suffix: `spacing` finds
|
|
1272
|
-
// "space" and "spaces", `
|
|
1306
|
+
// "space" and "spaces", `tables` finds "table".
|
|
1273
1307
|
const roots = [...new Set([stem(term), ...wordForms(term)])]
|
|
1274
1308
|
.filter(f => f.length >= 3)
|
|
1275
1309
|
.map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
@@ -2288,18 +2322,21 @@ async function searchOnce(query, options) {
|
|
|
2288
2322
|
if (!spans.has(run)) spans.set(run, [a, a + len]);
|
|
2289
2323
|
}
|
|
2290
2324
|
}
|
|
2291
|
-
const plainWords = new Set(queryWords);
|
|
2292
2325
|
/**
|
|
2293
|
-
*
|
|
2294
|
-
* the rank its name earns, whatever else it matched.
|
|
2326
|
+
* Where a query word is the candidate's whole name, or null: such an entry
|
|
2327
|
+
* keeps the rank its name earns, whatever else it matched.
|
|
2295
2328
|
* @param {Candidate} candidate
|
|
2329
|
+
* @returns {[number, number] | null}
|
|
2296
2330
|
*/
|
|
2297
|
-
const wordNamed = candidate =>
|
|
2298
|
-
candidate.domain
|
|
2299
|
-
[candidate.name, ...(candidate.aliases ?? [])]
|
|
2331
|
+
const wordNamed = candidate => {
|
|
2332
|
+
if (candidate.domain === 'doc') return null;
|
|
2333
|
+
for (const name of [candidate.name, ...(candidate.aliases ?? [])]) {
|
|
2300
2334
|
const n = joined(name);
|
|
2301
|
-
|
|
2302
|
-
|
|
2335
|
+
const at = queryWords.findIndex(w => w === n || w === `${n}s`);
|
|
2336
|
+
if (at >= 0) return [at, at + 1];
|
|
2337
|
+
}
|
|
2338
|
+
return null;
|
|
2339
|
+
};
|
|
2303
2340
|
/** @param {Candidate} candidate @returns {[number, number] | null} */
|
|
2304
2341
|
const namedSpan = candidate => {
|
|
2305
2342
|
if (candidate.domain === 'doc') return null;
|
|
@@ -2322,7 +2359,7 @@ async function searchOnce(query, options) {
|
|
|
2322
2359
|
// role (page / block / component) and takes the top of each, so there's no
|
|
2323
2360
|
// cross-role competition to engineer — a target page only needs to be the
|
|
2324
2361
|
// strongest PAGE, not outrank every component.
|
|
2325
|
-
/** @type {{result: any, priority: 0 | 1 | 2, key: number, alias:
|
|
2362
|
+
/** @type {{result: any, priority: 0 | 1 | 2, key: number, alias: 'partial' | 'keyword' | false, aliasWords: number, candidate: Candidate, span: [number, number] | null, word: [number, number] | null}[]} */
|
|
2326
2363
|
const ranked = [];
|
|
2327
2364
|
for (const candidate of all) {
|
|
2328
2365
|
const hit = scoreQuery(term, tokens, candidate, words);
|
|
@@ -2337,14 +2374,16 @@ async function searchOnce(query, options) {
|
|
|
2337
2374
|
),
|
|
2338
2375
|
priority: domainPriority(term, tokens, candidate, hit, words),
|
|
2339
2376
|
key: hit.score,
|
|
2340
|
-
alias: hit.alias
|
|
2377
|
+
alias: hit.alias ?? false,
|
|
2378
|
+
aliasWords: hit.aliasWords ?? 0,
|
|
2341
2379
|
candidate,
|
|
2342
2380
|
span: namedSpan(candidate),
|
|
2343
2381
|
word: wordNamed(candidate),
|
|
2344
2382
|
});
|
|
2345
2383
|
}
|
|
2346
|
-
// A match
|
|
2347
|
-
//
|
|
2384
|
+
// A match on a keyword read joined never outranks an entry the query names,
|
|
2385
|
+
// and neither does a match on part of another name unless it spans more
|
|
2386
|
+
// query words than any named run: `table header with sticky columns` keeps
|
|
2348
2387
|
// TableHeader above useTableStickyColumns, which only holds the words
|
|
2349
2388
|
// `sticky columns`. Only the order changes; each result keeps the score its
|
|
2350
2389
|
// text earned.
|
|
@@ -2360,17 +2399,26 @@ async function searchOnce(query, options) {
|
|
|
2360
2399
|
!ranked.some(o => o !== r && o.span != null && inside(span, o.span))
|
|
2361
2400
|
);
|
|
2362
2401
|
});
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2402
|
+
/** @param {{key: number}[]} rows */
|
|
2403
|
+
const floorOf = rows =>
|
|
2404
|
+
rows.length ? Math.min(...rows.map(r => r.key)) : Infinity;
|
|
2405
|
+
const namedFloor = floorOf(named);
|
|
2406
|
+
const longestNamed = Math.max(
|
|
2407
|
+
0,
|
|
2408
|
+
...named.map(r => (r.span ? r.span[1] - r.span[0] : 0)),
|
|
2409
|
+
);
|
|
2410
|
+
for (const r of ranked) {
|
|
2411
|
+
if (named.includes(r)) continue;
|
|
2412
|
+
if (!r.alias || r.word) continue;
|
|
2413
|
+
// A match on part of a longer name that spans more words than any named
|
|
2414
|
+
// run reads more of the query than the named entry does (`dropdown menu
|
|
2415
|
+
// radio` and DropdownMenuRadioItem, against DropdownMenu), so it is not
|
|
2416
|
+
// held back. A joined keyword always is.
|
|
2417
|
+
if (r.alias === 'partial' && r.aliasWords > longestNamed) continue;
|
|
2418
|
+
// It keeps what it earns without those matches.
|
|
2419
|
+
const own =
|
|
2420
|
+
scoreQuery(term, tokens, r.candidate, words, {plain: true})?.score ?? 0;
|
|
2421
|
+
r.key = Math.max(own, Math.min(r.key, namedFloor - 0.5));
|
|
2374
2422
|
}
|
|
2375
2423
|
|
|
2376
2424
|
// Docs and everything else are each sorted by score desc, then domain
|
|
@@ -956,6 +956,17 @@ describe('search leaf — compound names, other names, and word forms', () => {
|
|
|
956
956
|
expect(data.results[0]).toMatchObject({name: 'TextArea'});
|
|
957
957
|
}, SLOW);
|
|
958
958
|
|
|
959
|
+
it('ranks a match on more of the query above a shorter named entry', async () => {
|
|
960
|
+
const {data} = await search('dropdown menu radio options', {cwd});
|
|
961
|
+
expect(data.results[0]).toMatchObject({name: 'DropdownMenuRadioItem'});
|
|
962
|
+
}, SLOW);
|
|
963
|
+
|
|
964
|
+
it('lets a plural start a name through its singular', () => {
|
|
965
|
+
expect(
|
|
966
|
+
scoreCandidate('tokens', {domain: 'component', name: 'Tokenizer'}),
|
|
967
|
+
).toMatchObject({score: 60});
|
|
968
|
+
});
|
|
969
|
+
|
|
959
970
|
it('finds Icon by a glyph name', async () => {
|
|
960
971
|
for (const q of ['cog', 'lightning bolt']) {
|
|
961
972
|
const {data} = await search(q, {cwd});
|
|
@@ -31,6 +31,43 @@ export function detectInstalledTargetVersion(cwd: string): {
|
|
|
31
31
|
version: string;
|
|
32
32
|
packageName: string;
|
|
33
33
|
} | null;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the installed Core is newer than this CLI, so part of the requested
|
|
36
|
+
* range has no codemods here.
|
|
37
|
+
*
|
|
38
|
+
* Core codemods ship inside the CLI. A CLI older than the installed
|
|
39
|
+
* `@astryxdesign/core` has none for the releases after its own version, so it
|
|
40
|
+
* can find no codemods, or stop partway, while the code still needs those
|
|
41
|
+
* releases' migrations. The returned command repeats this upgrade with the CLI
|
|
42
|
+
* release that matches the installed Core.
|
|
43
|
+
*
|
|
44
|
+
* Where an upgrade runs decides what it finds: the installed Core is read
|
|
45
|
+
* from that folder, and `--path` must stay inside it. So the command first
|
|
46
|
+
* changes to `cwd`, the folder this run used, then names `sourcePath`, the
|
|
47
|
+
* directory this run scanned, as an absolute `--path`. Both are named by their
|
|
48
|
+
* physical paths, with every symbolic link resolved: a shell's `cd` follows a
|
|
49
|
+
* link, but the CLI it starts reads its folder with every link resolved and
|
|
50
|
+
* checks `--path` against that. Pasted from any folder, the command finds the
|
|
51
|
+
* same Core and scans the same directory, even after a package runner moved
|
|
52
|
+
* this run (Yarn 1 runs `yarn astryx` at the project root). It is written for
|
|
53
|
+
* a POSIX shell, or for PowerShell on Windows (cmd.exe is not a target), with
|
|
54
|
+
* every argument quoted for that shell.
|
|
55
|
+
*
|
|
56
|
+
* Returns null when the CLI covers the whole range (`to` is not newer than
|
|
57
|
+
* both the CLI and `from`), when the CLI's own version cannot be read, or when
|
|
58
|
+
* the target is legacy `@xds/core`, which no CLI release shares a version with.
|
|
59
|
+
*
|
|
60
|
+
* @param {{from: string, to: string, packageName: string, options: UpgradeOptions, cwd: string, sourcePath: string}} input
|
|
61
|
+
* @returns {import('./upgrade.type.mjs').CliBehindCore | null}
|
|
62
|
+
*/
|
|
63
|
+
export function detectCliBehindCore({ from, to, packageName, options, cwd, sourcePath, }: {
|
|
64
|
+
from: string;
|
|
65
|
+
to: string;
|
|
66
|
+
packageName: string;
|
|
67
|
+
options: UpgradeOptions;
|
|
68
|
+
cwd: string;
|
|
69
|
+
sourcePath: string;
|
|
70
|
+
}): import("./upgrade.type.mjs").CliBehindCore | null;
|
|
34
71
|
/**
|
|
35
72
|
* @param {(string | null | undefined | false)[] | undefined} files
|
|
36
73
|
* @returns {string[]}
|
|
@@ -104,9 +141,9 @@ export function ensureCodemodDeps({ installDeps }?: {
|
|
|
104
141
|
* Run the CORE registry codemods. Runs BEFORE the config is loaded so a core
|
|
105
142
|
* CONFIG codemod can repair a config the strict loader would otherwise reject.
|
|
106
143
|
* @param {CoreVersionManifest[]} versionManifests
|
|
107
|
-
* @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean}} options
|
|
144
|
+
* @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean, coversTarget?: boolean}} options
|
|
108
145
|
*/
|
|
109
|
-
export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply, path: srcPath, codemod, skipCodemods, root, protection, silent }: {
|
|
146
|
+
export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply, path: srcPath, codemod, skipCodemods, root, protection, silent, coversTarget, }: {
|
|
110
147
|
apply: boolean;
|
|
111
148
|
path: string;
|
|
112
149
|
codemod?: string;
|
|
@@ -117,6 +154,7 @@ export function runCoreCodemods(versionManifests: CoreVersionManifest[], { apply
|
|
|
117
154
|
classify: (file: string) => import("../../foundation/fs/file-protection.mjs").FileProtection[];
|
|
118
155
|
};
|
|
119
156
|
silent?: boolean;
|
|
157
|
+
coversTarget?: boolean;
|
|
120
158
|
}): Promise<{
|
|
121
159
|
totalFilesChanged: number;
|
|
122
160
|
totalTransformsApplied: number;
|
package/api/upgrade/_adapter.mjs
CHANGED
|
@@ -34,7 +34,15 @@ import {
|
|
|
34
34
|
inspectAgentDocs,
|
|
35
35
|
renderAgentDocsBlock,
|
|
36
36
|
} from '../../foundation/agent-docs/agent-docs.mjs';
|
|
37
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
CLI_PACKAGE,
|
|
39
|
+
commandInFolder,
|
|
40
|
+
formatCliCommand,
|
|
41
|
+
getDlxPrefix,
|
|
42
|
+
quoteCommandArgument,
|
|
43
|
+
} from '../../foundation/env/package-manager.mjs';
|
|
44
|
+
import {isValidSemver, semverGt} from '../../foundation/env/semver.mjs';
|
|
45
|
+
import {CLI_ROOT} from '../../foundation/fs/paths.mjs';
|
|
38
46
|
import {Project, providerLedgerOf} from '../../foundation/config/project.mjs';
|
|
39
47
|
import {loadIntegrations} from '../../foundation/integrations/integrations.mjs';
|
|
40
48
|
import {resolveProviders} from '../../foundation/integrations/provider-resolution.mjs';
|
|
@@ -96,6 +104,99 @@ export function detectInstalledTargetVersion(cwd) {
|
|
|
96
104
|
return null;
|
|
97
105
|
}
|
|
98
106
|
|
|
107
|
+
/**
|
|
108
|
+
* The running CLI's own version, read from its package.json.
|
|
109
|
+
* @returns {string | null} null when it cannot be read or is not semver
|
|
110
|
+
*/
|
|
111
|
+
function readRunningCliVersion() {
|
|
112
|
+
try {
|
|
113
|
+
const pkg = JSON.parse(
|
|
114
|
+
fs.readFileSync(path.join(CLI_ROOT, 'package.json'), 'utf-8'),
|
|
115
|
+
);
|
|
116
|
+
return isValidSemver(pkg.version) ? pkg.version : null;
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Whether the installed Core is newer than this CLI, so part of the requested
|
|
124
|
+
* range has no codemods here.
|
|
125
|
+
*
|
|
126
|
+
* Core codemods ship inside the CLI. A CLI older than the installed
|
|
127
|
+
* `@astryxdesign/core` has none for the releases after its own version, so it
|
|
128
|
+
* can find no codemods, or stop partway, while the code still needs those
|
|
129
|
+
* releases' migrations. The returned command repeats this upgrade with the CLI
|
|
130
|
+
* release that matches the installed Core.
|
|
131
|
+
*
|
|
132
|
+
* Where an upgrade runs decides what it finds: the installed Core is read
|
|
133
|
+
* from that folder, and `--path` must stay inside it. So the command first
|
|
134
|
+
* changes to `cwd`, the folder this run used, then names `sourcePath`, the
|
|
135
|
+
* directory this run scanned, as an absolute `--path`. Both are named by their
|
|
136
|
+
* physical paths, with every symbolic link resolved: a shell's `cd` follows a
|
|
137
|
+
* link, but the CLI it starts reads its folder with every link resolved and
|
|
138
|
+
* checks `--path` against that. Pasted from any folder, the command finds the
|
|
139
|
+
* same Core and scans the same directory, even after a package runner moved
|
|
140
|
+
* this run (Yarn 1 runs `yarn astryx` at the project root). It is written for
|
|
141
|
+
* a POSIX shell, or for PowerShell on Windows (cmd.exe is not a target), with
|
|
142
|
+
* every argument quoted for that shell.
|
|
143
|
+
*
|
|
144
|
+
* Returns null when the CLI covers the whole range (`to` is not newer than
|
|
145
|
+
* both the CLI and `from`), when the CLI's own version cannot be read, or when
|
|
146
|
+
* the target is legacy `@xds/core`, which no CLI release shares a version with.
|
|
147
|
+
*
|
|
148
|
+
* @param {{from: string, to: string, packageName: string, options: UpgradeOptions, cwd: string, sourcePath: string}} input
|
|
149
|
+
* @returns {import('./upgrade.type.mjs').CliBehindCore | null}
|
|
150
|
+
*/
|
|
151
|
+
export function detectCliBehindCore({
|
|
152
|
+
from,
|
|
153
|
+
to,
|
|
154
|
+
packageName,
|
|
155
|
+
options,
|
|
156
|
+
cwd,
|
|
157
|
+
sourcePath,
|
|
158
|
+
}) {
|
|
159
|
+
if (packageName !== '@astryxdesign/core') return null;
|
|
160
|
+
const cliVersion = readRunningCliVersion();
|
|
161
|
+
if (!cliVersion || !semverGt(to, cliVersion) || !semverGt(to, from)) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
const runFolder = path.resolve(cwd);
|
|
165
|
+
const folder = physicalFolder(runFolder);
|
|
166
|
+
const scanned = path.join(folder, path.relative(runFolder, sourcePath));
|
|
167
|
+
const args = ['upgrade', '--from', from, '--path', scanned];
|
|
168
|
+
if (options.codemod) args.push('--codemod', options.codemod);
|
|
169
|
+
for (const name of options.skipCodemod ?? []) {
|
|
170
|
+
args.push('--skip-codemod', name);
|
|
171
|
+
}
|
|
172
|
+
for (const spec of options.integration ?? []) {
|
|
173
|
+
args.push('--integration', spec);
|
|
174
|
+
}
|
|
175
|
+
if (options.force) args.push('--force');
|
|
176
|
+
if (options.installDeps) args.push('--install-deps');
|
|
177
|
+
if (options.apply) args.push('--apply');
|
|
178
|
+
const upgrade = [
|
|
179
|
+
getDlxPrefix(cwd),
|
|
180
|
+
...[`${CLI_PACKAGE}@${to}`, ...args].map(arg => quoteCommandArgument(arg)),
|
|
181
|
+
].join(' ');
|
|
182
|
+
return {cliVersion, command: commandInFolder(folder, upgrade)};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* A folder as the operating system reports it to a process that runs there,
|
|
187
|
+
* with every symbolic link on the way resolved. Falls back to the path as
|
|
188
|
+
* given when it cannot be resolved.
|
|
189
|
+
* @param {string} dir an absolute folder
|
|
190
|
+
* @returns {string}
|
|
191
|
+
*/
|
|
192
|
+
function physicalFolder(dir) {
|
|
193
|
+
try {
|
|
194
|
+
return fs.realpathSync(dir);
|
|
195
|
+
} catch {
|
|
196
|
+
return dir;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
99
200
|
/**
|
|
100
201
|
* @param {(string | null | undefined | false)[] | undefined} files
|
|
101
202
|
* @returns {string[]}
|
|
@@ -332,11 +433,20 @@ export async function ensureCodemodDeps({installDeps} = {}) {
|
|
|
332
433
|
* Run the CORE registry codemods. Runs BEFORE the config is loaded so a core
|
|
333
434
|
* CONFIG codemod can repair a config the strict loader would otherwise reject.
|
|
334
435
|
* @param {CoreVersionManifest[]} versionManifests
|
|
335
|
-
* @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean}} options
|
|
436
|
+
* @param {{apply: boolean, path: string, codemod?: string, skipCodemods: Set<string>, root?: string, protection?: {root: string, classify: (file: string) => import('../../foundation/fs/file-protection.mjs').FileProtection[]}, silent?: boolean, coversTarget?: boolean}} options
|
|
336
437
|
*/
|
|
337
438
|
export async function runCoreCodemods(
|
|
338
439
|
versionManifests,
|
|
339
|
-
{
|
|
440
|
+
{
|
|
441
|
+
apply,
|
|
442
|
+
path: srcPath,
|
|
443
|
+
codemod,
|
|
444
|
+
skipCodemods,
|
|
445
|
+
root,
|
|
446
|
+
protection,
|
|
447
|
+
silent,
|
|
448
|
+
coversTarget,
|
|
449
|
+
},
|
|
340
450
|
) {
|
|
341
451
|
return runCodemods(versionManifests, {
|
|
342
452
|
apply,
|
|
@@ -346,6 +456,7 @@ export async function runCoreCodemods(
|
|
|
346
456
|
silent: silent ?? logger.silent,
|
|
347
457
|
root,
|
|
348
458
|
protection,
|
|
459
|
+
coversTarget,
|
|
349
460
|
});
|
|
350
461
|
}
|
|
351
462
|
|
|
@@ -411,7 +522,9 @@ export async function loadProjectContext(cwd, extraIntegrationSpecs = []) {
|
|
|
411
522
|
const extras =
|
|
412
523
|
extraSpecs.length === 0
|
|
413
524
|
? []
|
|
414
|
-
:
|
|
525
|
+
: // Resolved from the project, as --integration names a package it
|
|
526
|
+
// installed, not from whichever folder the process started in.
|
|
527
|
+
await loadIntegrations(extraSpecs, {cwd, resolveProviders: false});
|
|
415
528
|
const {integrations, ledger} = resolveProviders(
|
|
416
529
|
[
|
|
417
530
|
...candidates,
|