@astryxdesign/cli 0.7.3-canary.cbe384c → 0.7.3-canary.f94e962

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.
Files changed (52) hide show
  1. package/README.md +63 -63
  2. package/api/component/component.mjs +16 -2
  3. package/api/component/component.test.mjs +15 -0
  4. package/api/doctor/doctor.test.mjs +28 -3
  5. package/api/integration/_adapter.d.mts +8 -0
  6. package/api/integration/_adapter.mjs +21 -1
  7. package/api/integration/authoring-checks.test.mjs +220 -0
  8. package/api/integration/validate-integration.d.mts +2 -1
  9. package/api/integration/validate-integration.mjs +30 -5
  10. package/api/integration/validate-integration.type.d.mts +2 -1
  11. package/api/integration/validate-integration.type.mjs +2 -1
  12. package/api/integration/validateIntegration.doc.mjs +1 -1
  13. package/api/search/_entries.mjs +57 -1
  14. package/api/upgrade/_adapter.d.mts +57 -3
  15. package/api/upgrade/_adapter.mjs +149 -27
  16. package/api/upgrade/registry/registry.d.mts +10 -4
  17. package/api/upgrade/registry/registry.mjs +33 -16
  18. package/api/upgrade/registry/registry.test.mjs +85 -0
  19. package/api/upgrade/run/run.d.mts +4 -2
  20. package/api/upgrade/run/run.mjs +13 -2
  21. package/api/upgrade/run/run.test.mjs +417 -3
  22. package/api/upgrade/upgrade.doc.mjs +10 -5
  23. package/api/upgrade/upgrade.mjs +13 -2
  24. package/api/upgrade/upgrade.type.d.mts +5 -3
  25. package/api/upgrade/upgrade.type.mjs +8 -6
  26. package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
  27. package/assets/docs/tree/checks.doc.mjs +1 -1
  28. package/assets/templates/themes/butter/butterTheme.ts +4 -2
  29. package/assets/templates/themes/stone/stoneTheme.ts +4 -2
  30. package/assets/templates/themes/y2k/y2kTheme.ts +4 -2
  31. package/clients/cli/commands/integration-check.test.mjs +48 -0
  32. package/clients/cli/commands/upgrade.doc.mjs +4 -2
  33. package/clients/cli/commands/upgrade.mjs +9 -2
  34. package/clients/cli/commands/upgrade.subfolder-path.test.mjs +97 -0
  35. package/foundation/config/project.mjs +5 -20
  36. package/foundation/config/project.test.mjs +30 -0
  37. package/foundation/discovery/runner-allowlist.d.mts +2 -4
  38. package/foundation/discovery/runner-allowlist.mjs +2 -4
  39. package/foundation/discovery/runner-commands.d.mts +77 -0
  40. package/foundation/discovery/runner-commands.mjs +293 -0
  41. package/foundation/discovery/runner-commands.test.mjs +128 -0
  42. package/foundation/discovery/template-needs.mjs +1 -44
  43. package/foundation/doc-compiler/doc-loads.test.mjs +4 -0
  44. package/foundation/fs/paths.d.mts +70 -8
  45. package/foundation/fs/paths.mjs +526 -35
  46. package/foundation/fs/paths.test.mjs +430 -54
  47. package/foundation/integrations/autolink.d.mts +2 -1
  48. package/foundation/integrations/autolink.mjs +4 -13
  49. package/foundation/integrations/integrations.d.mts +11 -0
  50. package/foundation/integrations/integrations.mjs +21 -1
  51. package/foundation/response/response-types.doc.mjs +1 -1
  52. package/package.json +9 -9
@@ -461,8 +461,22 @@ async function componentRead(name, options = {}) {
461
461
  return componentDetailBlocks(dirName, cwd, owner.package);
462
462
  }
463
463
  const loaded = await loadComponentDoc(owner.docPath, docOpts);
464
- // A family member an integration lists under its own name reads as that
465
- // member, the way a Core sub-component does below.
464
+ // A family member reads as that member, scoped the way the unscoped
465
+ // lookup scopes it: an integration member by its own entry, a Core
466
+ // sub-component (HStack in the Stack doc) by scopeSubComponent.
467
+ const sub =
468
+ scoped.kind === 'core'
469
+ ? scopeSubComponent(loaded, dirName, coreDir)
470
+ : null;
471
+ if (sub) {
472
+ if (props) {
473
+ return componentDetailProps(
474
+ {props: sub.matchingComponent.props},
475
+ owner.package,
476
+ );
477
+ }
478
+ return componentDetail(sub.scoped, owner, dirName, coreDir);
479
+ }
466
480
  const docs =
