@astryxdesign/cli 0.7.3-canary.0bf23bd → 0.7.3-canary.0fd4f9e

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 (78) hide show
  1. package/README.md +63 -63
  2. package/api/build/_adapter.mjs +37 -25
  3. package/api/build/blocks/blocks.d.mts +68 -18
  4. package/api/build/blocks/blocks.mjs +475 -116
  5. package/api/build/blocks/blocks.test.mjs +191 -61
  6. package/api/build/blocks/blocks.weights.json +1 -1
  7. package/api/build/build.type.mjs +1 -1
  8. package/api/build/kit/answer.d.mts +9 -5
  9. package/api/build/kit/answer.mjs +123 -13
  10. package/api/build/kit/answer.test.mjs +73 -3
  11. package/api/build/kit/signals.d.mts +19 -0
  12. package/api/build/kit/signals.mjs +18 -7
  13. package/api/build/kit/weights.d.mts +8 -22
  14. package/api/build/kit/weights.mjs +87 -8
  15. package/api/build/kit/weights.test.mjs +96 -0
  16. package/api/build/tree.mjs +2 -1
  17. package/api/build/tree.test.mjs +37 -29
  18. package/api/component/_adapter.mjs +39 -5
  19. package/api/component/component-replacement.test.mjs +1 -0
  20. package/api/discover/_adapter.d.mts +1 -2
  21. package/api/discover/_adapter.mjs +6 -8
  22. package/api/discover/discover.mjs +0 -1
  23. package/api/docs/_adapter.mjs +4 -0
  24. package/api/doctor/_adapter.d.mts +33 -13
  25. package/api/doctor/_adapter.mjs +55 -25
  26. package/api/doctor/doctor.d.mts +23 -5
  27. package/api/doctor/doctor.mjs +81 -16
  28. package/api/doctor/doctor.test.mjs +58 -0
  29. package/api/integration/validate-integration-fixes.test.mjs +6 -5
  30. package/api/integration/validate-integration-gaps.test.mjs +12 -1
  31. package/api/integration/validate-integration.d.mts +4 -0
  32. package/api/integration/validate-integration.mjs +48 -7
  33. package/api/integration/validate-integration.type.d.mts +36 -5
  34. package/api/integration/validate-integration.type.mjs +27 -6
  35. package/api/integration/validateIntegration.doc.mjs +1 -1
  36. package/api/search/_entries.d.mts +11 -0
  37. package/api/search/_entries.mjs +35 -17
  38. package/api/search/_entries.test.mjs +48 -0
  39. package/api/search/_gather-templates.d.mts +0 -1
  40. package/api/search/_gather-templates.mjs +25 -0
  41. package/api/search/search.integration-block.test.mjs +100 -0
  42. package/api/template/template.mjs +5 -1
  43. package/assets/docs/tree/checks.doc.mjs +1 -1
  44. package/assets/docs/tree/ci-and-containers.doc.mjs +13 -0
  45. package/assets/docs/tree/versioning.doc.mjs +4 -0
  46. package/clients/cli/commands/doctor-integration.test.mjs +49 -1
  47. package/clients/cli/commands/doctor.doc.mjs +1 -1
  48. package/clients/cli/commands/doctor.mjs +10 -0
  49. package/clients/cli/commands/outside-project.test.mjs +99 -0
  50. package/clients/cli/commands/setup-nudge.test.mjs +17 -0
  51. package/clients/cli/index.mjs +25 -8
  52. package/foundation/agent-docs/agent-doc-state.d.mts +12 -0
  53. package/foundation/agent-docs/agent-doc-state.mjs +24 -2
  54. package/foundation/agent-docs/agent-docs.mjs +5 -5
  55. package/foundation/agent-docs/computer-agent-text.d.mts +39 -2
  56. package/foundation/agent-docs/computer-agent-text.mjs +135 -8
  57. package/foundation/agent-docs/computer-agent-text.test.mjs +99 -2
  58. package/foundation/integrations/cli-peer-version.d.mts +36 -0
  59. package/foundation/integrations/cli-peer-version.mjs +132 -0
  60. package/foundation/integrations/cli-peer-version.test.mjs +354 -0
  61. package/foundation/integrations/exports-subpaths.d.mts +57 -0
  62. package/foundation/integrations/exports-subpaths.mjs +113 -0
  63. package/foundation/integrations/public-imports.d.mts +118 -0
  64. package/foundation/integrations/public-imports.mjs +1769 -0
  65. package/foundation/integrations/public-imports.test.mjs +1793 -0
  66. package/foundation/release/cache.test.mjs +24 -21
  67. package/foundation/release/global-state.d.mts +8 -4
  68. package/foundation/release/global-state.mjs +4 -2
  69. package/foundation/release/notices.d.mts +62 -8
  70. package/foundation/release/notices.mjs +136 -25
  71. package/foundation/release/notices.test.mjs +21 -0
  72. package/foundation/response/response-types.doc.mjs +1 -1
  73. package/foundation/text/string-utils.d.mts +2 -1
  74. package/foundation/text/string-utils.mjs +16 -5
  75. package/foundation/text/suggest-order.d.mts +72 -0
  76. package/foundation/text/suggest-order.mjs +363 -0
  77. package/foundation/text/suggest-order.test.mjs +259 -0
  78. package/package.json +9 -9
