@astryxdesign/cli 0.7.2-canary.621784f → 0.7.2-canary.64e1dde
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 +12 -12
- 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/doctor.mjs +27 -3
- package/api/doctor/doctor.test.mjs +43 -0
- 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 +10 -0
- package/api/integration/_adapter.mjs +13 -0
- package/api/integration/authoring-checks.mjs +14 -3
- package/api/integration/authoring-checks.test.mjs +326 -0
- package/api/integration/authoring-checks.type.d.mts +50 -0
- package/api/integration/authoring-checks.type.mjs +21 -1
- package/api/integration/integrationComponentConflicts.doc.mjs +9 -3
- package/api/integration/integrationDocConflicts.doc.mjs +17 -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 +72 -12
- package/api/search/search.domain-priority.test.mjs +108 -18
- package/api/search/search.mjs +501 -37
- package/api/search/search.test.mjs +139 -0
- package/api/theme/build/build.family.test.mjs +54 -6
- package/api/theme/build/build.mjs +110 -13
- package/api/theme/themeBuild.doc.mjs +4 -4
- 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/styling-overview.doc.mjs +1 -1
- package/assets/docs/theme.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 +11 -8
- 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 +2 -2
- package/assets/docs/tree/check-your-docs.doc.mjs +16 -7
- package/assets/docs/tree/checks.doc.mjs +7 -7
- 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 +25 -16
- 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 +8 -0
- package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
- package/assets/docs/tree/layout.doc.mjs +6 -6
- package/assets/docs/tree/links.doc.mjs +5 -4
- package/assets/docs/tree/migration-setup.doc.mjs +3 -2
- 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 +2 -2
- package/assets/docs/tree/quick-start.doc.mjs +37 -21
- 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 +5 -16
- 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 +8 -8
- package/assets/docs/tree/upgrading.doc.mjs +4 -4
- 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 +29 -26
- 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/build-theme.path-safety.test.mjs +155 -21
- package/clients/cli/commands/cli-postinstall.test.mjs +49 -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 +17 -5
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +34 -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 +65 -0
- package/clients/cli/commands/integration.mjs +2 -3
- package/clients/cli/commands/json-contract.test.mjs +5 -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/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/upgrade.doc.mjs +14 -0
- package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
- 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/copied-passages.d.mts +208 -0
- package/foundation/discovery/copied-passages.mjs +720 -0
- package/foundation/discovery/copied-passages.test.mjs +124 -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 +10 -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/scripts/postinstall.mjs +3 -3
|
@@ -303,6 +303,347 @@ function runCliVerify() {
|
|
|
303
303
|
};
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Give the built ocean theme a font stylesheet and an entry module that loads
|
|
308
|
+
* the theme's own styles, and export them the way such a package does.
|
|
309
|
+
* @param {string} entry
|
|
310
|
+
* @param {string} [file] the entry's file name in `entries/`
|
|
311
|
+
*/
|
|
312
|
+
function writeOwnStylesEntry(entry, file = 'ocean.mjs') {
|
|
313
|
+
fs.writeFileSync(
|
|
314
|
+
path.join(tmpDir, 'themes', 'ocean', 'ocean.fonts.css'),
|
|
315
|
+
"@font-face { font-family: 'Ocean Sans'; src: local('Ocean Sans'); }\n",
|
|
316
|
+
);
|
|
317
|
+
fs.mkdirSync(path.join(tmpDir, 'entries'), {recursive: true});
|
|
318
|
+
fs.writeFileSync(path.join(tmpDir, 'entries', file), entry);
|
|
319
|
+
const packageFile = path.join(tmpDir, 'package.json');
|
|
320
|
+
const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf-8'));
|
|
321
|
+
pkg.files = ['astryx.integration.mjs', 'themes', 'entries'];
|
|
322
|
+
pkg.exports = {
|
|
323
|
+
'./themes/ocean': `./entries/${file}`,
|
|
324
|
+
'./themes/ocean.css': './themes/ocean/ocean.css',
|
|
325
|
+
'./themes/ocean.fonts.css': './themes/ocean/ocean.fonts.css',
|
|
326
|
+
};
|
|
327
|
+
fs.writeFileSync(packageFile, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Rename the ocean theme to deep-sea, keeping its `ocean` slug, and build it,
|
|
332
|
+
* so its outputs are named after the theme: `deep-sea.css` and `deep-sea.js`,
|
|
333
|
+
* which exports `deepSeaTheme`.
|
|
334
|
+
*/
|
|
335
|
+
function writeRenamedOcean() {
|
|
336
|
+
writePackage({files: ['astryx.integration.mjs', 'themes', 'entries']});
|
|
337
|
+
fs.writeFileSync(
|
|
338
|
+
path.join(tmpDir, 'themes', 'ocean', 'oceanTheme.ts'),
|
|
339
|
+
"import {defineTheme} from '@astryxdesign/core/theme';\n\nexport const oceanTheme = defineTheme({name: 'deep-sea'});\n",
|
|
340
|
+
);
|
|
341
|
+
const built = spawnSync(
|
|
342
|
+
process.execPath,
|
|
343
|
+
[
|
|
344
|
+
path.join(process.cwd(), 'packages/cli/clients/cli/bin/astryx.mjs'),
|
|
345
|
+
'theme',
|
|
346
|
+
'build',
|
|
347
|
+
'themes/ocean/oceanTheme.ts',
|
|
348
|
+
],
|
|
349
|
+
{cwd: tmpDir, encoding: 'utf-8', timeout: 30_000},
|
|
350
|
+
);
|
|
351
|
+
if (built.status !== 0) {
|
|
352
|
+
throw new Error(`Could not build the theme fixture: ${built.stderr}`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Give the ocean theme an icon registry and build it, so its built module
|
|
358
|
+
* also exports `oceanIcons`.
|
|
359
|
+
*/
|
|
360
|
+
function writeOceanWithIcons() {
|
|
361
|
+
writePackage({files: ['astryx.integration.mjs', 'themes', 'entries']});
|
|
362
|
+
const themeDir = path.join(tmpDir, 'themes', 'ocean');
|
|
363
|
+
fs.writeFileSync(
|
|
364
|
+
path.join(themeDir, 'icons.js'),
|
|
365
|
+
'export const oceanIcons = {};\n',
|
|
366
|
+
);
|
|
367
|
+
fs.writeFileSync(
|
|
368
|
+
path.join(themeDir, 'oceanTheme.ts'),
|
|
369
|
+
"import {defineTheme} from '@astryxdesign/core/theme';\nimport {oceanIcons} from './icons';\n\nexport const oceanTheme = defineTheme({name: 'ocean', icons: oceanIcons});\n",
|
|
370
|
+
);
|
|
371
|
+
const built = spawnSync(
|
|
372
|
+
process.execPath,
|
|
373
|
+
[
|
|
374
|
+
path.join(process.cwd(), 'packages/cli/clients/cli/bin/astryx.mjs'),
|
|
375
|
+
'theme',
|
|
376
|
+
'build',
|
|
377
|
+
'themes/ocean/oceanTheme.ts',
|
|
378
|
+
],
|
|
379
|
+
{cwd: tmpDir, encoding: 'utf-8', timeout: 30_000},
|
|
380
|
+
);
|
|
381
|
+
if (built.status !== 0) {
|
|
382
|
+
throw new Error(`Could not build the theme fixture: ${built.stderr}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// An entry like one whose import is the whole integration: it loads the
|
|
387
|
+
// theme's fonts and stylesheet, by relative path and through the package's
|
|
388
|
+
// own exports, and re-exports the built theme.
|
|
389
|
+
const OWN_STYLES_ENTRY = `// Copyright (c) Acme.
|
|
390
|
+
|
|
391
|
+
import '../themes/ocean/ocean.fonts.css';
|
|
392
|
+
import '@acme/widgets/themes/ocean.css';
|
|
393
|
+
|
|
394
|
+
export {oceanTheme} from '../themes/ocean/ocean.js';
|
|
395
|
+
`;
|
|
396
|
+
|
|
397
|
+
describe('a theme module that loads its own styles', () => {
|
|
398
|
+
it('passes an entry that imports the theme stylesheet and fonts and re-exports the built module', async () => {
|
|
399
|
+
writePackage({themeExports: true});
|
|
400
|
+
writeOwnStylesEntry(OWN_STYLES_ENTRY);
|
|
401
|
+
|
|
402
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
403
|
+
|
|
404
|
+
expect(result.data.issues).toEqual([]);
|
|
405
|
+
expect(result.data.packable).toBe(true);
|
|
406
|
+
const cli = runCliVerify();
|
|
407
|
+
expect(cli.status, cli.stderr).toBe(0);
|
|
408
|
+
expect(cli.receipt?.data.issues).toEqual([]);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it('passes an entry that imports its fonts through the package exports and re-exports everything', async () => {
|
|
412
|
+
writePackage({themeExports: true});
|
|
413
|
+
writeOwnStylesEntry(
|
|
414
|
+
"import '@acme/widgets/themes/ocean.fonts.css';\nimport '../themes/ocean/ocean.css';\nexport * from '../themes/ocean/ocean.js';\n",
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
418
|
+
|
|
419
|
+
expect(result.data.issues).toEqual([]);
|
|
420
|
+
expect(result.data.packable).toBe(true);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it.each([
|
|
424
|
+
[
|
|
425
|
+
'also imports another stylesheet',
|
|
426
|
+
`${OWN_STYLES_ENTRY}import './other.css';\n`,
|
|
427
|
+
"./other.css is not the theme's own stylesheet or font stylesheet",
|
|
428
|
+
],
|
|
429
|
+
[
|
|
430
|
+
'also imports a script',
|
|
431
|
+
`import './setup.mjs';\n${OWN_STYLES_ENTRY}`,
|
|
432
|
+
"./setup.mjs is not the theme's own stylesheet or font stylesheet",
|
|
433
|
+
],
|
|
434
|
+
[
|
|
435
|
+
'runs code',
|
|
436
|
+
`${OWN_STYLES_ENTRY}console.log('ocean');\n`,
|
|
437
|
+
'line 7 is neither a stylesheet import nor the re-export',
|
|
438
|
+
],
|
|
439
|
+
[
|
|
440
|
+
'exports another value',
|
|
441
|
+
`${OWN_STYLES_ENTRY}export const extra = 1;\n`,
|
|
442
|
+
'line 7 is neither a stylesheet import nor the re-export',
|
|
443
|
+
],
|
|
444
|
+
[
|
|
445
|
+
'renames the theme it re-exports',
|
|
446
|
+
"import '../themes/ocean/ocean.css';\nexport {oceanTheme, oceanTheme as theme} from '../themes/ocean/ocean.js';\n",
|
|
447
|
+
'it re-exports names other than oceanTheme',
|
|
448
|
+
],
|
|
449
|
+
[
|
|
450
|
+
'binds the stylesheet it imports',
|
|
451
|
+
"import styles from '../themes/ocean/ocean.css';\nexport {oceanTheme} from '../themes/ocean/ocean.js';\n",
|
|
452
|
+
'its import of ../themes/ocean/ocean.css is not a side-effect import',
|
|
453
|
+
],
|
|
454
|
+
[
|
|
455
|
+
'imports the stylesheet as a CSS module script',
|
|
456
|
+
"import '../themes/ocean/ocean.css' with {type: 'css'};\nexport {oceanTheme} from '../themes/ocean/ocean.js';\n",
|
|
457
|
+
'its import of ../themes/ocean/ocean.css is not a side-effect import',
|
|
458
|
+
],
|
|
459
|
+
[
|
|
460
|
+
're-exports another name',
|
|
461
|
+
"import '../themes/ocean/ocean.css';\nexport {oceanTheme, missing} from '../themes/ocean/ocean.js';\n",
|
|
462
|
+
'it re-exports names other than oceanTheme',
|
|
463
|
+
],
|
|
464
|
+
[
|
|
465
|
+
're-exports a copy that is not a .js module',
|
|
466
|
+
"import '../themes/ocean/ocean.css';\nexport {oceanTheme} from './copy.cjs';\n",
|
|
467
|
+
'its re-export from ./copy.cjs does not name a .js module',
|
|
468
|
+
],
|
|
469
|
+
[
|
|
470
|
+
'has a directive',
|
|
471
|
+
`'use client';\n${OWN_STYLES_ENTRY}`,
|
|
472
|
+
'it has a directive',
|
|
473
|
+
],
|
|
474
|
+
[
|
|
475
|
+
're-exports twice',
|
|
476
|
+
`${OWN_STYLES_ENTRY}export * from '../themes/ocean/ocean.js';\n`,
|
|
477
|
+
'it has more than one re-export',
|
|
478
|
+
],
|
|
479
|
+
])('fails an entry that %s', async (_label, entry, reason) => {
|
|
480
|
+
writePackage({themeExports: true});
|
|
481
|
+
writeOwnStylesEntry(entry);
|
|
482
|
+
fs.writeFileSync(path.join(tmpDir, 'entries', 'other.css'), '.x {}\n');
|
|
483
|
+
fs.writeFileSync(path.join(tmpDir, 'entries', 'setup.mjs'), 'export {};\n');
|
|
484
|
+
fs.copyFileSync(
|
|
485
|
+
path.join(tmpDir, 'themes', 'ocean', 'ocean.js'),
|
|
486
|
+
path.join(tmpDir, 'entries', 'copy.cjs'),
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
490
|
+
|
|
491
|
+
expect(result.data.packable).toBe(false);
|
|
492
|
+
expect(result.data.issues).toEqual([
|
|
493
|
+
{
|
|
494
|
+
code: 'theme_module_stale',
|
|
495
|
+
severity: 'error',
|
|
496
|
+
message: `Theme "ocean" module is not the module \`astryx theme build themes/ocean/oceanTheme.ts\` writes and does not only wrap it: ${reason}. A module that wraps the built module may only import the theme's own stylesheet and font stylesheet for their side effects and re-export from the built module either everything or only its theme, as oceanTheme.`,
|
|
497
|
+
},
|
|
498
|
+
]);
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
it('fails an entry whose re-exported module drifts from source', async () => {
|
|
502
|
+
writePackage({themeExports: true});
|
|
503
|
+
writeOwnStylesEntry(OWN_STYLES_ENTRY);
|
|
504
|
+
fs.appendFileSync(
|
|
505
|
+
path.join(tmpDir, 'themes', 'ocean', 'ocean.js'),
|
|
506
|
+
'// stale module\n',
|
|
507
|
+
);
|
|
508
|
+
|
|
509
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
510
|
+
|
|
511
|
+
expect(result.data.packable).toBe(false);
|
|
512
|
+
expect(result.data.issues).toEqual([
|
|
513
|
+
{
|
|
514
|
+
code: 'theme_module_stale',
|
|
515
|
+
severity: 'error',
|
|
516
|
+
message:
|
|
517
|
+
'Theme "ocean" module re-exports ../themes/ocean/ocean.js, which does not match themes/ocean/oceanTheme.ts. Run `astryx theme build themes/ocean/oceanTheme.ts` before packing.',
|
|
518
|
+
},
|
|
519
|
+
]);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it('does not accept a TypeScript entry', async () => {
|
|
523
|
+
writePackage({themeExports: true});
|
|
524
|
+
writeOwnStylesEntry(OWN_STYLES_ENTRY, 'ocean.ts');
|
|
525
|
+
|
|
526
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
527
|
+
|
|
528
|
+
expect(result.data.packable).toBe(false);
|
|
529
|
+
expect(result.data.issues).toEqual([
|
|
530
|
+
{
|
|
531
|
+
code: 'theme_module_stale',
|
|
532
|
+
severity: 'error',
|
|
533
|
+
message:
|
|
534
|
+
'Theme "ocean" module does not match themes/ocean/oceanTheme.ts. Run `astryx theme build themes/ocean/oceanTheme.ts` before packing.',
|
|
535
|
+
},
|
|
536
|
+
]);
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
it('does not accept an entry that re-exports itself', async () => {
|
|
540
|
+
writePackage({themeExports: true});
|
|
541
|
+
writeOwnStylesEntry(
|
|
542
|
+
"import '../themes/ocean/ocean.css';\nexport * from './ocean.js';\n",
|
|
543
|
+
'ocean.js',
|
|
544
|
+
);
|
|
545
|
+
|
|
546
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
547
|
+
|
|
548
|
+
expect(result.data.packable).toBe(false);
|
|
549
|
+
expect(result.data.issues).toContainEqual(
|
|
550
|
+
expect.objectContaining({
|
|
551
|
+
code: 'theme_import_unresolvable',
|
|
552
|
+
message: expect.stringContaining('does not export "oceanTheme"'),
|
|
553
|
+
}),
|
|
554
|
+
);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('passes an entry for a theme whose own name differs from its slug', async () => {
|
|
558
|
+
writeRenamedOcean();
|
|
559
|
+
writeOwnStylesEntry(
|
|
560
|
+
"import '../themes/ocean/deep-sea.css';\nexport {deepSeaTheme as oceanTheme} from '../themes/ocean/deep-sea.js';\n",
|
|
561
|
+
);
|
|
562
|
+
setThemeExports({
|
|
563
|
+
'./themes/ocean': './entries/ocean.mjs',
|
|
564
|
+
'./themes/ocean.css': './themes/ocean/deep-sea.css',
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
568
|
+
|
|
569
|
+
expect(result.data.issues).toEqual([]);
|
|
570
|
+
expect(result.data.packable).toBe(true);
|
|
571
|
+
const cli = runCliVerify();
|
|
572
|
+
expect(cli.status, cli.stderr).toBe(0);
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
it('compares a partial export set with the module named after the theme', async () => {
|
|
576
|
+
writeRenamedOcean();
|
|
577
|
+
setThemeExports({'./themes/ocean': './themes/ocean/deep-sea.js'});
|
|
578
|
+
|
|
579
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
580
|
+
|
|
581
|
+
expect(result.data.packable).toBe(true);
|
|
582
|
+
expect(result.data.issues.map(issue => issue.code)).toEqual([
|
|
583
|
+
'theme_exports_incomplete',
|
|
584
|
+
]);
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
it('passes an entry that re-exports only the theme from a built module that also exports its icons', async () => {
|
|
588
|
+
writeOceanWithIcons();
|
|
589
|
+
writeOwnStylesEntry(OWN_STYLES_ENTRY);
|
|
590
|
+
|
|
591
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
592
|
+
|
|
593
|
+
expect(result.data.issues).toEqual([]);
|
|
594
|
+
expect(result.data.packable).toBe(true);
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
it('fails an entry that gives the built icons the theme export name', async () => {
|
|
598
|
+
writeOceanWithIcons();
|
|
599
|
+
writeOwnStylesEntry(
|
|
600
|
+
"import '../themes/ocean/ocean.css';\nexport {oceanIcons as oceanTheme} from '../themes/ocean/ocean.js';\n",
|
|
601
|
+
);
|
|
602
|
+
|
|
603
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
604
|
+
|
|
605
|
+
expect(result.data.packable).toBe(false);
|
|
606
|
+
expect(result.data.issues).toEqual([
|
|
607
|
+
expect.objectContaining({
|
|
608
|
+
code: 'theme_module_stale',
|
|
609
|
+
message: expect.stringContaining(
|
|
610
|
+
'it re-exports oceanIcons, which is not the built theme',
|
|
611
|
+
),
|
|
612
|
+
}),
|
|
613
|
+
]);
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
it('fails when packing changes the module an entry re-exports', async () => {
|
|
617
|
+
const prepack = [
|
|
618
|
+
"const fs=require('fs')",
|
|
619
|
+
"fs.copyFileSync('themes/ocean/ocean.js','.ocean.js.orig')",
|
|
620
|
+
"fs.appendFileSync('themes/ocean/ocean.js','// packed\\n')",
|
|
621
|
+
].join(';');
|
|
622
|
+
const postpack =
|
|
623
|
+
"require('fs').renameSync('.ocean.js.orig','themes/ocean/ocean.js')";
|
|
624
|
+
writePackage({
|
|
625
|
+
themeExports: true,
|
|
626
|
+
scripts: {
|
|
627
|
+
prepack: `node -e "${prepack}"`,
|
|
628
|
+
postpack: `node -e "${postpack}"`,
|
|
629
|
+
},
|
|
630
|
+
});
|
|
631
|
+
writeOwnStylesEntry(OWN_STYLES_ENTRY);
|
|
632
|
+
|
|
633
|
+
const result = await integrationPackCheck({cwd: tmpDir});
|
|
634
|
+
|
|
635
|
+
expect(result.data.packable).toBe(false);
|
|
636
|
+
expect(result.data.issues).toEqual([
|
|
637
|
+
{
|
|
638
|
+
code: 'packed_theme_module_changed',
|
|
639
|
+
severity: 'error',
|
|
640
|
+
message:
|
|
641
|
+
'Theme "ocean" module changed during packing. Keep the built output unchanged in the tarball.',
|
|
642
|
+
},
|
|
643
|
+
]);
|
|
644
|
+
});
|
|
645
|
+
});
|
|
646
|
+
|
|
306
647
|
describe('integrationPackCheck', () => {
|
|
307
648
|
it('returns packable:true for a valid integration with themes', async () => {
|
|
308
649
|
writePackage({files: ['astryx.integration.mjs', 'themes']});
|
|
@@ -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
|
|
@@ -40,19 +82,20 @@ export function tokenizeQuery(term: string): string[];
|
|
|
40
82
|
* typography/font-setup, `side panel` is "Side panels");
|
|
41
83
|
* - 1: a word of the query is the topic's name (`illustration` in a longer
|
|
42
84
|
* question is the illustrations guide);
|
|
85
|
+
* - 1: a query of two or more words is one of the topic's own declared
|
|
86
|
+
* keywords, whatever the plural (`code review` on a guide that declares it);
|
|
43
87
|
* - 1: the query holds one of the doc's titles whole (`resizable side panels`
|
|
44
88
|
* names "Side panels"; `light dark mode button` names "Light/Dark Mode");
|
|
45
89
|
* - 1: the doc matches every word of the query and one of them is a word of
|
|
46
90
|
* its title (`switch to a dark theme` and "Use a theme").
|
|
47
91
|
* A section answers to its topic's name.
|
|
48
92
|
*
|
|
49
|
-
* A doc that matched only by
|
|
93
|
+
* A doc that matched only by a heading holding the query, by one word, or by
|
|
50
94
|
* words spread through its text has no priority. Docs are split into many
|
|
51
|
-
* small topics,
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* above the component. Broad reference pages match every word of many queries
|
|
95
|
+
* small topics, each with its own headings, so a common phrase such as
|
|
96
|
+
* `font size` hits a heading exactly (170) while the component the reader is
|
|
97
|
+
* after matches one word by keyword (`Text`, 98). Ranked on text alone, every
|
|
98
|
+
* split adds another doc above the component. Broad reference pages match every word of many queries
|
|
56
99
|
* in their text the same way. The score stays the text-match strength the
|
|
57
100
|
* result reports, so callers that gate on it (`build`) see the same numbers.
|
|
58
101
|
*
|
|
@@ -67,7 +110,7 @@ export function domainPriority(term: string, tokens: string[], candidate: Candid
|
|
|
67
110
|
score: number;
|
|
68
111
|
matched: number;
|
|
69
112
|
total: number;
|
|
70
|
-
}): 0 | 1 | 2;
|
|
113
|
+
}, queryWords?: string[]): 0 | 1 | 2;
|
|
71
114
|
/**
|
|
72
115
|
* The first title or heading that holds every word of the query, in order and
|
|
73
116
|
* side by side, or null.
|
|
@@ -89,18 +132,26 @@ export function titleInQuery(term: string, titles: string[] | undefined): string
|
|
|
89
132
|
* @param {string} term - Lowercased full query.
|
|
90
133
|
* @param {string[]} tokens - Content tokens from tokenizeQuery(term).
|
|
91
134
|
* @param {Candidate} candidate
|
|
92
|
-
* @
|
|
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}
|
|
93
140
|
* `matched`/`total` are the query concepts this candidate answered, out of
|
|
94
141
|
* the concepts the query had. Callers that must distinguish "matched one word
|
|
95
142
|
* of three" from "matched all three" — `build`, which gates its pages group
|
|
96
143
|
* on coverage — cannot recover that from the score, because a single strong
|
|
97
144
|
* hit and a broad weak one land on the same number.
|
|
98
145
|
*/
|
|
99
|
-
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
|
+
}): {
|
|
100
149
|
score: number;
|
|
101
150
|
reason: string;
|
|
102
151
|
matched: number;
|
|
103
152
|
total: number;
|
|
153
|
+
alias?: "partial" | "keyword";
|
|
154
|
+
aliasWords?: number;
|
|
104
155
|
} | null;
|
|
105
156
|
/**
|
|
106
157
|
* Score a single candidate against the search term across name, keywords,
|
|
@@ -118,8 +169,9 @@ export function scoreQuery(term: string, tokens: string[], candidate: Candidate)
|
|
|
118
169
|
* @param {string} [candidate.description]
|
|
119
170
|
* @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
|
|
120
171
|
* @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
|
|
121
|
-
* @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
|
|
122
|
-
* @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.
|
|
123
175
|
*/
|
|
124
176
|
export function scoreCandidate(term: string, { name, aliases, domain, keywords, weakKeywords, description, prose, guidance, }: {
|
|
125
177
|
name: string;
|
|
@@ -130,11 +182,13 @@ export function scoreCandidate(term: string, { name, aliases, domain, keywords,
|
|
|
130
182
|
description?: string | undefined;
|
|
131
183
|
prose?: string[] | undefined;
|
|
132
184
|
guidance?: string[] | undefined;
|
|
133
|
-
}, { fuzzy }?: {
|
|
185
|
+
}, { fuzzy, joins }?: {
|
|
134
186
|
fuzzy?: boolean;
|
|
187
|
+
joins?: boolean;
|
|
135
188
|
}): {
|
|
136
189
|
score: number;
|
|
137
190
|
reason: string;
|
|
191
|
+
alias?: "partial" | "keyword";
|
|
138
192
|
} | null;
|
|
139
193
|
/**
|
|
140
194
|
* The components (name and keywords) a search response was scored against, or
|
|
@@ -213,6 +267,12 @@ export type Candidate = {
|
|
|
213
267
|
*/
|
|
214
268
|
aliases?: string[] | undefined;
|
|
215
269
|
keywords?: string[] | undefined;
|
|
270
|
+
/**
|
|
271
|
+
* - A doc's own declared keywords: what its
|
|
272
|
+
* author lists in `keywords`, without the code terms and table cells its
|
|
273
|
+
* other keywords add.
|
|
274
|
+
*/
|
|
275
|
+
_declared?: string[] | undefined;
|
|
216
276
|
weakKeywords?: string[] | undefined;
|
|
217
277
|
description?: string | undefined;
|
|
218
278
|
prose?: string[] | undefined;
|
|
@@ -75,14 +75,75 @@ async function placedGuides(route, seen = new Set()) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
describe('search domain priority — the rule', () => {
|
|
78
|
-
it('gives a doc no priority for a
|
|
78
|
+
it('gives a doc no priority for a heading match or a one-word keyword', () => {
|
|
79
79
|
const topic = {
|
|
80
80
|
domain: 'doc',
|
|
81
81
|
name: 'typography/font-setup',
|
|
82
|
-
keywords: ['
|
|
82
|
+
keywords: ['size'],
|
|
83
83
|
titles: ['Font Setup', 'Font Sizes'],
|
|
84
84
|
};
|
|
85
85
|
expect(priority('font size', topic)).toBe(0);
|
|
86
|
+
expect(priority('size', topic)).toBe(0);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('gives a doc priority when the query is one of its declared keywords', () => {
|
|
90
|
+
const guide = {
|
|
91
|
+
domain: 'doc',
|
|
92
|
+
name: 'guides/quality',
|
|
93
|
+
titles: ['Is my code good?'],
|
|
94
|
+
keywords: ['code review', 'review my code'],
|
|
95
|
+
_declared: ['code review', 'review my code'],
|
|
96
|
+
};
|
|
97
|
+
expect(priority('code review', guide)).toBe(1);
|
|
98
|
+
expect(priority('Code Reviews', guide)).toBe(1);
|
|
99
|
+
expect(priority('review my code', guide)).toBe(1);
|
|
100
|
+
// A section's keywords are its headings and code terms.
|
|
101
|
+
const section = {
|
|
102
|
+
...guide,
|
|
103
|
+
name: 'before-you-ship',
|
|
104
|
+
_topic: 'guides/quality',
|
|
105
|
+
_section: 'before-you-ship',
|
|
106
|
+
};
|
|
107
|
+
expect(priority('code review', section)).toBe(0);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("gives a doc no priority for a code term or table cell it didn't declare", () => {
|
|
111
|
+
// A typed doc's keywords hold the first column of its tables and the code
|
|
112
|
+
// terms its text mentions; `missing_field` reads as two words.
|
|
113
|
+
const reference = {
|
|
114
|
+
domain: 'doc',
|
|
115
|
+
name: 'cli/api/functions/validate-integration',
|
|
116
|
+
titles: ['validateIntegration'],
|
|
117
|
+
keywords: ['validate-integration', 'missing_field', 'file required'],
|
|
118
|
+
_declared: [],
|
|
119
|
+
_topic: 'cli/api/functions/validate-integration',
|
|
120
|
+
};
|
|
121
|
+
expect(priority('missing field', reference)).toBe(0);
|
|
122
|
+
expect(priority('file required', reference)).toBe(0);
|
|
123
|
+
expect(
|
|
124
|
+
priority('missing field', {...reference, _declared: ['missing field']}),
|
|
125
|
+
).toBe(1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('keeps a component the query names exactly above a doc that declares it', async () => {
|
|
129
|
+
const tokens = tokenizeQuery('empty state');
|
|
130
|
+
const component = {domain: 'component', name: 'EmptyState'};
|
|
131
|
+
const doc = {
|
|
132
|
+
domain: 'doc',
|
|
133
|
+
name: 'illustrations',
|
|
134
|
+
keywords: ['empty state'],
|
|
135
|
+
_declared: ['empty state'],
|
|
136
|
+
};
|
|
137
|
+
const c = scoreQuery('empty state', tokens, component);
|
|
138
|
+
const d = scoreQuery('empty state', tokens, doc);
|
|
139
|
+
expect(
|
|
140
|
+
domainPriority('empty state', tokens, /** @type {any} */ (component), c),
|
|
141
|
+
).toBe(1);
|
|
142
|
+
expect(
|
|
143
|
+
domainPriority('empty state', tokens, /** @type {any} */ (doc), d),
|
|
144
|
+
).toBe(1);
|
|
145
|
+
// Both have priority, so the stronger match wins: the exact name.
|
|
146
|
+
expect(c?.score).toBeGreaterThan(d?.score ?? 0);
|
|
86
147
|
});
|
|
87
148
|
|
|
88
149
|
it('gives a doc priority when the query names it', () => {
|
|
@@ -190,32 +251,61 @@ describe('search domain priority — the rule', () => {
|
|
|
190
251
|
|
|
191
252
|
describe('search domain priority — real docs and components', () => {
|
|
192
253
|
it(
|
|
193
|
-
'finds
|
|
254
|
+
'finds a guide that declares the whole phrase above a component that matches one word',
|
|
194
255
|
async () => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
r => r.domain === '
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
256
|
+
const results = (await search('font size', {cwd})).data.results;
|
|
257
|
+
expect(results[0]).toMatchObject({domain: 'doc'});
|
|
258
|
+
expect(results[0].name).toMatch(/^typography(?:\/|$)/);
|
|
259
|
+
// The component the phrase points to stays near the top.
|
|
260
|
+
expect(
|
|
261
|
+
results
|
|
262
|
+
.slice(0, 3)
|
|
263
|
+
.some(r => r.domain === 'component' && r.name === 'Text'),
|
|
264
|
+
).toBe(true);
|
|
265
|
+
},
|
|
266
|
+
SLOW,
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
it(
|
|
270
|
+
'keeps a component above a reference doc whose table or code terms hold the phrase',
|
|
271
|
+
async () => {
|
|
272
|
+
for (const q of ['missing field', 'file required']) {
|
|
273
|
+
const [top] = (await search(q, {cwd})).data.results;
|
|
274
|
+
expect(top, q).toMatchObject({domain: 'component', name: 'Field'});
|
|
206
275
|
}
|
|
207
276
|
},
|
|
208
277
|
SLOW,
|
|
209
278
|
);
|
|
210
279
|
|
|
211
280
|
it(
|
|
212
|
-
'
|
|
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
|
+
|
|
295
|
+
it(
|
|
296
|
+
'keeps a component above docs that match only by a heading, with scores unchanged',
|
|
213
297
|
async () => {
|
|
214
298
|
const results = (await search('font size', {cwd})).data.results;
|
|
215
|
-
const
|
|
216
|
-
r => r.domain === '
|
|
299
|
+
const text = results.findIndex(
|
|
300
|
+
r => r.domain === 'component' && r.name === 'Text',
|
|
217
301
|
);
|
|
218
|
-
expect(
|
|
302
|
+
expect(text).toBeGreaterThanOrEqual(0);
|
|
303
|
+
// A doc below Text outscores it on text alone: priority moved it, not the score.
|
|
304
|
+
expect(
|
|
305
|
+
results
|
|
306
|
+
.slice(text + 1)
|
|
307
|
+
.some(r => r.domain === 'doc' && r.score > results[text].score),
|
|
308
|
+
).toBe(true);
|
|
219
309
|
},
|
|
220
310
|
SLOW,
|
|
221
311
|
);
|