@astryxdesign/cli 0.7.2-canary.7462c41 → 0.7.2-canary.7ae39ea
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 +6 -6
- package/api/doctor/doctor.mjs +27 -3
- package/api/doctor/doctor.test.mjs +43 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +9 -3
- package/api/integration/validateIntegration.doc.mjs +3 -1
- package/api/search/search.d.mts +59 -6
- package/api/search/search.domain-priority.test.mjs +15 -0
- package/api/search/search.mjs +468 -28
- package/api/search/search.test.mjs +139 -0
- package/assets/docs/styling-overview.doc.mjs +1 -1
- package/assets/docs/tree/add-a-component.doc.mjs +1 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
- package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
- package/assets/docs/tree/block-template.doc.mjs +6 -18
- package/assets/docs/tree/build-the-template.doc.mjs +1 -1
- package/assets/docs/tree/check-the-props.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +10 -5
- package/assets/docs/tree/checks.doc.mjs +3 -3
- package/assets/docs/tree/codemods.doc.mjs +4 -4
- package/assets/docs/tree/component-family.doc.mjs +3 -5
- package/assets/docs/tree/component-imports.doc.mjs +2 -2
- package/assets/docs/tree/components.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -18
- package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
- package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
- package/assets/docs/tree/docs.doc.mjs +3 -3
- package/assets/docs/tree/document-the-template.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
- package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
- package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
- package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
- package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
- package/assets/docs/tree/integrations.doc.mjs +4 -0
- package/assets/docs/tree/links.doc.mjs +5 -4
- package/assets/docs/tree/migration-setup.doc.mjs +1 -0
- package/assets/docs/tree/migration-verification.doc.mjs +0 -1
- package/assets/docs/tree/migration.doc.mjs +0 -1
- package/assets/docs/tree/package-and-test.doc.mjs +1 -1
- package/assets/docs/tree/page-template.doc.mjs +3 -7
- package/assets/docs/tree/publishing.doc.mjs +1 -1
- package/assets/docs/tree/quick-start.doc.mjs +7 -19
- package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
- package/assets/docs/tree/replace-a-core-template.doc.mjs +5 -7
- package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
- package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
- package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
- package/assets/docs/tree/single-component.doc.mjs +12 -4
- package/assets/docs/tree/start-a-template.doc.mjs +3 -3
- package/assets/docs/tree/subcomponent.doc.mjs +6 -6
- package/assets/docs/tree/template-assets.doc.mjs +2 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
- package/assets/docs/tree/template-fonts.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +1 -1
- package/assets/docs/tree/template-images-media.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +2 -2
- package/assets/docs/tree/templates.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
- package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
- package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
- package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
- package/assets/docs/tree/upgrading.doc.mjs +3 -3
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
- package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
- package/assets/docs/tree/versioning.doc.mjs +6 -6
- package/assets/docs/tree/write-the-template-file.doc.mjs +2 -2
- package/authoring/codemod/codemod.doc.mjs +7 -3
- package/authoring/config/config.doc.mjs +9 -6
- package/authoring/config/type.ts +4 -2
- package/authoring/discover/discover.doc.mjs +1 -1
- package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
- package/authoring/doctypes/command/command.doc.mjs +14 -12
- package/authoring/doctypes/component/component.doc.mjs +28 -25
- package/authoring/doctypes/component/type.ts +7 -5
- package/authoring/doctypes/enum/enum.doc.mjs +7 -4
- package/authoring/doctypes/function/function.doc.mjs +9 -8
- package/authoring/doctypes/hook/hook.doc.mjs +5 -4
- package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
- package/authoring/doctypes/reference/reference.doc.mjs +11 -10
- package/authoring/doctypes/schema/schema.doc.mjs +9 -9
- package/authoring/doctypes/template/template.doc.mjs +2 -2
- package/authoring/doctypes/theme/theme.doc.mjs +2 -2
- package/authoring/gap-report/gap-report.doc.mjs +2 -2
- package/authoring/identity/identity.doc.mjs +3 -3
- package/authoring/integration/integration.doc.mjs +4 -3
- package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
- package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -1
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +3 -1
- package/clients/cli/commands/setup-nudge.test.mjs +79 -1
- package/clients/cli/commands/swizzle.mjs +5 -3
- package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
- package/clients/cli/index.mjs +29 -5
- package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
- package/foundation/agent-docs/agent-doc-state.mjs +38 -0
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/discovery/authoring-self-docs.mjs +1 -1
- 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/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 +6 -2
- package/package.json +9 -9
- package/scripts/postinstall.mjs +3 -3
package/README.md
CHANGED
|
@@ -581,12 +581,12 @@ There is no factory: write a plain object. For editor autocomplete and
|
|
|
581
581
|
type-checking, annotate it with the `AstryxConfig` type exported from
|
|
582
582
|
`@astryxdesign/cli/authoring`.
|
|
583
583
|
|
|
584
|
-
| Field | Type | Purpose
|
|
585
|
-
| ----------------------------- | ------------------------------ |
|
|
586
|
-
| `integrations` | `string[]` | Integration package names to load (see [Integrations](#integrations)).
|
|
587
|
-
| `issuesUrl` | `string` | Where "report an issue" links point for your project. Defaults to the core issue tracker.
|
|
588
|
-
| `hooks.postCodemod` | `PostCodemodHook[]` | Commands to run after `astryx upgrade` applies codemods (e.g. reinstall, rebuild, reformat).
|
|
589
|
-
| `experimental.xle.components` | `Record<string, XleComponent>` |
|
|
584
|
+
| Field | Type | Purpose |
|
|
585
|
+
| ----------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
586
|
+
| `integrations` | `string[]` | Integration package names to load (see [Integrations](#integrations)). |
|
|
587
|
+
| `issuesUrl` | `string` | Where "report an issue" links point for your project. Defaults to the core issue tracker. |
|
|
588
|
+
| `hooks.postCodemod` | `PostCodemodHook[]` | Commands to run after `astryx upgrade` applies codemods (e.g. reinstall, rebuild, reformat). |
|
|
589
|
+
| `experimental.xle.components` | `Record<string, XleComponent>` | Custom components for the removed layout expander, keyed by component name. The CLI still validates the field, so an entry without a string `from` makes `astryx.config` invalid, but nothing reads it. |
|
|
590
590
|
|
|
591
591
|
The config is validated against a strict schema when the CLI loads it, so an
|
|
592
592
|
unknown field is a hard error rather than a silent no-op. `astryx doctor`
|
package/api/doctor/doctor.mjs
CHANGED
|
@@ -351,6 +351,26 @@ export async function checkConfig(ctx) {
|
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
/**
|
|
355
|
+
* Why no integration is implicitly linked, from what actually loaded. A
|
|
356
|
+
* configured integration is named in astryx.config; the package's own manifest
|
|
357
|
+
* loads as itself (`__local`). Only the first may be described as named in
|
|
358
|
+
* astryx.config: a package with no config that loads its own manifest has no
|
|
359
|
+
* config file to name it.
|
|
360
|
+
*
|
|
361
|
+
* @param {Array<{name?: string, __local?: boolean}>} integrations loaded, none
|
|
362
|
+
* autolinked and none that failed to load
|
|
363
|
+
* @returns {string}
|
|
364
|
+
*/
|
|
365
|
+
function describeNoImplicit(integrations) {
|
|
366
|
+
const own = integrations.filter(integration => integration.__local);
|
|
367
|
+
const configured = integrations.length - own.length;
|
|
368
|
+
const ownNames = own.map(integration => integration.name ?? 'this package').join(', ');
|
|
369
|
+
if (own.length === 0) return 'None — every loaded integration is named in astryx.config.';
|
|
370
|
+
if (configured === 0) return `None — the only loaded integration is this package's own manifest (${ownNames}).`;
|
|
371
|
+
return `None — every loaded integration is named in astryx.config or is this package's own manifest (${ownNames}).`;
|
|
372
|
+
}
|
|
373
|
+
|
|
354
374
|
/**
|
|
355
375
|
* Check 6 — integrations that are loaded without an astryx.config entry.
|
|
356
376
|
*
|
|
@@ -395,14 +415,18 @@ export function checkImplicitIntegrations(ctx) {
|
|
|
395
415
|
const unreadable = describeUnreadableManifests(ctx.autolinkFailures ?? []);
|
|
396
416
|
|
|
397
417
|
if (implicit.length === 0) {
|
|
418
|
+
// A record that carries `__loadError` (the package's own manifest, or a
|
|
419
|
+
// configured one, that failed to load) loaded nothing, so it is not named
|
|
420
|
+
// as loaded beside the line reporting that it could not be loaded.
|
|
421
|
+
const loaded = ctx.integrations.filter(integration => !integration.__loadError);
|
|
398
422
|
return {
|
|
399
423
|
id,
|
|
400
424
|
label,
|
|
401
425
|
status: 'info',
|
|
402
426
|
message:
|
|
403
|
-
(
|
|
404
|
-
?
|
|
405
|
-
: unreadable
|
|
427
|
+
(loaded.length > 0
|
|
428
|
+
? describeNoImplicit(loaded)
|
|
429
|
+
: ctx.integrations.length > 0 || unreadable
|
|
406
430
|
? 'None loaded.'
|
|
407
431
|
: 'None — no installed dependency ships an astryx.integration.* manifest.') +
|
|
408
432
|
unreadable,
|
|
@@ -353,6 +353,49 @@ describe('checkImplicitIntegrations', () => {
|
|
|
353
353
|
expect(c.message).toContain('named in astryx.config');
|
|
354
354
|
});
|
|
355
355
|
|
|
356
|
+
// A package with no astryx.config that loads its own manifest: there is no
|
|
357
|
+
// config file, so the message must not say anything is named in one.
|
|
358
|
+
it("names the package's own manifest instead of a config that does not exist", () => {
|
|
359
|
+
const c = checkImplicitIntegrations({
|
|
360
|
+
integrations: [autolinked({__autolinked: false, __local: true, name: '@acme/kit'})],
|
|
361
|
+
});
|
|
362
|
+
expect(c.status).toBe('info');
|
|
363
|
+
expect(c.message).toBe(
|
|
364
|
+
"None — the only loaded integration is this package's own manifest (@acme/kit).",
|
|
365
|
+
);
|
|
366
|
+
expect(c.message).not.toContain('astryx.config');
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// An own manifest that failed to load keeps a `__local` record carrying
|
|
370
|
+
// `__loadError`; it loaded nothing, so it is never named as loaded.
|
|
371
|
+
it("does not name the package's own manifest as loaded when it failed to load", () => {
|
|
372
|
+
const failed = autolinked({
|
|
373
|
+
__autolinked: false,
|
|
374
|
+
__local: true,
|
|
375
|
+
name: '@acme/kit',
|
|
376
|
+
__loadError: 'astryx.integration.mjs threw: boom',
|
|
377
|
+
});
|
|
378
|
+
const alone = checkImplicitIntegrations({integrations: [failed]});
|
|
379
|
+
expect(alone.status).toBe('info');
|
|
380
|
+
expect(alone.message).toBe('None loaded.');
|
|
381
|
+
const beside = checkImplicitIntegrations({
|
|
382
|
+
integrations: [autolinked({__autolinked: false}), failed],
|
|
383
|
+
});
|
|
384
|
+
expect(beside.message).toBe('None — every loaded integration is named in astryx.config.');
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it('names both when configured integrations load beside the own manifest', () => {
|
|
388
|
+
const c = checkImplicitIntegrations({
|
|
389
|
+
integrations: [
|
|
390
|
+
autolinked({__autolinked: false}),
|
|
391
|
+
autolinked({__autolinked: false, __local: true, name: '@acme/kit'}),
|
|
392
|
+
],
|
|
393
|
+
});
|
|
394
|
+
expect(c.message).toBe(
|
|
395
|
+
"None — every loaded integration is named in astryx.config or is this package's own manifest (@acme/kit).",
|
|
396
|
+
);
|
|
397
|
+
});
|
|
398
|
+
|
|
356
399
|
it('names the package, the field, and what it contributes', () => {
|
|
357
400
|
// Roots count only when they exist, so this one gives them real folders.
|
|
358
401
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-implicit-'));
|
|
@@ -18,7 +18,9 @@ export const doc = {
|
|
|
18
18
|
'replaces is checked too: its findings are issues, errors for a package that ' +
|
|
19
19
|
'declares the CLI range that turns replacement on and warnings otherwise. ' +
|
|
20
20
|
"Each component doc's props are compared with the component's TypeScript props, " +
|
|
21
|
-
"read with the project's own `typescript
|
|
21
|
+
"read with the project's own `typescript` (or, where `typescript` is missing or has no " +
|
|
22
|
+
'JavaScript compiler API, as TypeScript 7 does, the `@typescript/typescript6` it ' +
|
|
23
|
+
'installs): a documented prop the code lacks, a ' +
|
|
22
24
|
'prop the package declares that the doc omits, a wrong `required`, or a type ' +
|
|
23
25
|
'that does not match. A type is judged only when it reads exactly: the same ' +
|
|
24
26
|
'text as the source, once whitespace, quotes and union order are set aside (exactly, if it contains `readonly`), ' +
|
|
@@ -50,14 +52,18 @@ export const doc = {
|
|
|
50
52
|
'drift',
|
|
51
53
|
],
|
|
52
54
|
params: [
|
|
53
|
-
{
|
|
55
|
+
{
|
|
56
|
+
name: 'pkg',
|
|
57
|
+
type: 'string',
|
|
58
|
+
description: 'Installed package; omit for the local package.',
|
|
59
|
+
},
|
|
54
60
|
{name: 'options.cwd', type: 'string', description: 'Resolution directory.'},
|
|
55
61
|
],
|
|
56
62
|
returns: [
|
|
57
63
|
{
|
|
58
64
|
type: 'integration.component-conflicts',
|
|
59
65
|
description:
|
|
60
|
-
|
|
66
|
+
"`validated` (false when no integration manifest was found, so nothing was inspected), integration identity, structural and replaces issues, and Core component-name conflicts with package-qualified commands. An active replacement that keeps the Core name it replaces is not a conflict. When the manifest loads and declares a components root, `propDrift` holds the props comparison: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `components` compared, `typesCompared` (documented prop types judged), `typesSkipped` (why none was, with a TypeScript older than 4.8), `findings` ({component, prop, kind: `not_in_code` | `not_in_doc` | `required_mismatch` | `type_mismatch`, severity: `warning`, message, doc, source, docType?, codeType?, docRequired?, codeRequired?}), `unchecked` ({component, doc, reason}), `typesNotCompared` ({component, doc, reason, props}: every other documented prop type, grouped by why it was not judged: not a form the check judges exactly (a doc type that does not parse, or a prop a mapped type builds from keys the check cannot trace, included), a field the prop's variants give different types, a standard prop such as `className`, or a prop declared outside the package), and `propsNotChecked` when a mapped type builds props from keys the check cannot trace to the package ({component, doc, reason, props}: no warning is drawn for those props).",
|
|
61
67
|
},
|
|
62
68
|
],
|
|
63
69
|
examples: [
|
|
@@ -26,7 +26,9 @@ export const doc = {
|
|
|
26
26
|
'can stay exit-0 in a non-integration directory. It also checks every doc the ' +
|
|
27
27
|
'package ships under its roots (component, template, docs topic, theme, and translation, served or not) against ' +
|
|
28
28
|
"the published authoring type for its kind, as `tsc` would, with the project's " +
|
|
29
|
-
'own `typescript
|
|
29
|
+
'own `typescript` (or, where `typescript` is missing or has no JavaScript compiler ' +
|
|
30
|
+
'API, as TypeScript 7 does, the `@typescript/typescript6` it installs): an unknown ' +
|
|
31
|
+
'field, a missing required field, or a value outside ' +
|
|
30
32
|
"a field's type is a warning in `docTypes` naming the field and a fix. A test " +
|
|
31
33
|
'fixture under `__tests__` in the components or docs root is counted, not checked. ' +
|
|
32
34
|
'Without TypeScript, `docTypes` is `skipped` with a reason.',
|
package/api/search/search.d.mts
CHANGED
|
@@ -16,6 +16,48 @@ export function stem(w: string): string;
|
|
|
16
16
|
* @returns {boolean}
|
|
17
17
|
*/
|
|
18
18
|
export function sameWord(a: string, b: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* A query with its camelCase and PascalCase identifiers spelled as words, so
|
|
21
|
+
* `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
|
|
22
|
+
* table pagination state". Plain words, and identifiers joined with `_` or `-`, are
|
|
23
|
+
* unchanged: a joined token that matches nothing stays unmatched.
|
|
24
|
+
* @param {string} query - The query as typed, before lowercasing.
|
|
25
|
+
* @returns {string} Lowercased.
|
|
26
|
+
*/
|
|
27
|
+
export function spellIdentifiers(query: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* The strongest hit a run of two or more adjacent query words has when it is
|
|
30
|
+
* read as one joined word, and the query words it covers. Readers type a
|
|
31
|
+
* compound name as separate words (`table header cell` is TableHeaderCell,
|
|
32
|
+
* `number field` the keyword `numberfield`), and no single word of the run
|
|
33
|
+
* matches on its own.
|
|
34
|
+
*
|
|
35
|
+
* - 100: the run joins to a component, hook, or template name, or its plural
|
|
36
|
+
* (`table header cells` is TableHeaderCell), or a hook name without its
|
|
37
|
+
* `use` prefix (`table sticky columns` is useTableStickyColumns).
|
|
38
|
+
* - 90: the run joins to a one-word keyword (`number field` is
|
|
39
|
+
* `numberfield`).
|
|
40
|
+
* - 95: the run joins to most of a name, cut short (`dropdown menu radio` is
|
|
41
|
+
* DropdownMenuRadioItem); 92: it is a name's leading words, covering at least half
|
|
42
|
+
* of it (`top nav mega` is TopNavMegaMenu); 70: it is two or more adjacent
|
|
43
|
+
* words of a name that cover at least half of it (`header cell` in
|
|
44
|
+
* TableHeaderCell), the same coverage a word prefix needs. These three
|
|
45
|
+
* are for components and hooks only.
|
|
46
|
+
*
|
|
47
|
+
* A doc's name is a route or key, so docs are left out.
|
|
48
|
+
* @param {string[]} words - The query's words, stopwords included.
|
|
49
|
+
* @param {Candidate} candidate
|
|
50
|
+
* @returns {{score: number, reason: string, covered: Set<string>, alias?: 'partial' | 'keyword', aliasWords?: number} | null}
|
|
51
|
+
* `covered` holds the run's words and every stretch of them joined. `alias`
|
|
52
|
+
* marks a hit on part of a name or on a keyword, not on the whole name.
|
|
53
|
+
*/
|
|
54
|
+
export function compoundHit(words: string[], candidate: Candidate): {
|
|
55
|
+
score: number;
|
|
56
|
+
reason: string;
|
|
57
|
+
covered: Set<string>;
|
|
58
|
+
alias?: "partial" | "keyword";
|
|
59
|
+
aliasWords?: number;
|
|
60
|
+
} | null;
|
|
19
61
|
/**
|
|
20
62
|
* Split a query into meaningful content tokens (lowercased, stopwords + very
|
|
21
63
|
* short words removed). Empty for single-word queries (callers fall back to
|
|
@@ -68,7 +110,7 @@ export function domainPriority(term: string, tokens: string[], candidate: Candid
|
|
|
68
110
|
score: number;
|
|
69
111
|
matched: number;
|
|
70
112
|
total: number;
|
|
71
|
-
}): 0 | 1 | 2;
|
|
113
|
+
}, queryWords?: string[]): 0 | 1 | 2;
|
|
72
114
|
/**
|
|
73
115
|
* The first title or heading that holds every word of the query, in order and
|
|
74
116
|
* side by side, or null.
|
|
@@ -90,18 +132,26 @@ export function titleInQuery(term: string, titles: string[] | undefined): string
|
|
|
90
132
|
* @param {string} term - Lowercased full query.
|
|
91
133
|
* @param {string[]} tokens - Content tokens from tokenizeQuery(term).
|
|
92
134
|
* @param {Candidate} candidate
|
|
93
|
-
* @
|
|
135
|
+
* @param {string[]} [words] - The query's words for compound names (see
|
|
136
|
+
* compoundHit); empty when the query names an entry outright.
|
|
137
|
+
* @param {{plain?: boolean}} [opts] - `plain`: score without matches on part
|
|
138
|
+
* of a name or a joined keyword.
|
|
139
|
+
* @returns {{score: number, reason: string, matched: number, total: number, alias?: 'partial' | 'keyword', aliasWords?: number} | null}
|
|
94
140
|
* `matched`/`total` are the query concepts this candidate answered, out of
|
|
95
141
|
* the concepts the query had. Callers that must distinguish "matched one word
|
|
96
142
|
* of three" from "matched all three" — `build`, which gates its pages group
|
|
97
143
|
* on coverage — cannot recover that from the score, because a single strong
|
|
98
144
|
* hit and a broad weak one land on the same number.
|
|
99
145
|
*/
|
|
100
|
-
export function scoreQuery(term: string, tokens: string[], candidate: Candidate
|
|
146
|
+
export function scoreQuery(term: string, tokens: string[], candidate: Candidate, words?: string[], { plain }?: {
|
|
147
|
+
plain?: boolean;
|
|
148
|
+
}): {
|
|
101
149
|
score: number;
|
|
102
150
|
reason: string;
|
|
103
151
|
matched: number;
|
|
104
152
|
total: number;
|
|
153
|
+
alias?: "partial" | "keyword";
|
|
154
|
+
aliasWords?: number;
|
|
105
155
|
} | null;
|
|
106
156
|
/**
|
|
107
157
|
* Score a single candidate against the search term across name, keywords,
|
|
@@ -119,8 +169,9 @@ export function scoreQuery(term: string, tokens: string[], candidate: Candidate)
|
|
|
119
169
|
* @param {string} [candidate.description]
|
|
120
170
|
* @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
|
|
121
171
|
* @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
|
|
122
|
-
* @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
|
|
123
|
-
* @returns {{score: number, reason: string} | null}
|
|
172
|
+
* @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.
|
|
173
|
+
* @returns {{score: number, reason: string, alias?: 'partial' | 'keyword'} | null}
|
|
174
|
+
* `alias` marks a hit that read the query's words joined.
|
|
124
175
|
*/
|
|
125
176
|
export function scoreCandidate(term: string, { name, aliases, domain, keywords, weakKeywords, description, prose, guidance, }: {
|
|
126
177
|
name: string;
|
|
@@ -131,11 +182,13 @@ export function scoreCandidate(term: string, { name, aliases, domain, keywords,
|
|
|
131
182
|
description?: string | undefined;
|
|
132
183
|
prose?: string[] | undefined;
|
|
133
184
|
guidance?: string[] | undefined;
|
|
134
|
-
}, { fuzzy }?: {
|
|
185
|
+
}, { fuzzy, joins }?: {
|
|
135
186
|
fuzzy?: boolean;
|
|
187
|
+
joins?: boolean;
|
|
136
188
|
}): {
|
|
137
189
|
score: number;
|
|
138
190
|
reason: string;
|
|
191
|
+
alias?: "partial" | "keyword";
|
|
139
192
|
} | null;
|
|
140
193
|
/**
|
|
141
194
|
* The components (name and keywords) a search response was scored against, or
|
|
@@ -277,6 +277,21 @@ describe('search domain priority — real docs and components', () => {
|
|
|
277
277
|
SLOW,
|
|
278
278
|
);
|
|
279
279
|
|
|
280
|
+
it(
|
|
281
|
+
'opens the guide that answers a declared phrase, not one that only mentions it',
|
|
282
|
+
async () => {
|
|
283
|
+
const [layers] = (await search('cascade layers', {cwd})).data.results;
|
|
284
|
+
expect(layers).toMatchObject({
|
|
285
|
+
domain: 'doc',
|
|
286
|
+
name: 'migration/migration-setup',
|
|
287
|
+
});
|
|
288
|
+
const [keyboard] = (await search('keyboard navigation', {cwd})).data
|
|
289
|
+
.results;
|
|
290
|
+
expect(keyboard?.name).not.toBe('migration/migration-verification');
|
|
291
|
+
},
|
|
292
|
+
SLOW,
|
|
293
|
+
);
|
|
294
|
+
|
|
280
295
|
it(
|
|
281
296
|
'keeps a component above docs that match only by a heading, with scores unchanged',
|
|
282
297
|
async () => {
|