An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): discover component blocks from the cwd component() is given (#6580)
Joey90a2012605a9
diff --git a/.changeset/cli-spec-component-blocks-cwd.md b/.changeset/cli-spec-component-blocks-cwd.mdnew file mode 100644index 0000000000..a730186550--- /dev/null+++ b/.changeset/cli-spec-component-blocks-cwd.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] The programmatic `component(name, {cwd, blocks: true})` now discovers blocks from the `cwd` it is given, as every other slice already does. It used to read blocks from the process working directory, so a caller pointing at another project got that directory's blocks, or none.++@josephfarinadiff --git a/packages/cli/api/component/component.mjs b/packages/cli/api/component/component.mjsindex ddfa3e0611..24d9a4f80d 100644--- a/packages/cli/api/component/component.mjs+++ b/packages/cli/api/component/component.mjs@@ -165,7 +165,7 @@ export async function component(name, options = {}) {: componentDetailShowcase(dirName, {cwd, name, resolve: false});}if (blocks) {- return componentDetailBlocks(dirName);+ return componentDetailBlocks(dirName, cwd);}const docs = await loadComponentDoc(owner.docPath, docOpts);if (props) return componentDetailProps(docs);@@ -183,7 +183,7 @@ export async function component(name, options = {}) {return componentDetailSource(dirName, null, {name, notFoundInPackage: packageScope});}if (blocks) {- return componentDetailBlocks(dirName);+ return componentDetailBlocks(dirName, cwd);}const docs = await loadComponentDoc(extDocPath, docOpts);if (props) return componentDetailProps(docs);@@ -224,7 +224,7 @@ export async function component(name, options = {}) {// ── Blocks mode ──────────────────────────────────────────────if (blocks) {- return componentDetailBlocks(dirName);+ return componentDetailBlocks(dirName, cwd);}// ── Sub-component scoping ────────────────────────────────────diff --git a/packages/cli/api/component/detail/blocks/blocks.mjs b/packages/cli/api/component/detail/blocks/blocks.mjsindex 67f050afc5..4eb856d1e3 100644--- a/packages/cli/api/component/detail/blocks/blocks.mjs+++ b/packages/cli/api/component/detail/blocks/blocks.mjs@@ -3,7 +3,7 @@/*** @file `component.detail.blocks` leaf — a component's example/related blocks.*- * @input a component name+ * @input a component name + the project cwd* @output the `component.detail.blocks` envelope (showcase, examples, related)* @position api/component/detail/blocks (projection leaf; routed by component.mjs)*/@@ -16,10 +16,11 @@ import {findRelatedBlocks} from '../../../template/template.mjs';* envelope, splitting them into the hero showcase, component-specific examples,* and broader related blocks.* @param {string} componentName+ * @param {string} cwd - project to discover blocks from; never the process cwd* @returns {Promise<import('../../component.type.mjs').ComponentDetailBlocksResponse>}*/-export async function componentDetailBlocks(componentName) {- const allBlocks = await findRelatedBlocks(componentName);+export async function componentDetailBlocks(componentName, cwd) {+ const allBlocks = await findRelatedBlocks(componentName, cwd);const toEntry = (/** @type {any} */ b) => ({name: b.dirName,displayName: b.name,diff --git a/packages/cli/clients/cli/commands/component-package.test.mjs b/packages/cli/clients/cli/commands/component-package.test.mjsindex 12598459f6..d3687c1121 100644--- a/packages/cli/clients/cli/commands/component-package.test.mjs+++ b/packages/cli/clients/cli/commands/component-package.test.mjs@@ -138,4 +138,15 @@ describe('component() with --package option', () => {expect(scoped.type).toBe('component.detail.blocks');expect(scoped.data).toEqual(unscoped.data);});++ // `cwd` is an explicit API input: --blocks must discover from it, as+ // --showcase does, not from the process working directory.+ it('--blocks discovers blocks from options.cwd, like --showcase', async () => {+ const showcase = await component('ProfileCard', {cwd: tmpDir, showcase: true});+ expect(showcase.data.source).toContain('ProfileCardShowcase');++ const blocks = await component('ProfileCard', {cwd: tmpDir, blocks: true});+ expect(blocks.type).toBe('component.detail.blocks');+ expect(blocks.data.showcase?.name).toBe('ProfileCardShowcase');+ });});