@@ -65,8 +65,9 @@ import {typedEdges} from '../docs/node/node.mjs';
65
65
  import {detailView, indexView} from '../../foundation/doc-compiler/lenses.mjs';
66
66
  import {semverCompare, isValidSemver, satisfiesRange} from '../../foundation/env/semver.mjs';
67
67
  import {checkAppThemes, checkThemes} from './theme-checks.mjs';
68
- import {availableLine, upgradeLine} from '../../foundation/release/notices.mjs';
69
- import {alignCommand, addCliCommandFor, computerAgentTextState, installCommandFor, projectCoreVersion, projectHasOwnCli, computerIntegrationsOutside, computerIntegrationsToAdd, displayHomePath, outsideProject, releaseFacts} from './_adapter.mjs';
68
+ import {availableLine, RUN_FROM_PROJECT, upgradeLine} from '../../foundation/release/notices.mjs';
69
+ import {COMPUTER_COMMAND, COMPUTER_INSTALL_STEP} from '../../foundation/agent-docs/computer-agent-text.mjs';
70
+ import {alignCommand, addCliCommandFor, computerAgentTextState, installCommandFor, insideProjectElsewhere, projectCoreVersion, projectHasOwnCli, computerIntegrationsOutside, computerIntegrationsToAdd, displayHomePath, outsideProject, releaseFacts} from './_adapter.mjs';
70
71
 
71
72
  /**
72
73
  * @typedef {'pass'|'warn'|'fail'|'info'} DoctorStatus
@@ -286,15 +287,25 @@ export function checkVersionAlignment(ctx) {
286
287
  // the run (spec AST-081 FR2): say so, and how to add the CLI at Core's
287
288
  // version.
288
289
  if (ctx.ownCli === false) {
290
+ // The same comparison as the daily hint: the CLI against the Core the
291
+ // run reads (spec AST-081 FR2). The command adds the CLI in the project
292
+ // spec:AST-040 FR9 defines; from a folder inside it whose package.json
293
+ // is not the project's, or in no project, the fix says how to reach one.
294
+ const add = addCliCommandFor(ctx.cwd, coreVersion);
295
+ const matches = coreVersion === cliVersion;
296
+ const fix = add
297
+ ? `${matches ? 'To pin it for the team and CI' : 'To match'}, run: ${add.command}.`
298
+ : matches
299
+ ? null
300
+ : NO_PROJECT_FIX;
289
301
  return {
290
302
  id: 'version-alignment',
291
303
  label: '@astryxdesign/core <-> @astryxdesign/cli alignment',
292
- status: coreVersion === cliVersion ? 'info' : 'warn',
293
- message:
294
- coreVersion === cliVersion
295
- ? `This project has no Astryx CLI installed; CLI ${cliVersion}, the one you started, answered and matches its Core.`
296
- : `This project has no Astryx CLI installed; CLI ${cliVersion}, the one you started, answered while its Core is ${coreVersion}.`,
297
- fix: `${coreVersion === cliVersion ? 'To pin it for the team and CI' : 'To match'}, run: ${addCliCommandFor(ctx.cwd, coreVersion)}.`,
304
+ status: matches ? 'info' : 'warn',
305
+ message: matches
306
+ ? `This project has no Astryx CLI installed; CLI ${cliVersion}, the one you started, answered and matches its Core.`
307
+ : `This project has no Astryx CLI installed; CLI ${cliVersion}, the one you started, answered while its Core is ${coreVersion}.`,
308
+ ...(fix ? {fix} : {}),
298
309
  };
299
310
  }
300
311
  // The project's own CLI answers this project whatever its version
@@ -308,10 +319,31 @@ export function checkVersionAlignment(ctx) {
308
319
  message: drift
309
320
  ? `This project's CLI ${cliVersion} answers it, but its Core is ${coreVersion}: templates, docs, and agent text come from CLI ${cliVersion}, components from Core ${coreVersion}.`
310
321
  : `@astryxdesign/core v${coreVersion} is in step with @astryxdesign/cli v${cliVersion}.`,
311
- ...(drift ? {fix: `To align them, run: ${alignCommand(ctx.cwd, cliVersion, coreVersion)}.`} : {}),
322
+ ...(drift ? alignFix(ctx.cwd, cliVersion, coreVersion) : {}),
312
323
  };
313
324
  }
314
325
 
326
+ /**
327
+ * The fix for a CLI and Core on different releases, when a command fits.
328
+ * @param {string} cwd
329
+ * @param {string} cli
330
+ * @param {string} core
331
+ * @returns {{fix?: string}}
332
+ */
333
+ function alignFix(cwd, cli, core) {
334
+ // From a folder inside a project whose package.json is not the project's,
335
+ // aligning the project would leave this warning in place, so no command
336
+ // fits there (alignCommand returns none): point at the project instead.
337
+ const command = alignCommand(cwd, cli, core);
338
+ return {fix: command ? `To align them, run: ${command}.` : NO_PROJECT_FIX};
339
+ }
340
+
341
+ /**
342
+ * The fix where no install command fits: the folder's package.json is not an
343
+ * Astryx project's (spec AST-040 FR9), and adding there would make it one.
344
+ */
345
+ const NO_PROJECT_FIX = RUN_FROM_PROJECT;
346
+
315
347
  /**
316
348
  * Check 5 — astryx.config.mjs (if present) loads and has a valid shape.
317
349
  * @param {DoctorContext} ctx
@@ -1460,6 +1492,10 @@ export function checkCliCommand(ctx) {
1460
1492
  * each file of the computer-level agent text against this release's rendering
1461
1493
  * @property {import('../../foundation/env/user-settings.mjs').ComputerAgentTextSettings} [agentTextSettings]
1462
1494
  * the person's choices about the computer-level agent text
1495
+ * @property {string | null} [agentTextCommand] the command the skill file
1496
+ * tells agents to run, or null
1497
+ * @property {string | null} [agentTextInstall] the install step the skill
1498
+ * file records for when that command is not found, or null
1463
1499
  * @property {string} [cwd] the folder doctor runs in, for the printed fix
1464
1500
  * @property {import('../../foundation/release/notices.mjs').GlobalBehind | null} [globalBehind]
1465
1501
  * the CLI installed for the computer, when it is older than the newest
@@ -1472,7 +1508,7 @@ export function checkCliCommand(ctx) {
1472
1508
  * the newest update notice that did not print, and why (diagnostic only)
1473
1509
  * @property {{pid: number | null, host: string | null, since: number} | null} [stateLock]
1474
1510
  * who holds the state file's lock now (diagnostic only)
1475
- * @property {Array<import('../../foundation/env/search-path.mjs').SearchPathCommand & {upgrade?: string | null}>} [searchPathCommands]
1511
+ * @property {Array<import('../../foundation/env/search-path.mjs').SearchPathCommand & {upgrade?: string | null, runner?: boolean}>} [searchPathCommands]
1476
1512
  * every `astryx` on the search path, with the command that upgrades it
1477
1513
  * the `astryx` commands on the search path, in order
1478
1514
  * @property {import('../../foundation/integrations/computer-integrations.mjs').ComputerIntegrationCandidate[]} [computerIntegrations]
@@ -1559,6 +1595,7 @@ function checkFailureNote(failed) {
1559
1595
  const SKIP_REASONS = {
1560
1596
  'already-shown': 'it had already printed that day',
1561
1597
  'no-newer': 'no newer release was known',
1598
+ 'no-project': 'the folder belongs to no Astryx project, so no install command fits',
1562
1599
  };
1563
1600
 
1564
1601
  /**
@@ -1682,6 +1719,8 @@ export function checkComputerAgentText(ctx) {
1682
1719
  };
1683
1720
  }
1684
1721
  const entries = ctx.agentText ?? /** @type {NonNullable<typeof state>} */ (state).entries;
