Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): list legacy package components with their own import (#6578)

Joey3263b9912d3a
diff --git a/.changeset/cli-spec-component-list-legacy-import.md b/.changeset/cli-spec-component-list-legacy-import.md
new file mode 100644
index 0000000000..823c00bd04
--- /dev/null
+++ b/.changeset/cli-spec-component-list-legacy-import.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `astryx component --list` now prints the right import for components from packages that publish docs through the legacy `astryx.docs` field. It used to show an `@astryxdesign/core` path for them. The JSON list entries now carry the same `import` that `astryx component <Name>` reports for each of those components.
+
+@josephfarina
diff --git a/packages/cli/api/component/component.doc.mjs b/packages/cli/api/component/component.doc.mjs
index 7f0e70fc13..1ca001bde4 100644
--- a/packages/cli/api/component/component.doc.mjs
+++ b/packages/cli/api/component/component.doc.mjs
@@ -109,7 +109,7 @@ export const doc = {
{
type: 'component.list',
description:
- "The catalog grouped by category. data.detail is the level ('names' | 'compact' | 'full') and data.components is the grouped map: names entries with name, package, and an optional canonical import for integrations; brief entries; or full ComponentDoc entries.",
+ "The catalog grouped by category. data.detail is the level ('names' | 'compact' | 'full') and data.components is the grouped map: names entries with name, package, and an optional canonical import for integration and legacy package components; brief entries; or full ComponentDoc entries.",
},
{
type: 'component.detail',
diff --git a/packages/cli/api/component/component.type.mjs b/packages/cli/api/component/component.type.mjs
index 841bd3645c..02e6d03925 100644
--- a/packages/cli/api/component/component.type.mjs
+++ b/packages/cli/api/component/component.type.mjs
@@ -52,13 +52,14 @@
/**
* A single entry in a `component.list` group at `detail: 'names'`. Pre-1.0 the
* list moved from bare strings to package-qualified objects so consumers can
- * disambiguate ownership (core vs. an integration package). Integration entries
- * carry `import` — the package-authored specifier; core entries omit it (the
- * specifier is derived from the component name by the renderer).
+ * disambiguate ownership (core vs. an integration package). Integration and
+ * legacy `astryx.docs` package entries carry `import` — the same specifier their
+ * `component.detail` reports; core entries omit it (the specifier is derived
+ * from the component name by the renderer).
* @typedef {object} ComponentListEntry
* @property {string} name
* @property {string} package - Owner package, e.g. '@astryxdesign/core' or '@acme/astryx-meta'.
- * @property {string} [import] - Import specifier; present for integration components, absent for core.
+ * @property {string} [import] - Import specifier; present for integration and legacy package components, absent for core.
*/
/**
diff --git a/packages/cli/api/component/list/list.mjs b/packages/cli/api/component/list/list.mjs
index b69e95edab..659dbadb0d 100644
--- a/packages/cli/api/component/list/list.mjs
+++ b/packages/cli/api/component/list/list.mjs
@@ -17,13 +17,14 @@ import {
discoverExternalComponentsGrouped,
discoverIntegrationComponents,
findComponentReadme,
+ findExternalComponentDoc,
resolveImportPath,
resolveIntegrationImportPath,
} from '../../../foundation/discovery/component-discovery.mjs';
import {discoverExternalPackages} from '../../../foundation/fs/paths.mjs';
import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
import {AstryxError} from '../../error.mjs';
-import {loadComponentDoc, loadIntegrationsSafely} from '../_adapter.mjs';
+import {loadComponentDoc, loadIntegrationsSafely, withOwnership} from '../_adapter.mjs';
/**
* @typedef {import('../component.type.mjs').ComponentListResponse} ComponentListResponse
@@ -31,6 +32,29 @@ import {loadComponentDoc, loadIntegrationsSafely} from '../_adapter.mjs';
* @typedef {import('../component.type.mjs').ComponentBriefEntry} ComponentBriefEntry
*/
+/**
+ * The import a legacy `pkg.astryx.docs` component's detail reports, derived the
+ * same way (`withOwnership`) so list and detail agree.
+ * @param {{name: string, docsDir: string}} ext
+ * @param {string} name
+ * @param {string} coreDir
+ * @param {{zh: boolean, lang: string|null}} docOpts
+ * @returns {Promise<string>}
+ */
+async function legacyImport(ext, name, coreDir, docOpts) {
+ const docPath = findExternalComponentDoc(ext.docsDir, name);
+ /** @type {import('../_adapter.mjs').LoadedComponentDoc} */
+ let docs = {};
+ if (docPath && docPath.endsWith('.doc.mjs')) {
+ try {
+ docs = await loadComponentDoc(docPath, docOpts);
+ } catch {
+ // Keep list resilient; validation owns malformed docs.
+ }
+ }
+ return withOwnership(docs, {package: ext.name, sourcePath: null}, name, coreDir).import;
+}
+
/**
* Build the `component.list` envelope. The list taxonomy is collapsed: all
* three detail levels emit ONE `component.list` type; the depth rides in
@@ -267,20 +291,24 @@ export async function componentList(
k => grouped[k].length > 1 || grouped[k][0] !== k,
);
- if (hasGroups) {
- for (const [group, members] of Object.entries(grouped)) {
- listData[`${group} (${ext.name})`] = members.map(n => ({
+ /** @param {string[]} names */
+ const entriesFor = names =>
+ Promise.all(
+ names.map(async n => ({
name: n,
package: ext.name,
- }));
+ import: await legacyImport(ext, n, coreDir, {zh, lang}),
+ })),
+ );
+
+ if (hasGroups) {
+ for (const [group, members] of Object.entries(grouped)) {
+ listData[`${group} (${ext.name})`] = await entriesFor(members);
}
} else {
const allComps = Object.values(grouped).flat().sort();
if (allComps.length > 0) {
- listData[`${ext.category} (${ext.name})`] = allComps.map(n => ({
- name: n,
- package: ext.name,
- }));
+ listData[`${ext.category} (${ext.name})`] = await entriesFor(allComps);
}
}
}
diff --git a/packages/cli/clients/cli/commands/component-package.test.mjs b/packages/cli/clients/cli/commands/component-package.test.mjs
index d3687c1121..9c734420ef 100644
--- a/packages/cli/clients/cli/commands/component-package.test.mjs
+++ b/packages/cli/clients/cli/commands/component-package.test.mjs
@@ -5,6 +5,7 @@ import * as fs from 'node:fs';
import * as path from 'node:path';
import * as os from 'node:os';
import {component} from '../../../api/component/component.mjs';
+import {runCli} from '../../../test-utils/run-cli.mjs';
// These tests create a minimal monorepo fixture with:
// - packages/core (symlinked to real @astryxdesign/core for loadDocs compatibility)
@@ -149,4 +150,20 @@ describe('component() with --package option', () => {
expect(blocks.type).toBe('component.detail.blocks');
expect(blocks.data.showcase?.name).toBe('ProfileCardShowcase');
});
+
+ // List and detail report one import for a legacy package component; the
+ // text list projects the JSON value instead of deriving a Core path.
+ it('the names list gives a legacy package component the import its detail reports', async () => {
+ const detail = await component('ProfileCard', {cwd: tmpDir});
+ const list = await component(undefined, {cwd: tmpDir, list: true});
+ const entry = Object.values(list.data.components)
+ .flat()
+ .find(e => e.name === 'ProfileCard' && e.package === '@test/ext');
+ expect(entry?.import).toBe(detail.data.import);
+
+ const text = await runCli(['component', '--list'], tmpDir);
+ expect(text.code).toBe(0);
+ expect(text.stdout).toContain(`name: ProfileCard\nimport: ${detail.data.import} [@test/ext]`);
+ expect(text.stdout).not.toMatch(/^import: +@astryxdesign\/core\S* +\[@test\/ext\]$/m);
+ });
});