Skip to content

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

TypeScript

fix(cli): honor --source and --blocks for legacy --package lookups (#6577)

Joey7191bc1877d5
diff --git a/.changeset/cli-spec-component-legacy-package-flags.md b/.changeset/cli-spec-component-legacy-package-flags.md
new file mode 100644
index 0000000000..5222aeda65
--- /dev/null
+++ b/.changeset/cli-spec-component-legacy-package-flags.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `astryx component <Name> --package <pkg>` no longer ignores `--source` and `--blocks` when the package publishes docs through the legacy `astryx.docs` field. `--source` now fails with `ERR_NO_SOURCE`, and `--blocks` returns the blocks, the same answers as without `--package`. Before, both flags silently returned the plain doc.
+
+@josephfarina
diff --git a/packages/cli/api/component/component.mjs b/packages/cli/api/component/component.mjs
index 8e142c8c12..ddfa3e0611 100644
--- a/packages/cli/api/component/component.mjs
+++ b/packages/cli/api/component/component.mjs
@@ -178,6 +178,13 @@ export async function component(name, options = {}) {
}
const extDocPath = resolveLegacyExternalDoc(scoped.ext, dirName);
if (extDocPath) {
+ // Legacy packages ship docs, never source.
+ if (source) {
+ return componentDetailSource(dirName, null, {name, notFoundInPackage: packageScope});
+ }
+ if (blocks) {
+ return componentDetailBlocks(dirName);
+ }
const docs = await loadComponentDoc(extDocPath, docOpts);
if (props) return componentDetailProps(docs);
return componentDetail(docs, {package: scoped.ext.name, sourcePath: null}, dirName, coreDir);
diff --git a/packages/cli/clients/cli/commands/component-package.test.mjs b/packages/cli/clients/cli/commands/component-package.test.mjs
index 33ce5018c4..12598459f6 100644
--- a/packages/cli/clients/cli/commands/component-package.test.mjs
+++ b/packages/cli/clients/cli/commands/component-package.test.mjs
@@ -120,4 +120,22 @@ describe('component() with --package option', () => {
expect(result.data.source).toContain('ProfileCardShowcase');
expect(result.data.aspectRatio).toBeCloseTo(16 / 9);
});
+
+ // A legacy package ships docs only: --source and --blocks answer the same
+ // way scoped as unscoped, never falling back to the plain doc.
+ it('--package + --source reports the missing source, like the unscoped lookup', async () => {
+ await expect(
+ component('ProfileCard', {cwd: tmpDir, source: true}),
+ ).rejects.toMatchObject({code: 'ERR_NO_SOURCE'});
+ await expect(
+ component('ProfileCard', {cwd: tmpDir, package: '@test/ext', source: true}),
+ ).rejects.toMatchObject({code: 'ERR_NO_SOURCE'});
+ });
+
+ it('--package + --blocks returns the blocks, like the unscoped lookup', async () => {
+ const unscoped = await component('ProfileCard', {cwd: tmpDir, blocks: true});
+ const scoped = await component('ProfileCard', {cwd: tmpDir, package: '@test/ext', blocks: true});
+ expect(scoped.type).toBe('component.detail.blocks');
+ expect(scoped.data).toEqual(unscoped.data);
+ });
});