1722
+ const command = ctx.agentText ? (ctx.agentTextCommand ?? null) : /** @type {NonNullable<typeof state>} */ (state).command;
1723
+ const recorded = (ctx.agentText ? ctx.agentTextInstall : /** @type {NonNullable<typeof state>} */ (state).install) ?? null;
1685
1724
  const fix = `Run \`${formatCliCommand('astryx init --user', ctx.cwd)}\`.`;
1686
1725
  const [file, ...links] = entries;
1687
1726
  const home = (/** @type {{path: string}} */ e) => displayHomePath(e.path);
@@ -1710,9 +1749,29 @@ export function checkComputerAgentText(ctx) {
1710
1749
  };
1711
1750
  }
1712
1751
  const current = file.state === 'current';
1752
+ const status = `${current ? 'The computer-level agent text matches this release' : "The computer-level agent text differs from this release's"}: ${home(file)}.`;
1753
+ // The skill outlives the CLI it names when the home folder outlasts the
1754
+ // folder the CLI is installed in, as on a machine whose system folders
1755
+ // reset on restart. Reported only when no `astryx` command is on the search
1756
+ // path at all, apart from a package runner's own copy, which it puts first
1757
+ // only for the run it starts (the way back when the global CLI is gone).
1758
+ // Any other `astryx`, even one the scan cannot trace to the package, such
1759
+ // as the shim of Volta, asdf or mise, may well run the CLI, so doctor stays
1760
+ // quiet here and cli-on-path reports what it can; never a false "gone".
1761
+ // The reinstalled copy refreshes the text too.
1762
+ const rows = ctx.searchPathCommands;
1763
+ if (command === COMPUTER_COMMAND && rows && !rows.some(r => !r.runner)) {
1764
+ return {
1765
+ ...base,
1766
+ message: `${status} It tells agents to run \`${COMPUTER_COMMAND}\`, but no \`${COMPUTER_COMMAND}\` command is on the search path, so agents that read it find no CLI to run (as when a restart removes the CLI installed for the computer and keeps the home folder).${linkNote}`,
1767
+ fix: recorded
1768
+ ? `Run \`${recorded}\`, the step the skill names for when \`${COMPUTER_COMMAND}\` is not found.`
1769
+ : `Install it for the computer: \`${COMPUTER_INSTALL_STEP}\`.`,
1770
+ };
1771
+ }
1713
1772
  return {
1714
1773
  ...base,
1715
- message: `${current ? 'The computer-level agent text matches this release' : "The computer-level agent text differs from this release's"}: ${home(file)}.${linkNote}`,
1774
+ message: `${status}${linkNote}`,
1716
1775
  ...(!current || missing.length > 0 || dangling.length > 0 ? {fix} : {}),
1717
1776
  };
1718
1777
  }
