An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): make hook detail text a projection of its JSON (#6537)
Joey97dcfe6df5f8
diff --git a/.changeset/cli-spec-hook-text-projection.md b/.changeset/cli-spec-hook-text-projection.mdnew file mode 100644index 0000000000..f851a928df--- /dev/null+++ b/.changeset/cli-spec-hook-text-projection.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] `astryx hook <name>` text output no longer lists block templates that the `--json` envelope does not carry. It now names the related components and points to `astryx component <name> --blocks`, which returns their block templates as JSON.++@josephfarinadiff --git a/packages/cli/clients/cli/commands/hook.text-projection.test.mjs b/packages/cli/clients/cli/commands/hook.text-projection.test.mjsnew file mode 100644index 0000000000..8a9462f5b3--- /dev/null+++ b/packages/cli/clients/cli/commands/hook.text-projection.test.mjs@@ -0,0 +1,45 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file `astryx hook <name>` text is a projection of `hook.detail`: it shows+ * nothing the JSON envelope does not carry.+ */++import {describe, it, expect} from 'vitest';+import {runCli} from '../../../test-utils/run-cli.mjs';+import {findRelatedBlocks} from '../../../api/template/template.mjs';++const HOOK = 'useAnnounce';++describe('hook detail text projection', () => {+ it('prints no block templates that the JSON envelope lacks', async () => {+ const json = await runCli(['--json', 'hook', HOOK]);+ expect(json.status).toBe(0);+ const envelope = JSON.parse(json.stdout);+ expect(envelope.type).toBe('hook.detail');+ const related = envelope.data.relatedComponents;+ expect(related.length).toBeGreaterThan(0);++ const blockNames = [];+ for (const component of related) {+ for (const block of await findRelatedBlocks(component)) {+ blockNames.push(block.dirName);+ }+ }+ expect(blockNames.length).toBeGreaterThan(0);++ const text = await runCli(['hook', HOOK]);+ expect(text.status).toBe(0);+ const shownButNotInJson = blockNames.filter(+ name => text.stdout.includes(name) && !json.stdout.includes(name),+ );+ expect(shownButNotInJson).toEqual([]);+ });++ it('points at the JSON-backed block lookup for each related component', async () => {+ const text = await runCli(['hook', HOOK]);+ expect(text.stdout).toMatch(/component <name> --blocks/);+ expect(text.stdout).toContain('VisuallyHidden');+ expect(text.stdout).toContain('Toast');+ });+});diff --git a/packages/cli/clients/cli/commands/hook/index.mjs b/packages/cli/clients/cli/commands/hook/index.mjsindex 0a951c59ac..8fc7f65eb8 100644--- a/packages/cli/clients/cli/commands/hook/index.mjs+++ b/packages/cli/clients/cli/commands/hook/index.mjs@@ -20,7 +20,6 @@ import {defineCommand} from '../../lib/define-command.mjs';import {resultSet} from '../../../../foundation/debug/index.mjs';import {ERROR_CODES} from '../../../../foundation/response/error-codes.mjs';import {hook as hookApi} from '../../../../api/hook/hook.mjs';-import {findRelatedBlocks} from '../../../../api/template/template.mjs';import {doc as hookCommand} from '../hook.doc.mjs';import {doc as hookFn} from '../../../../api/hook/hook.doc.mjs';@@ -169,24 +168,15 @@ export function registerHook(program) {): formatHookFull(result.data);- // Show related block templates from relatedComponents- const relatedComps = result.data.relatedComponents || [];- /** @type {import('../../../../api/template/template.mjs').DiscoveredTemplate[]} */- const allBlocks = [];- for (const comp of relatedComps) {- const blocks = await findRelatedBlocks(comp);- for (const b of blocks) {- if (!allBlocks.some(existing => existing.dirName === b.dirName)) {- allBlocks.push(b);- }- }- }-+ // Text projects the envelope only. Block templates are JSON-backed+ // under `component <name> --blocks`.+ const related = result.data.relatedComponents ?? [];emit(code(doc),- allBlocks.length > 0 && section('Related block templates'),- allBlocks.length > 0 &&- records(allBlocks, {fields: ['dirName', 'description']}),+ related.length > 0 &&+ text(+ `Block templates: ${run} component <name> --blocks for ${related.join(', ')}`,+ ),);break;}