Skip to content

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

TypeScript

fix(cli): use the resolved owner package for a component's plain-text import hint (#5294)

Andrii Skrebets4265195cd3e0
diff --git a/.changeset/cli-component-detail-import-hint-ownership.md b/.changeset/cli-component-detail-import-hint-ownership.md
new file mode 100644
index 0000000000..3ad3d2c191
--- /dev/null
+++ b/.changeset/cli-component-detail-import-hint-ownership.md
@@ -0,0 +1,9 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `astryx component <Name>`'s plain-text output always showed `import {Name} from '@astryxdesign/core/...'`, even for a component owned by an integration package. The JSON response already resolved the import against the correct owner, but the command's text formatter recomputed its own hint via the core-only resolver and ignored that value.
+
+The command now uses the already-resolved `import` field from the component's detail response, so the plain-text output matches the JSON output and shows the integration's own package.
+
+@andrskr
diff --git a/packages/cli/clients/cli/commands/component/index.mjs b/packages/cli/clients/cli/commands/component/index.mjs
index 5cc2cb195f..e2560d41bf 100644
--- a/packages/cli/clients/cli/commands/component/index.mjs
+++ b/packages/cli/clients/cli/commands/component/index.mjs
@@ -231,7 +231,7 @@ export function registerComponent(program) {
case 'component.detail': {
const resolvedName = (name || '').replace(/^XDS/, '');
- const importHint = resolveImportPath(coreDir, resolvedName);
+ const importHint = result.data.import;
const doc =
detail === 'brief'
? code(formatBrief(result.data, resolvedName, importHint, {themeData}))
diff --git a/packages/cli/clients/cli/commands/import-hint-correctness.test.mjs b/packages/cli/clients/cli/commands/import-hint-correctness.test.mjs
index 865d5ef11f..faa9f6046b 100644
--- a/packages/cli/clients/cli/commands/import-hint-correctness.test.mjs
+++ b/packages/cli/clients/cli/commands/import-hint-correctness.test.mjs
@@ -123,6 +123,94 @@ describe('import hint correctness', () => {
}
});
+ describe('integration-owned components show their own package as the import hint', () => {
+ /**
+ * @param {{exports?: Record<string, string>}} [opts]
+ * @returns {string} the fixture's project root (pass as runCli's cwd)
+ */
+ function createIntegrationFixture({exports: pkgExports} = {}) {
+ const fixtureDir = fs.mkdtempSync(
+ path.join(__dirname, '__import_hint_integration_'),
+ );
+
+ fs.mkdirSync(path.join(fixtureDir, 'packages'), {recursive: true});
+ fs.symlinkSync(coreDir, path.join(fixtureDir, 'packages', 'core'));
+ fs.writeFileSync(
+ path.join(fixtureDir, 'package.json'),
+ JSON.stringify({name: 'fixture-app', version: '1.0.0'}),
+ );
+ fs.writeFileSync(
+ path.join(fixtureDir, 'astryx.config.mjs'),
+ "export default { integrations: ['@test/widgets'] };",
+ );
+
+ const intDir = path.join(fixtureDir, 'node_modules', '@test', 'widgets');
+ const compDir = path.join(intDir, 'components', 'Widget');
+ fs.mkdirSync(compDir, {recursive: true});
+ fs.writeFileSync(
+ path.join(intDir, 'package.json'),
+ JSON.stringify({
+ name: '@test/widgets',
+ version: '1.0.0',
+ ...(pkgExports ? {exports: pkgExports} : {}),
+ }),
+ );
+ fs.writeFileSync(
+ path.join(intDir, 'astryx.integration.mjs'),
+ "export default { components: './components' };",
+ );
+ fs.writeFileSync(
+ path.join(compDir, 'Widget.doc.mjs'),
+ "export const docs = {\n name: 'Widget',\n usage: { description: 'A test widget.' },\n props: [{ name: 'label', type: 'string', description: 'Label text' }],\n};\n",
+ );
+
+ return fixtureDir;
+ }
+
+ it('component <Name> (full) shows the integration package, not @astryxdesign/core', async () => {
+ const fixtureDir = createIntegrationFixture();
+ try {
+ const result = await runCli(['component', 'Widget'], fixtureDir);
+ expect(result.code).toBe(0);
+ expect(result.stdout).toContain("from '@test/widgets';");
+ expect(result.stdout).not.toContain('@astryxdesign/core');
+ } finally {
+ fs.rmSync(fixtureDir, {recursive: true, force: true});
+ }
+ });
+
+ it('component <Name> --detail brief also shows the integration package', async () => {
+ const fixtureDir = createIntegrationFixture();
+ try {
+ const result = await runCli(
+ ['component', 'Widget', '--detail', 'brief'],
+ fixtureDir,
+ );
+ expect(result.code).toBe(0);
+ expect(result.stdout).toContain('@test/widgets');
+ expect(result.stdout).not.toContain('@astryxdesign/core');
+ } finally {
+ fs.rmSync(fixtureDir, {recursive: true, force: true});
+ }
+ });
+
+ it('resolves to a subpath when the integration exports one for the component', async () => {
+ const fixtureDir = createIntegrationFixture({
+ exports: {
+ '.': './index.js',
+ './Widget': './components/Widget/index.js',
+ },
+ });
+ try {
+ const result = await runCli(['component', 'Widget'], fixtureDir);
+ expect(result.code).toBe(0);
+ expect(result.stdout).toContain("from '@test/widgets/Widget';");
+ } finally {
+ fs.rmSync(fixtureDir, {recursive: true, force: true});
+ }
+ });
+ });
+
describe('group names do NOT resolve to incorrect import paths', () => {
const groups = ['Checkbox', 'Radio', 'Chat', 'Tabs', 'Resizable', 'Utilities'];