An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): align direct localized doc loading (#5761)
Cindy Zhangf6daac029b02
diff --git a/.changeset/direct-loader-anatomy-fallback.md b/.changeset/direct-loader-anatomy-fallback.mdnew file mode 100644index 0000000000..f7755036dc--- /dev/null+++ b/.changeset/direct-loader-anatomy-fallback.md@@ -0,0 +1,9 @@+---+'@astryxdesign/cli': patch+---++[fix] Preserve anatomy when loading localized component docs directly++The validated component-doc loader now applies the same full-overlay fallback as the CLI loader, so omitted localized anatomy inherits the canonical structure while explicit localized anatomy still wins.++@cixzhangdiff --git a/packages/cli/foundation/discovery/component-loader.mjs b/packages/cli/foundation/discovery/component-loader.mjsindex 844a7620d7..47db469216 100644--- a/packages/cli/foundation/discovery/component-loader.mjs+++ b/packages/cli/foundation/discovery/component-loader.mjs@@ -51,7 +51,7 @@ export async function loadComponentDoc(/** @type {any} */const translation = mod[translationKey];if (translation.props || translation.components?.some((/** @type {any} */ c) => c.props)) {- return translation;+ return overlayComponentDoc(docs, translation);}return mergeTranslation(docs, translation);}diff --git a/packages/cli/foundation/discovery/component-loader.test.mjs b/packages/cli/foundation/discovery/component-loader.test.mjsindex a6d2479eb9..5c99760e94 100644--- a/packages/cli/foundation/discovery/component-loader.test.mjs+++ b/packages/cli/foundation/discovery/component-loader.test.mjs@@ -9,7 +9,8 @@*/import {describe, it, expect} from 'vitest';-import {mergeTranslation} from './component-loader.mjs';+import * as path from 'node:path';+import {loadComponentDoc, loadDocs, mergeTranslation} from './component-loader.mjs';/** Minimal HookDoc-shaped fixture with params + returns. */function hookDocs() {@@ -105,3 +106,37 @@ describe('mergeTranslation — component prop descriptions (regression)', () =>expect(merged.props.find(p => p.name === 'disabled').description).toBe('Disabled state.');});});++describe('loadComponentDoc — full localized doc overlays', () => {+ it('inherits canonical anatomy when docsZh omits it and matches loadDocs', async () => {+ const docPath = path.join(+ import.meta.dirname,+ '__fixtures__',+ 'component-accessibility-overlay.doc.mjs',+ );++ const direct = await loadComponentDoc(docPath, {zh: true});+ const cli = await loadDocs(docPath, {zh: true});++ expect(direct).toEqual(cli);+ expect(direct.usage.description).toBe('Translated full-doc description.');+ expect(direct.usage.anatomy).toEqual((await loadComponentDoc(docPath)).usage.anatomy);+ expect(direct.usage.bestPractices).toBeUndefined();+ });++ it('keeps explicit localized anatomy and matches loadDocs', async () => {+ const docPath = path.join(+ import.meta.dirname,+ '__fixtures__',+ 'component-anatomy-override.doc.mjs',+ );++ const direct = await loadComponentDoc(docPath, {zh: true});+ const cli = await loadDocs(docPath, {zh: true});+ const canonical = await loadComponentDoc(docPath);++ expect(direct).toEqual(cli);+ expect(direct.usage.anatomy).not.toEqual(canonical.usage.anatomy);+ expect(direct.usage.anatomy[0].name).toBe('文本区域');+ });+});