@@ -1764,12 +1823,14 @@ export function checkComputerIntegrations(ctx) {
1764
1823
  * Inside a project, the integrations installed for the computer that the
1765
1824
  * project does not install: available, never used (spec AST-081 FR12).
1766
1825
  * Always info.
1767
- * @param {{installed: Set<string>, candidates: import('../../foundation/integrations/computer-integrations.mjs').ComputerIntegrationCandidate[], install: (name: string) => string}} input
1826
+ * @param {{installed: Set<string>, candidates: import('../../foundation/integrations/computer-integrations.mjs').ComputerIntegrationCandidate[], install: ((name: string) => string) | null, elsewhere?: boolean}} input
1768
1827
  * `install`: the command that adds a package with the project's package
1769
- * manager (read by the adapter)
1828
+ * manager (read by the adapter); null when the folder belongs to no
1829
+ * project, or `elsewhere`: its package.json is not the project's, where the
1830
+ * fix points at the project's folder
1770
1831
  * @returns {DoctorCheck}
1771
1832
  */
1772
- export function checkComputerIntegrationsAvailable({installed, candidates, install}) {
1833
+ export function checkComputerIntegrationsAvailable({installed, candidates, install, elsewhere = false}) {
1773
1834
  const available = candidates.filter(c => !installed.has(c.name));
1774
1835
  const base = {id: 'computer-integrations', label: 'Integrations installed for this computer', status: /** @type {const} */ ('info')};
1775
1836
  if (available.length === 0) {
@@ -1779,7 +1840,11 @@ export function checkComputerIntegrationsAvailable({installed, candidates, insta
1779
1840
  return {
1780
1841
  ...base,
1781
1842
  message: `Installed for this computer but not in this project, so not used here: ${available.map(c => c.name).join(', ')}.`,
1782
- fix: `To use one in this project, run ${available.map(c => `\`${add(c.name)}\``).join(' or ')}.`,
1843
+ ...(add
1844
+ ? {fix: `To use one in this project, run ${available.map(c => `\`${add(c.name)}\``).join(' or ')}.`}
1845
+ : elsewhere
1846
+ ? {fix: NO_PROJECT_FIX}
1847
+ : {}),
1783
1848
  };
1784
1849
  }
1785
1850
 
@@ -2038,7 +2103,7 @@ export async function runChecks(options = {}) {
2038
2103
  {
2039
2104
  const loadedNames = (project?.loadedIntegrations ?? []).map((/** @type {{name: string}} */ i) => i.name);
2040
2105
  const candidates = await computerIntegrationsToAdd(cwd, loadedNames);
2041
- checks.push(checkComputerIntegrationsAvailable({installed: new Set(loadedNames), candidates, install: installCommandFor(cwd)}));
2106
+ checks.push(checkComputerIntegrationsAvailable({installed: new Set(loadedNames), candidates, install: installCommandFor(cwd), elsewhere: insideProjectElsewhere(cwd)}));
2042
2107
  }
2043
2108
  checks.push(await checkAuthoringDocs(ctx));
2044
2109
  checks.push(await checkCliDocs(ctx));
@@ -31,7 +31,9 @@ import {
31
31
  checkIntegrationIssues,
32
32
  checkVersionAlignment,
33
33
  checkPackageManager,
34
+ checkComputerIntegrationsAvailable,
34
35
  } from './doctor.mjs';
36
+ import {installCommandFor} from './_adapter.mjs';
35
37
  import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
36
38
  import {Project} from '../../foundation/config/project.mjs';
37
39
 
@@ -223,7 +225,13 @@ describe("doctor — the project's own CLI and Core on different releases", () =
223
225
  ).version;
224
226
  /** @param {string} core */
225
227
  const at = core => {
228
+ // A project as spec:AST-040 FR9 defines it: its package.json declares
229
+ // an Astryx package.
226
230
  const dir = mkProject({
231
+ 'package.json': JSON.stringify({
232
+ name: 'app',
233
+ dependencies: {'@astryxdesign/core': core},
234
+ }),
227
235
  'package-lock.json': '{}',
228
236
  'node_modules/@astryxdesign/core/package.json': JSON.stringify({
229
237
  name: '@astryxdesign/core',
@@ -257,6 +265,10 @@ describe("doctor — the project's own CLI and Core on different releases", () =
257
265
 
258
266
  it('in a project with no CLI of its own, warns that the started copy answered and names the command that adds the CLI at Core', () => {
259
267
  const dir = mkProject({
268
+ 'package.json': JSON.stringify({
269
+ name: 'app',
270
+ dependencies: {'@astryxdesign/core': '0.0.1'},
271
+ }),
260
272
  'package-lock.json': '{}',
261
273
  'node_modules/@astryxdesign/core/package.json': JSON.stringify({
262
274
  name: '@astryxdesign/core',
@@ -279,6 +291,52 @@ describe("doctor — the project's own CLI and Core on different releases", () =
279
291
  });
280
292
  });
281
293
 
294
+ describe('the command that adds an integration installed for the computer', () => {
295
+ const app = () =>
296
+ mkProject({
297
+ 'package.json': JSON.stringify({
298
+ name: 'app',
299
+ dependencies: {'@astryxdesign/core': '0.7.0'},
300
+ }),
301
+ 'pnpm-lock.yaml': '',
302
+ 'tools/codegen/package.json': JSON.stringify({name: 'codegen'}),
303
+ });
304
+
305
+ it('adds it in the project, with its package manager', () => {
306
+ const dir = app();
307
+ expect(installCommandFor(dir)?.('@acme/a')).toBe('pnpm add @acme/a');
308
+ });
309
+
310
+ // A package.json that is not the project's (spec AST-040 FR9): a run
311
+ // there loads integrations from it, so a package added to the project
312
+ // stays unused there. No command; the fix points at the project.
313
+ it("from a tool folder inside the project, names no command and points at the project's folder", () => {
314
+ const dir = app();
315
+ expect(installCommandFor(path.join(dir, 'tools', 'codegen'))).toBeNull();
316
+ const c = checkComputerIntegrationsAvailable({
317
+ installed: new Set(),
318
+ candidates: [/** @type {any} */ ({name: '@acme/a'})],
319
+ install: null,
320
+ elsewhere: true,
321
+ });
322
+ expect(c.fix).toBe(
323
+ "Run this from the Astryx project's folder, or declare an Astryx package in this folder's package.json to make it a project of its own.",
324
+ );
325
+ });
326
+
327
+ it('in a folder that belongs to no project, names no command', () => {
328
+ const dir = mkProject({'package.json': JSON.stringify({name: 'tool'})});
329
+ expect(installCommandFor(dir)).toBeNull();
330
+ const c = checkComputerIntegrationsAvailable({
331
+ installed: new Set(),
332
+ candidates: [/** @type {any} */ ({name: '@acme/a'})],
333
+ install: null,
334
+ });
335
+ expect(c.status).toBe('info');
336
+ expect(c).not.toHaveProperty('fix');
337
+ });
338
+ });
339
+
282
340
  describe('checkCliCommand', () => {
283
341
  it('is informational when no integration declares a command', () => {
284
342
  const dir = mkProject({'pnpm-lock.yaml': ''});
@@ -37,6 +37,7 @@ const componentDoc = name =>
37
37
  `export default {type: 'component', name: '${name}', displayName: '${name}', usage: {description: '${name}.'}, props: []};\n`;
38
38
  /** @param {string} name */
39
39
  const componentSource = name => `export function ${name}() { return null; }\n`;
40
+ /** @param {string} name */
40
41
  const templateSource = name =>
41
42
  `export default function ${name}() { return null; }\n`;
42
43
  /** @param {string} name */
@@ -398,9 +399,9 @@ describe('unreachable_contribution fixes hold when followed', () => {
398
399
  const dir = writePackage({
399
400
  [MANIFEST]: manifest({templates: './templates'}),
400
401
  'templates/hero.doc.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
401
- 'templates/hero.tsx': componentSource('Hero'),
402
+ 'templates/hero.tsx': templateSource('Hero'),
402
403
  'src/blocks/Carousel.doc.mjs': `export default {type: 'block', name: 'Carousel', displayName: 'Carousel', aspectRatio: 1};\n`,
403
- 'src/blocks/Carousel.tsx': componentSource('Carousel'),
404
+ 'src/blocks/Carousel.tsx': templateSource('Carousel'),
404
405
  });
405
406
 
406
407
  const message = only(await issuesOf(dir), 'unreachable_contribution');
@@ -423,7 +424,7 @@ describe('unreachable_contribution fixes hold when followed', () => {
423
424
  [MANIFEST]: manifest({templates: './templates'}),
424
425
  'templates/.keep': '',
425
426
  'src/blocks/Carousel.doc.mjs': `export default {type: 'block', name: 'Carousel', displayName: 'Carousel', aspectRatio: 1};\n`,
426
- 'src/blocks/Carousel.tsx': componentSource('Carousel'),
427
+ 'src/blocks/Carousel.tsx': templateSource('Carousel'),
427
428
  });
428
429
 
429
430
  const message = only(await issuesOf(dir), 'unreachable_contribution');
@@ -687,9 +688,9 @@ describe('fixes never move a contribution onto a name its root already has', ()
687
688
  const dir = writePackage({
688
689
  [MANIFEST]: manifest({templates: './templates'}),
689
690
  'templates/hero.doc.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
690
- 'templates/hero.tsx': componentSource('Hero'),
691
+ 'templates/hero.tsx': templateSource('Hero'),
691
692
  'extra/hero.doc.mjs': `export default {type: 'page', name: 'hero', displayName: 'Hero'};\n`,
692
- 'extra/hero.tsx': componentSource('Hero'),
693
+ 'extra/hero.tsx': templateSource('Hero'),
693
694
  });
694
695
 
695
696
  const message = only(await issuesOf(dir), 'unreachable_contribution');
@@ -169,6 +169,7 @@ const writeNamed = files =>
169
169
  version: '1.0.0',
170
170
  exports: {
171
171
  './components/*': './components/*.tsx',
172
+ './templates/*': './templates/*.tsx',
172
173
  '.': './index.ts',
173
174
  },
174
175
  });
@@ -534,7 +535,14 @@ describe('block component names', () => {
534
535
  'export function Panel() { return null; }\nexport const UI = {};\nexport const Lib = {};\nexport function pick() { return null; }\n',
535
536
  ...files,
536
537
  },
537
- {name: '@acme/kit', version: '1.0.0', exports: {'.': './index.tsx'}},
538
+ {
539
+ name: '@acme/kit',
540
+ version: '1.0.0',
541
+ exports: {
542
+ '.': './index.tsx',
543
+ './templates/*': './templates/*.tsx',
544
+ },
545
+ },
538
546
  );
539
547
  /** @param {string} extra */
540
548
  const block = extra =>
@@ -572,6 +580,9 @@ describe('block component names', () => {
572
580
  ),
573
581
  'templates/account-card.tsx':
574
582
  "import {Helper} from 'some-lib';\nexport default function A() {\n return <Helper />;\n}\n",
583
+ // The package root the doc's derived import names exports the component.
584
+ 'index.tsx':
585
+ "export function Panel() { return null; }\nexport {AcmeWidget} from './components/AcmeWidget';\n",
575
586
  });
576
587
 
577
588
  expect(await allOf(dir)).toEqual([]);
@@ -83,6 +83,10 @@ export type ValidateResult = {
83
83
  */
84
84
  listed?: import("../../foundation/integrations/issue").AstryxIntegrationIssue[] | undefined;
85
85
  integration?: import("../../foundation/integrations/integrations.mjs").LoadedIntegration | undefined;
86
+ /**
87
+ * what the public-import check could not judge
88
+ */
89
+ publicImports?: import("./validate-integration.type.mjs").PublicImportsReport | undefined;
86
90
  };
87
91
  import { validateLoadedIntegration } from '../../foundation/integrations/validate-contributions.mjs';
88
92
  import { isListedIssue } from '../../foundation/integrations/validate-contributions.mjs';
@@ -70,6 +70,12 @@ import {
70
70
  rootProblem,
71
71
  } from '../../foundation/integrations/validate-contributions.mjs';
72
72
  import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
73
+ import {cliPeerVersionProblem} from '../../foundation/integrations/cli-peer-version.mjs';
74
+ import {publicImportIssues} from '../../foundation/integrations/public-imports.mjs';
75
+ import {runChoice} from '../../foundation/release/run-context.mjs';
76
+
77
+ /** The running CLI is outside the package's `@astryxdesign/cli` peer range. */
78
+ const CLI_PEER_VERSION = 'cli_peer_version';
73
79
 
74
80
  export {validateLoadedIntegration, isListedIssue};
75
81
 
@@ -92,6 +98,8 @@ export {validateLoadedIntegration, isListedIssue};
92
98
  * may not fail `--strict` until the next (architecture:cli-surface INV35);
93
99
  * `integration verify` still fails on a package.json npm cannot pack.
94
100
  * @property {import('../../foundation/integrations/integrations.mjs').LoadedIntegration} [integration]
101
+ * @property {import('./validate-integration.type.mjs').PublicImportsReport} [publicImports]
102
+ * what the public-import check could not judge
95
103
  */
96
104
 
97
105
  /**
@@ -278,13 +286,15 @@ async function findUnreachableContributionIssues(
278
286
  * Shared core for the local and installed entry points.
279
287
  * @param {string} packageDir
280
288
  * @param {{name: string, version?: string}} identity
281
- * @param {{scanUnreachable?: boolean}} [options]
289
+ * @param {{scanUnreachable?: boolean, own?: boolean, cwd?: string}} [options]
290
+ * `own`: the package is the one being authored in the current folder;
291
+ * `cwd`: the folder whose package manager an install command names
282
292
  * @returns {Promise<ValidateResult>}
283
293
  */
284
294
  async function validateAtPackageDir(
285
295
  packageDir,
286
296
  identity,
287
- {scanUnreachable = false} = {},
297
+ {scanUnreachable = false, own = false, cwd = packageDir} = {},
288
298
  ) {
289
299
  /** @type {Issue[]} */
290
300
  const issues = [];
@@ -426,6 +436,24 @@ async function validateAtPackageDir(
426
436
  issues.push(issue);
427
437
  }
428
438
  }
439
+ // The running CLI outside the package's `@astryxdesign/cli` peer range is a
440
+ // note for the same reason. It is built here, not among the contribution
441
+ // checks, so `integration verify` (which reports their layout findings)
442
+ // does not see it.
443
+ // The version an upgrade starts from is the project's: its own CLI's, or,
444
+ // with none, its Core's, as the project-upgrade notice takes it.
445
+ const choice = runChoice(cwd);
446
+ const from =
447
+ choice.inProject && choice.copy === 'starting' && choice.coreVersion
448
+ ? choice.coreVersion
449
+ : undefined;
450
+ const peerProblem = cliPeerVersionProblem(loaded, undefined, cwd, {
451
+ own,
452
+ from,
453
+ });
454
+ if (peerProblem) {
455
+ (result.notes ??= []).push({code: CLI_PEER_VERSION, message: peerProblem});
456
+ }
429
457
  if (loaded.themes && !rootProblem(loaded.themes))
430
458
  issues.push(...unreadThemeFolderIssues(packageDir, loaded));
431
459
  // What the docs say that no reader serves: a prop listed twice, an
@@ -444,6 +472,14 @@ async function validateAtPackageDir(
444
472
  packageDir,
445
473
  )),
446
474
  );
475
+ // What the package tells apps to import, read from source: package.json
476
+ // `exports`, docs, examples and template imports.
477
+ const publicImports = await publicImportIssues(packageDir, loaded);
478
+ issues.push(...publicImports.issues);
479
+ // Each finding is a note until the next minor makes it a warning.
480
+ if (publicImports.notes.length > 0)
481
+ (result.notes ??= []).push(...publicImports.notes);
482
+ result.publicImports = publicImports.report;
447
483
  if (scanUnreachable) {
448
484
  issues.push(
449
485
  ...(await findUnreachableContributionIssues(
@@ -507,7 +543,7 @@ export async function validateLocalIntegration(cwd = process.cwd()) {
507
543
  const result = await validateAtPackageDir(
508
544
  packageDir,
509
545
  {name, version: pkg.version},
510
- {scanUnreachable: true},
546
+ {scanUnreachable: true, own: true},
511
547
  );
512
548
  (result.listed ??= []).unshift(
513
549
  ...fields,
@@ -642,10 +678,11 @@ export async function validateInstalledIntegration(spec, cwd = process.cwd()) {
642
678
  };
643
679
  }
644
680
 
645
- return validateAtPackageDir(packageDir, {
646
- name: pkg.name ?? spec,
647
- version: pkg.version,
648
- });
681
+ return validateAtPackageDir(
682
+ packageDir,
683
+ {name: pkg.name ?? spec, version: pkg.version},
684
+ {cwd},
685
+ );
649
686
  }
650
687
 
651
688
  /**
@@ -744,6 +781,10 @@ export async function validateIntegration(pkg, options = {}) {
744
781
  ...(docTypes ? {docTypes} : {}),
745
782
  ...(docNames ? {docNames} : {}),
746
783
  ...(blockComponents ? {blockComponents} : {}),
784
+ // What the public-import check could not judge: listed, never failed on.
785
+ ...(result.found && result.publicImports
786
+ ? {publicImports: result.publicImports}
787
+ : {}),
747
788
  },
748
789
  };
749
790
  }
@@ -37,7 +37,9 @@ export type ValidateIntegrationResponse = {
37
37
  type: "integration.validate";
38
38
  /**
39
39
  * `notes`: information beside the issues that fails nothing, such as
40
- * `invalid_cli_command`, a `cliCommand` that was ignored as malformed, and
40
+ * `invalid_cli_command`, a `cliCommand` that was ignored as malformed;
41
+ * `cli_peer_version`, the running CLI outside the package's
42
+ * `@astryxdesign/cli` peer range; and
41
43
  * the package layout findings added after the last minor release, each with
42
44
  * its fix in the message: two docs for one component
43
45
  * (`duplicate_component_doc`), a root reached through a symlink
@@ -45,10 +47,11 @@ export type ValidateIntegrationResponse = {
45
47
  * (`unreadable_file`), a package.json without `name` or `version`
46
48
  * (`invalid_package_json`), no provider ID (`no_provider_id`), and a doc
47
49
  * whose file name differs from its source only in letter case where the two
48
- * still pair (`source_without_component_doc`); and `doc_name_mismatch` and
49
- * `unknown_block_component` (see `docNames` and `blockComponents`); they
50
- * become warnings in the next minor release; and `runner_command`, an
51
- * Astryx command a topic writes with a package runner
50
+ * still pair (`source_without_component_doc`); `doc_name_mismatch` and
51
+ * `unknown_block_component` (see `docNames` and `blockComponents`); and
52
+ * since 0.7.3 each public-import finding; they become warnings in the next
53
+ * minor release; and `runner_command`, an Astryx command a topic writes
54
+ * with a package runner
52
55
  */
53
56
  data: {
54
57
  validated: boolean;
@@ -62,6 +65,7 @@ export type ValidateIntegrationResponse = {
62
65
  docTypes?: DocTypesReport;
63
66
  docNames?: DocNamesReport;
64
67
  blockComponents?: BlockComponentsReport;
68
+ publicImports?: PublicImportsReport;
65
69
  };
66
70
  };
67
71
  /**
@@ -115,3 +119,30 @@ export type BlockComponentsReport = {
115
119
  reason: string;
116
120
  }>;
117
121
  };
122
+ /**
123
+ * An import the public-import check could not judge.
124
+ */
125
+ export type PublicImportUnchecked = {
126
+ /**
127
+ * package-relative file that names it
128
+ */
129
+ file: string;
130
+ /**
131
+ * the import specifier
132
+ */
133
+ specifier: string;
134
+ /**
135
+ * why it was not checked
136
+ */
137
+ reason: string;
138
+ };
139
+ /**
140
+ * The public-import check's report on validate's result: `unchecked` lists
141
+ * what it could not judge, never counted or failed on. Its findings are
142
+ * notes on the result (`data.notes`), so `findings` stays empty.
143
+ */
144
+ export type PublicImportsReport = {
145
+ status: "checked";
146
+ findings: never[];
147
+ unchecked: PublicImportUnchecked[];
148
+ };
@@ -39,9 +39,11 @@
39
39
  * "healthy" — the two are otherwise byte-identical.
40
40
  * @typedef {object} ValidateIntegrationResponse
41
41
  * @property {'integration.validate'} type
42
- * @property {{validated: boolean, name: string | null, version: string | null, issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[], notes?: Array<{code: string, message: string}>, docTypes?: DocTypesReport, docNames?: DocNamesReport, blockComponents?: BlockComponentsReport}} data
42
+ * @property {{validated: boolean, name: string | null, version: string | null, issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[], notes?: Array<{code: string, message: string}>, docTypes?: DocTypesReport, docNames?: DocNamesReport, blockComponents?: BlockComponentsReport, publicImports?: PublicImportsReport}} data
43
43
  * `notes`: information beside the issues that fails nothing, such as
44
- * `invalid_cli_command`, a `cliCommand` that was ignored as malformed, and
44
+ * `invalid_cli_command`, a `cliCommand` that was ignored as malformed;
45
+ * `cli_peer_version`, the running CLI outside the package's
46
+ * `@astryxdesign/cli` peer range; and
45
47
  * the package layout findings added after the last minor release, each with
46
48
  * its fix in the message: two docs for one component
47
49
  * (`duplicate_component_doc`), a root reached through a symlink
@@ -49,10 +51,11 @@
49
51
  * (`unreadable_file`), a package.json without `name` or `version`
50
52
  * (`invalid_package_json`), no provider ID (`no_provider_id`), and a doc
51
53
  * whose file name differs from its source only in letter case where the two
52
- * still pair (`source_without_component_doc`); and `doc_name_mismatch` and
53
- * `unknown_block_component` (see `docNames` and `blockComponents`); they
54
- * become warnings in the next minor release; and `runner_command`, an
55
- * Astryx command a topic writes with a package runner
54
+ * still pair (`source_without_component_doc`); `doc_name_mismatch` and
55
+ * `unknown_block_component` (see `docNames` and `blockComponents`); and
56
+ * since 0.7.3 each public-import finding; they become warnings in the next
57
+ * minor release; and `runner_command`, an Astryx command a topic writes
58
+ * with a package runner
56
59
  */
57
60
 
58
61
  /**
@@ -99,3 +102,21 @@
99
102
  */
100
103
 
101
104
  export {};
105
+
106
+ /**
107
+ * An import the public-import check could not judge.
108
+ * @typedef {object} PublicImportUnchecked
109
+ * @property {string} file package-relative file that names it
110
+ * @property {string} specifier the import specifier
111
+ * @property {string} reason why it was not checked
112
+ */
113
+
114
+ /**
115
+ * The public-import check's report on validate's result: `unchecked` lists
116
+ * what it could not judge, never counted or failed on. Its findings are
117
+ * notes on the result (`data.notes`), so `findings` stays empty.
118
+ * @typedef {object} PublicImportsReport
119
+ * @property {'checked'} status
120
+ * @property {never[]} findings
121
+ * @property {PublicImportUnchecked[]} unchecked
122
+ */
@@ -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. 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).',
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 `cli_peer_version` when the running CLI is outside the `@astryxdesign/cli` peer range of the package, 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). Since 0.7.3 each import apps cannot use is a note in `data.notes`, its fix inside the message, listed only: it does not fail this command or `integration check --strict`, and fails `--strict` from the next minor release. The codes are `component_import_not_exported`, `component_import_other_package`, `component_import_missing_name`, `example_import_not_exported`, `example_import_missing_name`, `template_import_not_exported`, `template_import_outside_root`, `template_private_import`, `template_import_missing_name` and `template_no_default_export`. When the manifest loads, `data.publicImports` is `{status: 'checked', findings: [], unchecked}`: `unchecked` lists each import the check could not judge, as {file, specifier, reason}, the reason starting `example <label>:` for an import in a component example: an `exports` target not built yet; a module whose export list cannot be read in full (CommonJS, or a declaration file it cannot read); a root import in a package with no `exports` (the root module `main` names is not read); every name an import (other than a component doc's own component) names that its module does not export, while a TypeScript file in the package has a `declare module` block for a relative path or the package's own name or a subpath of it, which can add names to that module (a `declare module` in a comment, `declare global`, a wildcard such as `'*.css'`, and another package's name do not count; a file whose text has `declare module` but that cannot be parsed counts); the same for every such name when the package has more than 5,000 files to search for that block; a deep path into build output not built yet in a package with no `exports`; a template import of Core when `@astryxdesign/core` is not installed beside the package (a `packages/core` of the workspace under another name does not count); every import of the package's own name when package.json has no `name` or a `name` that is not a bare package name; one entry for the whole check when package.json cannot be read; and an import of a subpath whose `exports` entry has only a `types` target, unless it is `import type`, every binding is an inline `type`, or every name it imports is a type its types file declares: a value import of a name that file does not declare as a type, a namespace or side-effect import, or any import when the types file cannot be read (it may be build output). `integration check` counts the unchecked as not compared; they never fail it.",
66
66
  },
67
67
  ],
68
68
  examples: [
@@ -13,6 +13,16 @@ export function entryTable(all: any[], cards: Record<string, {
13
13
  synonyms?: string[];
14
14
  props?: string[];
15
15
  }>): EntryTable;
16
+ /**
17
+ * @param {any[]} all
18
+ * @param {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
19
+ * @returns {EntryTable}
20
+ */
21
+ export function buildTable(all: any[], cards: Record<string, {
22
+ what?: string;
23
+ synonyms?: string[];
24
+ props?: string[];
25
+ }>): EntryTable;
16
26
  export function entryOf(table: {
17
27
  index: Map<string, number>;
18
28
  }, res: {
@@ -22,6 +32,7 @@ export function entryOf(table: {
22
32
  section?: string;
23
33
  }): number | undefined;
24
34
  export function entryId(c: any): string;
35
+ export const HASHED_FIELDS: readonly string[];
25
36
  export type EntryTable = {
26
37
  /**
27
38
  * every returnable `<domain>:<name>`, in code-point order