467
481
  scoped.kind === 'integration'
468
482
  ? scopeIntegrationMember(loaded, owner, dirName)
@@ -135,6 +135,21 @@ describe('component list — components whose docs live in a family folder', ()
135
135
  });
136
136
  }, SLOW);
137
137
 
138
+ it('answers a Core-scoped lookup of a member with that member, as the unscoped lookup does', async () => {
139
+ for (const name of ['HStack', 'VStack']) {
140
+ const unscoped = await component(name, {cwd});
141
+ const scoped = await component(name, {
142
+ cwd,
143
+ package: '@astryxdesign/core',
144
+ });
145
+ expect(scoped.data.name).toBe(name);
146
+ expect(scoped.data.parentDoc).toBe('Stack');
147
+ expect(scoped.data.import).toBe(`@astryxdesign/core/${name}`);
148
+ expect(scoped.data.props).toEqual(unscoped.data.props);
149
+ expect(scoped.data.props.length).toBeGreaterThan(0);
150
+ }
151
+ }, SLOW);
152
+
138
153
  it('prints each one\'s own import path in the list, the detail, and search', async () => {
139
154
  // The path `component <Name>` prints is the one docs and examples teach:
140
155
  // the component's own entry point, never its family's (/Stack, /Text) or
@@ -1317,8 +1317,12 @@ describe('a configured integration that cannot load fails the gate', () => {
1317
1317
  'astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
1318
1318
  };
1319
1319
 
1320
- /** Run doctor on a project under the working directory. */
1321
- async function report(files) {
1320
+ /**
1321
+ * Run doctor on a project under the working directory, in its folder `at`.
1322
+ * @param {Record<string, string>} files
1323
+ * @param {string} [at]
1324
+ */
1325
+ async function report(files, at = '.') {
1322
1326
  const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-doctor-gate-'));
1323
1327
  tmpDirs.push(dir);
1324
1328
  for (const [rel, content] of Object.entries(files)) {
@@ -1326,7 +1330,7 @@ describe('a configured integration that cannot load fails the gate', () => {
1326
1330
  fs.mkdirSync(path.dirname(abs), {recursive: true});
1327
1331
  fs.writeFileSync(abs, content);
1328
1332
  }
1329
- const {checks, summary} = (await doctor({cwd: dir})).data;
1333
+ const {checks, summary} = (await doctor({cwd: path.join(dir, at)})).data;
1330
1334
  return {by: Object.fromEntries(checks.map(c => [c.id, c])), summary};
1331
1335
  }
1332
1336
 
@@ -1354,6 +1358,27 @@ describe('a configured integration that cannot load fails the gate', () => {
1354
1358
  SLOW,
1355
1359
  );
1356
1360
 
1361
+ it(
1362
+ 'passes in a workspace member whose configured integration is hoisted to the root',
1363
+ async () => {
1364
+ const {by} = await report(
1365
+ {
1366
+ 'package.json': JSON.stringify({name: 'root', private: true, workspaces: ['apps/*']}),
1367
+ ...CORE_STUB,
1368
+ ...widgets(),
1369
+ 'apps/web/package.json': '{"name":"web"}',
1370
+ 'apps/web/astryx.config.mjs': "export default { integrations: ['@acme/widgets'] };\n",
1371
+ },
1372
+ 'apps/web',
1373
+ );
1374
+ expect(by['configured-integrations'].status).toBe('pass');
1375
+ expect(by['configured-integrations'].message).toBe(
1376
+ '1 integration named in astryx.config loaded: @acme/widgets.',
1377
+ );
1378
+ },
1379
+ SLOW,
1380
+ );
1381
+
1357
1382
  it(
1358
1383
  'counts the package being authored when its own config names it',
1359
1384
  async () => {
@@ -40,6 +40,14 @@ export function integrationFluff(discovered: Parameters<typeof findFluff>[0]): P
40
40
  * read too
41
41
  */
42
42
  export function integrationStrayPointers(discovered: Parameters<typeof findStrayPointers>[0], integration?: any): Promise<import("./authoring-checks.type.mjs").StrayPointer[]>;
43
+ /**
44
+ * Each Astryx command a package's topics write with a package runner. A
45
+ * package whose topics cannot be discovered has none here: the other checks
46
+ * report topics that do not load.
47
+ * @param {any} integration a loaded integration
48
+ * @returns {Promise<import('../../foundation/discovery/runner-commands.mjs').RunnerCommand[]>}
49
+ */
50
+ export function integrationRunnerCommands(integration: any): Promise<import("../../foundation/discovery/runner-commands.mjs").RunnerCommand[]>;
43
51
  import { findCopiedPassages } from '../../foundation/discovery/copied-passages.mjs';
44
52
  import { findFluff } from '../../foundation/discovery/doc-fluff.mjs';
45
53
  import { findStrayPointers } from '../../foundation/discovery/stray-pointers.mjs';
@@ -2,7 +2,8 @@
2
2
 
3
3
  /**
4
4
  * @file The integration subject's access to the environment (INV21): reading
5
- * one package's component docs and sources with the project's own TypeScript.
5
+ * one package's component docs and sources with the project's own TypeScript,
6
+ * and its topics.
6
7
  *
7
8
  * @input a loaded integration and the directory the command runs in
8
9
  * @output the reports the integration checks attach to their results
@@ -14,9 +15,11 @@ import {
14
15
  forEachIntegrationDoc,
15
16
  integrationSourceForDoc,
16
17
  } from '../../foundation/discovery/component-discovery.mjs';
18
+ import {discoverIntegrationDocs} from '../../foundation/discovery/docs-discovery.mjs';
17
19
  import {comparePropDocs} from '../../foundation/discovery/prop-drift.mjs';
18
20
  import {findCopiedPassages} from '../../foundation/discovery/copied-passages.mjs';
19
21
  import {findFluff} from '../../foundation/discovery/doc-fluff.mjs';
22
+ import {findRunnerCommands} from '../../foundation/discovery/runner-commands.mjs';
20
23
  import {findStrayPointers} from '../../foundation/discovery/stray-pointers.mjs';
21
24
 
22
25
  /**
@@ -110,3 +113,20 @@ export async function integrationStrayPointers(discovered, integration) {
110
113
  }
111
114
  return findStrayPointers({...discovered, components});
112
115
  }
116
+
117
+ /**
118
+ * Each Astryx command a package's topics write with a package runner. A
119
+ * package whose topics cannot be discovered has none here: the other checks
120
+ * report topics that do not load.
121
+ * @param {any} integration a loaded integration
122
+ * @returns {Promise<import('../../foundation/discovery/runner-commands.mjs').RunnerCommand[]>}
123
+ */
124
+ export async function integrationRunnerCommands(integration) {
125
+ let discovered;
126
+ try {
127
+ discovered = await discoverIntegrationDocs(integration);
128
+ } catch {
129
+ return [];
130
+ }
131
+ return findRunnerCommands(discovered);
132
+ }
@@ -14,6 +14,7 @@ vi.mock('../../foundation/discovery/template-conflict-release.mjs', () => ({
14
14
  }));
15
15
  import * as fs from 'node:fs';
16
16
  import * as path from 'node:path';
17
+ import {validateIntegration} from './validate-integration.mjs';
17
18
  import {discoverCoreTemplates} from '../../foundation/discovery/template-adapter.mjs';
18
19
  import {discoverOwnedComponents} from '../../foundation/discovery/component-discovery.mjs';
19
20
  import {discoverBuiltinTopics} from '../../foundation/discovery/docs-discovery.mjs';
@@ -1331,3 +1332,222 @@ describe('links in component docs and topic descriptions', () => {
1331
1332
  ]);
1332
1333
  });
1333
1334
  });
1335
+
1336
+ describe('validateIntegration runner-command notes', () => {
1337
+ /** The runner-command notes, read back into their parts. */
1338
+ async function runnerNotes() {
1339
+ const {data} = await validateIntegration(undefined, {cwd: tmpDir});
1340
+ const notes = (data.notes ?? [])
1341
+ .filter((/** @type {any} */ note) => note.code === 'runner_command')
1342
+ .map((/** @type {any} */ note) => {
1343
+ const m =
1344
+ /^(\S+): "([^"]+)"(?: \(section "([^"]+)"\))? writes `([^`]+)`(?: \(line (\d+)\))?\./.exec(
1345
+ note.message,
1346
+ );
1347
+ return {
1348
+ file: m?.[1],
1349
+ topic: m?.[2],
1350
+ section: m?.[3] ?? null,
1351
+ command: m?.[4],
1352
+ line: m?.[5] ? Number(m[5]) : null,
1353
+ message: note.message,
1354
+ };
1355
+ });
1356
+ return {data, notes};
1357
+ }
1358
+
1359
+ function writeTopic(/** @type {string} */ text) {
1360
+ fs.writeFileSync(
1361
+ path.join(tmpDir, 'package.json'),
1362
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1363
+ );
1364
+ fs.writeFileSync(
1365
+ path.join(tmpDir, 'astryx.integration.mjs'),
1366
+ `export default {docs: './docs'};\n`,
1367
+ );
1368
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1369
+ const doc = {
1370
+ type: 'generic',
1371
+ name: 'acme-setup',
1372
+ title: 'Fixture',
1373
+ description: 'Fixture topic.',
1374
+ sections: [
1375
+ {
1376
+ title: 'Overview',
1377
+ content: [
1378
+ {type: 'prose', text},
1379
+ {type: 'code', lang: 'bash', code: 'npx @astryxdesign/cli init'},
1380
+ ],
1381
+ },
1382
+ ],
1383
+ };
1384
+ fs.writeFileSync(
1385
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1386
+ `export default ${JSON.stringify(doc)};\n`,
1387
+ );
1388
+ }
1389
+
1390
+ it('lists a runner command with its line and fix, and raises no issue', async () => {
1391
+ writeTopic('Check it with `pnpm exec astryx doctor` first.');
1392
+
1393
+ const {data, notes} = await runnerNotes();
1394
+ const [hit, ...rest] = notes;
1395
+
1396
+ expect(rest).toEqual([]);
1397
+ expect(hit).toMatchObject({
1398
+ topic: 'acme-setup',
1399
+ section: 'Overview',
1400
+ file: 'docs/acme-setup.doc.mjs',
1401
+ line: 1,
1402
+ command: 'pnpm exec astryx doctor',
1403
+ });
1404
+ expect(hit.message).toContain('Write `astryx doctor`');
1405
+ // A note only: no issue, so no exit changes on it.
1406
+ expect(
1407
+ data.issues.map((/** @type {any} */ issue) => issue.code),
1408
+ ).not.toContain('runner_command');
1409
+ });
1410
+
1411
+ it('puts each copy of a repeated command on its own line', async () => {
1412
+ fs.writeFileSync(
1413
+ path.join(tmpDir, 'package.json'),
1414
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1415
+ );
1416
+ fs.writeFileSync(
1417
+ path.join(tmpDir, 'astryx.integration.mjs'),
1418
+ `export default {docs: './docs'};\n`,
1419
+ );
1420
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1421
+ const doc = {
1422
+ type: 'generic',
1423
+ name: 'acme-setup',
1424
+ title: 'Fixture',
1425
+ description: 'Fixture topic.',
1426
+ sections: [
1427
+ {
1428
+ title: 'First',
1429
+ content: [{type: 'prose', text: 'Run `npx astryx doctor`.'}],
1430
+ },
1431
+ {
1432
+ title: 'Second',
1433
+ content: [{type: 'prose', text: 'Run `npx astryx doctor` again.'}],
1434
+ },
1435
+ {
1436
+ title: 'Third',
1437
+ content: [{type: 'prose', text: 'Or plain `npx astryx`.'}],
1438
+ },
1439
+ ],
1440
+ };
1441
+ fs.writeFileSync(
1442
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1443
+ `export default ${JSON.stringify(doc, null, 2)};\n`,
1444
+ );
1445
+ const lines = fs
1446
+ .readFileSync(path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'), 'utf8')
1447
+ .split('\n');
1448
+ const lineHolding = (/** @type {string} */ text) =>
1449
+ lines.findIndex(line => line.includes(text)) + 1;
1450
+
1451
+ const {notes} = await runnerNotes();
1452
+
1453
+ expect(
1454
+ notes.map((/** @type {any} */ each) => [
1455
+ each.section,
1456
+ each.line,
1457
+ each.command,
1458
+ ]),
1459
+ ).toEqual([
1460
+ ['First', lineHolding('Run `npx astryx doctor`.'), 'npx astryx doctor'],
1461
+ ['Second', lineHolding('again.'), 'npx astryx doctor'],
1462
+ ['Third', lineHolding('Or plain'), 'npx astryx'],
1463
+ ]);
1464
+ });
1465
+
1466
+ it('puts each copy of an identical one-line string on its own line', async () => {
1467
+ fs.writeFileSync(
1468
+ path.join(tmpDir, 'package.json'),
1469
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1470
+ );
1471
+ fs.writeFileSync(
1472
+ path.join(tmpDir, 'astryx.integration.mjs'),
1473
+ `export default {docs: './docs'};\n`,
1474
+ );
1475
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1476
+ const block = {type: 'code', lang: 'bash', code: 'npx astryx doctor'};
1477
+ const doc = {
1478
+ type: 'generic',
1479
+ name: 'acme-setup',
1480
+ title: 'Fixture',
1481
+ description: 'Fixture topic.',
1482
+ sections: [
1483
+ {title: 'First', content: [block]},
1484
+ {title: 'Second', content: [block]},
1485
+ ],
1486
+ };
1487
+ fs.writeFileSync(
1488
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1489
+ `export default ${JSON.stringify(doc, null, 2)};\n`,
1490
+ );
1491
+ const lines = fs
1492
+ .readFileSync(path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'), 'utf8')
1493
+ .split('\n');
1494
+ const copies = lines.flatMap((line, at) =>
1495
+ line.includes('"npx astryx doctor"') ? [at + 1] : [],
1496
+ );
1497
+
1498
+ const {notes} = await runnerNotes();
1499
+
1500
+ expect(copies).toHaveLength(2);
1501
+ expect(
1502
+ notes.map((/** @type {any} */ each) => [each.section, each.line]),
1503
+ ).toEqual([
1504
+ ['First', copies[0]],
1505
+ ['Second', copies[1]],
1506
+ ]);
1507
+ });
1508
+
1509
+ it("places a section's command on its own line when the section sits in a constant above the doc", async () => {
1510
+ fs.writeFileSync(
1511
+ path.join(tmpDir, 'package.json'),
1512
+ JSON.stringify({name: '@acme/widgets', version: '1.2.3'}),
1513
+ );
1514
+ fs.writeFileSync(
1515
+ path.join(tmpDir, 'astryx.integration.mjs'),
1516
+ `export default {docs: './docs'};\n`,
1517
+ );
1518
+ fs.mkdirSync(path.join(tmpDir, 'docs'), {recursive: true});
1519
+ fs.writeFileSync(
1520
+ path.join(tmpDir, 'docs', 'acme-setup.doc.mjs'),
1521
+ [
1522
+ "const install = {title: 'Install', content: [{type: 'prose', text: 'Run `npx astryx doctor`.'}]};",
1523
+ '',
1524
+ 'export default {',
1525
+ " type: 'generic',",
1526
+ " name: 'acme-setup',",
1527
+ " title: 'Fixture',",
1528
+ " description: 'Install first: `npx astryx doctor`.',",
1529
+ ' sections: [install],',
1530
+ '};',
1531
+ '',
1532
+ ].join('\n'),
1533
+ );
1534
+
1535
+ const {notes} = await runnerNotes();
1536
+
1537
+ expect(
1538
+ notes.map((/** @type {any} */ each) => [each.section, each.line]),
1539
+ ).toEqual(
1540
+ expect.arrayContaining([
1541
+ [null, 7],
1542
+ ['Install', 1],
1543
+ ]),
1544
+ );
1545
+ });
1546
+
1547
+ it('lists nothing for bare commands and the scoped install step', async () => {
1548
+ writeTopic('Check it with `astryx doctor` first.');
1549
+
1550
+ const {notes} = await runnerNotes();
1551
+ expect((await runnerNotes()).notes).toEqual([]);
1552
+ });
1553
+ });
@@ -10,7 +10,8 @@
10
10
  */
11
11
  export function validateLocalIntegration(cwd?: string): Promise<ValidateResult>;
12
12
  /**
13
- * Validate an INSTALLED integration package resolved from `cwd`/node_modules.
13
+ * Validate an INSTALLED integration package: the nearest `node_modules/<spec>`
14
+ * at or above `cwd`, resolved the way the project loads it.
14
15
  * @param {string} spec package name
15
16
  * @param {string} [cwd]
16
17
  * @returns {Promise<ValidateResult>}
@@ -12,7 +12,7 @@
12
12
  * - validateLocalIntegration(cwd) — the package rooted at `cwd` (nearest
13
13
  * package.json + sibling astryx.integration.{ts,mjs,js}).
14
14
  * - validateInstalledIntegration(spec, cwd) — an installed package resolved
15
- * from `cwd`/node_modules.
15
+ * from the node_modules chain at or above `cwd`.
16
16
  *
17
17
  * Both return a { found, name, version, manifestFile, issues } result. `found`
18
18
  * is false only for the no-manifest local case, which is guidance (not an
@@ -37,6 +37,7 @@ import {assertWithin} from '../../foundation/fs/path-safety.mjs';
37
37
  import {normalizeProviderId} from '../../foundation/identity/provider-identity.mjs';
38
38
  import {integrationDocTypes} from '../docs/_adapter.mjs';
39
39
  import {integrationDocConsistency} from '../../foundation/discovery/doc-consistency.mjs';
40
+ import {integrationRunnerCommands} from './_adapter.mjs';
40
41
  import {
41
42
  THEME_SLUG_RE,
42
43
  unreadThemeFolders,
@@ -52,7 +53,7 @@ import {
52
53
  import {
53
54
  findManifestPaths,
54
55
  loadManifest,
55
- resolvePackageDir,
56
+ resolveInstalledIntegrationDir,
56
57
  } from '../../foundation/integrations/integrations.mjs';
57
58
  // The on-disk contribution validators live in foundation: Project and
58
59
  // integration-warnings need them too, and foundation must not depend on api.
@@ -595,20 +596,21 @@ function packageJsonFieldIssues(pkg, pkgJsonPath) {
595
596
  }
596
597
 
597
598
  /**
598
- * Validate an INSTALLED integration package resolved from `cwd`/node_modules.
599
+ * Validate an INSTALLED integration package: the nearest `node_modules/<spec>`
600
+ * at or above `cwd`, resolved the way the project loads it.
599
601
  * @param {string} spec package name
600
602
  * @param {string} [cwd]
601
603
  * @returns {Promise<ValidateResult>}
602
604
  */
603
605
  export async function validateInstalledIntegration(spec, cwd = process.cwd()) {
604
- // resolvePackageDir throws (path-safety guard) on a spec with path segments,
606
+ // The resolver throws (path-safety guard) on a spec with path segments,
605
607
  // `..`, or an absolute path. Every other malformed input to this command
606
608
  // degrades into a diagnostic — so catch it here and return an issue instead
607
609
  // of letting the throw escape to a raw stack (human) / generic ERR_UNKNOWN
608
610
  // (--json).
609
611
  let packageDir;
610
612
  try {
611
- packageDir = resolvePackageDir(spec, cwd);
613
+ packageDir = resolveInstalledIntegrationDir(spec, cwd);
612
614
  } catch (err) {
613
615
  return {
614
616
  found: true,
@@ -646,6 +648,24 @@ export async function validateInstalledIntegration(spec, cwd = process.cwd()) {
646
648
  });
647
649
  }
648
650
 
651
+ /**
652
+ * The runner-command notes for a package's topics: each Astryx command a topic
653
+ * writes with a package runner, where the doc file is, and the bare command to
654
+ * write.
655
+ * @param {any} integration a loaded integration
656
+ * @returns {Promise<Array<{code: string, message: string}>>}
657
+ */
658
+ async function runnerCommandNotes(integration) {
659
+ const packageDir = integration.__packageDir;
660
+ return (await integrationRunnerCommands(integration)).map(each => ({
661
+ code: 'runner_command',
662
+ message:
663
+ typeof packageDir === 'string'
664
+ ? `${path.relative(packageDir, each.file).split(path.sep).join('/')}: ${each.message}`
665
+ : each.message,
666
+ }));
667
+ }
668
+
649
669
  /**
650
670
  * Unified entry: validate the LOCAL integration (no `pkg`) or an INSTALLED one
651
671
  * (`pkg` given) and return the `integration.validate` envelope. The no-manifest
@@ -696,6 +716,11 @@ export async function validateIntegration(pkg, options = {}) {
696
716
  ...(names ?? []).flatMap(each => each.notes),
697
717
  ]
698
718
  : [];
719
+ // Each Astryx command a topic writes with a package runner, as a
720
+ // `runner_command` note with its fix, the same way.
721
+ if (integration?.docs) {
722
+ notes.push(...(await runnerCommandNotes(integration)));
723
+ }
699
724
  return {
700
725
  type: 'integration.validate',
701
726
  data: {
@@ -47,7 +47,8 @@ export type ValidateIntegrationResponse = {
47
47
  * whose file name differs from its source only in letter case where the two
48
48
  * still pair (`source_without_component_doc`); and `doc_name_mismatch` and
49
49
  * `unknown_block_component` (see `docNames` and `blockComponents`); they
50
- * become warnings in the next minor release
50
+ * become warnings in the next minor release; and `runner_command`, an
51
+ * Astryx command a topic writes with a package runner
51
52
  */
52
53
  data: {
53
54
  validated: boolean;
@@ -51,7 +51,8 @@
51
51
  * whose file name differs from its source only in letter case where the two
52
52
  * still pair (`source_without_component_doc`); and `doc_name_mismatch` and
53
53
  * `unknown_block_component` (see `docNames` and `blockComponents`); they
54
- * become warnings in the next minor release
54
+ * become warnings in the next minor release; and `runner_command`, an
55
+ * Astryx command a topic writes with a package runner
55
56
  */
56
57
 
57
58
  /**
@@ -62,7 +62,7 @@ export const doc = {
62
62
  {
63
63
  type: 'integration.validate',
64
64
  description:
65
- 'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message} information that fails nothing, such as `invalid_cli_command` for a `cliCommand` that was ignored as malformed, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed).',
65
+ 'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message} information that fails nothing, such as `invalid_cli_command` for a `cliCommand` that was ignored as malformed, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. A `runner_command` note lists each Astryx command a topic writes with a package runner, with its file, line and the bare command to write. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed).',
66
66
  },
67
67
  ],
68
68
  examples: [
@@ -6,6 +6,7 @@
6
6
  * Built once per gathered catalog.
7
7
  */
8
8
 
9
+ import {createHash} from 'node:crypto';
9
10
  import {DOMAINS, words, fold, nameWords} from './_query-words.mjs';
10
11
 
11
12
  /** @param {string[]} list @returns {Map<string, number>} */
@@ -57,6 +58,62 @@ export const entryId = c =>
57
58
  export function entryTable(all, cards) {
58
59
  const hit = tables.get(all);
59
60
  if (hit) return hit;
61
+ // Each search gathers a fresh candidate list, so the table is also kept by
62
+ // the text it is built from: an unchanged catalog reuses it.
63
+ const key = fingerprint(all, cards);
64
+ if (last && last.key === key) {
65
+ tables.set(all, last.table);
66
+ return last.table;
67
+ }
68
+ const built = buildTable(all, cards);
69
+ last = {key, table: built};
70
+ tables.set(all, built);
71
+ return built;
72
+ }
73
+
74
+ /** @type {{key: string, table: EntryTable} | null} */
75
+ let last = null;
76
+ /** @type {WeakMap<object, number>} */
77
+ const cardIds = new WeakMap();
78
+ let nextCardId = 0;
79
+
80
+ /**
81
+ * Everything the table reads from the catalog, hashed.
82
+ * @param {any[]} all
83
+ * @param {object} cards
84
+ * @returns {string}
85
+ */
86
+ function fingerprint(all, cards) {
87
+ if (!cardIds.has(cards)) cardIds.set(cards, nextCardId++);
88
+ const h = createHash('sha1');
89
+ h.update(String(cardIds.get(cards)));
90
+ for (const c of all) {
91
+ h.update(
92
+ JSON.stringify([
93
+ c.domain,
94
+ c.name,
95
+ c._topic,
96
+ c._section,
97
+ c._resultName,
98
+ c._package,
99
+ c.description,
100
+ c.keywords,
101
+ c.aliases,
102
+ c.titles,
103
+ (c.guidance ?? []).slice(0, 10),
104
+ (c.prose ?? []).slice(0, 4),
105
+ ]),
106
+ );
107
+ }
108
+ return h.digest('hex');
109
+ }
110
+
111
+ /**
112
+ * @param {any[]} all
113
+ * @param {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
114
+ * @returns {EntryTable}
115
+ */
116
+ function buildTable(all, cards) {
60
117
  /** @type {Map<string, any[]>} */
61
118
  const by = new Map();
62
119
  /** @type {Map<string, string>} each id's first package */
@@ -153,6 +210,5 @@ export function entryTable(all, cards) {
153
210
  idf.set(w, Math.log(1 + (n - d + 0.5) / (d + 0.5)));
154
211
  table.fields[f] = {post, idf, len, avg: len.reduce((a, b) => a + b, 0) / n};
155
212
  }
156
- tables.set(all, table);
157
213
  return table;
158
214
  }