An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): project parentDoc through the component.detail contract (#6575)
Joey9071e42111ca
diff --git a/.changeset/cli-spec-component-detail-parent-doc.md b/.changeset/cli-spec-component-detail-parent-doc.mdnew file mode 100644index 0000000000..b7999778b6--- /dev/null+++ b/.changeset/cli-spec-component-detail-parent-doc.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] `parentDoc` in `astryx component <Name> --json` is now a documented part of the `component.detail` response. The field appears when a sub-component such as `HStack` is scoped out of its parent's doc. It is in the published response type and the `component()` reference, and the text output now shows it as `parentDoc: Stack`.++@josephfarinadiff --git a/packages/cli/api/component/component.doc.mjs b/packages/cli/api/component/component.doc.mjsindex 0e1ecf3d24..91d9feccc5 100644--- a/packages/cli/api/component/component.doc.mjs+++ b/packages/cli/api/component/component.doc.mjs@@ -113,7 +113,7 @@ export const doc = {{type: 'component.detail',description:- "One component's authored ComponentDoc plus ownership metadata (owner package, import specifier, whether source is available).",+ "One component's authored ComponentDoc plus ownership metadata (owner package, import specifier, whether source is available). When the name is a sub-component documented in a parent's doc, the payload is scoped to it and parentDoc names that parent.",},{type: 'component.detail.props',diff --git a/packages/cli/api/component/component.type.mjs b/packages/cli/api/component/component.type.mjsindex e435147c1d..841bd3645c 100644--- a/packages/cli/api/component/component.type.mjs+++ b/packages/cli/api/component/component.type.mjs@@ -73,7 +73,14 @@* astryx --json component <name>* @typedef {object} ComponentDetailResponse* @property {'component.detail'} type- * @property {import('@astryxdesign/cli/authoring').ComponentDoc & ComponentOwnership} data+ * @property {import('@astryxdesign/cli/authoring').ComponentDoc & ComponentOwnership & ComponentDetailScope} data+ */++/**+ * Present only when the requested name is a sub-component documented inside a+ * parent's doc (e.g. `HStack` in the `Stack` doc); the payload is scoped to it.+ * @typedef {object} ComponentDetailScope+ * @property {string} [parentDoc] - Name of the parent doc the payload was scoped from, e.g. 'Stack'.*//**diff --git a/packages/cli/clients/cli/commands/component-resolution.test.mjs b/packages/cli/clients/cli/commands/component-resolution.test.mjsindex a1f65c5d91..bbb20fa0f9 100644--- a/packages/cli/clients/cli/commands/component-resolution.test.mjs+++ b/packages/cli/clients/cli/commands/component-resolution.test.mjs@@ -3,6 +3,7 @@import {describe, it, expect} from 'vitest';import {component} from '../../../api/component/component.mjs';import {findShowcase, findRelatedBlocks} from '../../../api/template/template.mjs';+import {runCli} from '../../../test-utils/run-cli.mjs';const CWD = {cwd: '.'};@@ -74,6 +75,26 @@ describe('component() sub-component scoping', () => {const result = await component('SideNav', CWD);expect(result.data.name).toBe('SideNav');});++ // `parentDoc` is part of the component.detail schema: the text view+ // projects it under the same key.+ it('component("HStack") names its parent doc in JSON and text', async () => {+ const result = await component('HStack', CWD);+ expect(result.data.parentDoc).toBe('Stack');++ const text = await runCli(['component', 'HStack'], process.cwd());+ expect(text.code).toBe(0);+ expect(text.stdout).toMatch(/^parentDoc: +Stack$/m);+ });++ it('component("Stack") carries no parentDoc in JSON or text', async () => {+ const result = await component('Stack', CWD);+ expect(result.data).not.toHaveProperty('parentDoc');++ const text = await runCli(['component', 'Stack'], process.cwd());+ expect(text.code).toBe(0);+ expect(text.stdout).not.toMatch(/^parentDoc:/m);+ });}, SCAN_TIMEOUT);// ─── Bug: findShowcase priority ─────────────────────────────────diff --git a/packages/cli/clients/cli/commands/component/index.mjs b/packages/cli/clients/cli/commands/component/index.mjsindex d94d84891b..92a6072ef5 100644--- a/packages/cli/clients/cli/commands/component/index.mjs+++ b/packages/cli/clients/cli/commands/component/index.mjs@@ -234,6 +234,7 @@ export function registerComponent(program) {case 'component.detail': {const resolvedName = (name || '').replace(/^XDS/, '');const importHint = result.data.import;+ if (result.data.parentDoc) emit(record(result.data, {fields: ['parentDoc']}));const doc =detail === 'brief'? code(formatBrief(result.data, resolvedName, importHint, {themeData}))