Skip to content

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

TypeScript

fix(cli): honest message when discover has no source (#6958)

Joey374f2de5f1c4
diff --git a/.changeset/discover-no-source-message.md b/.changeset/discover-no-source-message.md
new file mode 100644
index 0000000000..a604368638
--- /dev/null
+++ b/.changeset/discover-no-source-message.md
@@ -0,0 +1,11 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] When `discover --available` runs without a discover source, the CLI now
+explains what discover sources are and where to find Astryx packages on
+npm, instead of the misleading message that told users to add package names
+they had no way to find. The base `discover` with no integrations also gains
+a pointer to npm and the integrations docs.
+
+@AstryxBot
diff --git a/packages/cli/clients/cli/commands/discover.mjs b/packages/cli/clients/cli/commands/discover.mjs
index cfb142bf3a..3ec814fb32 100644
--- a/packages/cli/clients/cli/commands/discover.mjs
+++ b/packages/cli/clients/cli/commands/discover.mjs
@@ -268,19 +268,47 @@ export function registerDiscover(program) {
// No discover source: the list of what this project has, as always.
if (available === undefined) {
if (result.data.length === 0) {
- if (result.meta && result.meta.configured === false) {
+ if (options.available) {
+ // The user specifically asked for available packages but
+ // there is no source to answer from. Say so honestly.
+ emit(
+ text('No discover source is configured.'),
+ text(
+ [
+ 'Available integrations are listed by discover sources.',
+ 'A project can set one in astryx.config.mjs, and installed',
+ 'integrations can provide one.',
+ ].join(' '),
+ ),
+ text(
+ [
+ `Find Astryx packages on npm: npm search @astryxdesign`,
+ `Learn more: ${run} docs cli/integrations`,
+ ].join('\n'),
+ ),
+ );
+ } else if (result.meta && result.meta.configured === false) {
emit(
text('No integrations configured.'),
text('Add integration package names to astryx.config.mjs:'),
code(
"export default {\n integrations: ['@scope/your-integration'],\n};",
),
+ text(
+ [
+ `Find Astryx packages on npm: npm search @astryxdesign`,
+ `Learn more: ${run} docs cli/integrations`,
+ ].join('\n'),
+ ),
);
} else {
emit(
text(
'No external components found in configured integrations.',
),
+ text(
+ `Find more packages: ${run} discover --available (needs a discover source)`,
+ ),
);
}
break;
diff --git a/packages/cli/clients/cli/commands/discover.no-source.test.mjs b/packages/cli/clients/cli/commands/discover.no-source.test.mjs
new file mode 100644
index 0000000000..530d0c7030
--- /dev/null
+++ b/packages/cli/clients/cli/commands/discover.no-source.test.mjs
@@ -0,0 +1,75 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file `astryx discover` when no discover source is configured and no
+ * integration provides one.
+ *
+ * In a fresh public app with no integrations, `discover --available` used to
+ * print "No integrations configured. Add integration package names..." — a
+ * message that told users to add names they had no way to find. These tests
+ * pin the honest replacement.
+ */
+
+import {describe, it, expect, beforeEach, afterEach} from 'vitest';
+import * as fs from 'node:fs';
+import * as path from 'node:path';
+import * as os from 'node:os';
+import {runCli} from '../../../test-utils/run-cli.mjs';
+
+let tmpDir;
+let project;
+
+beforeEach(() => {
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-discover-nosource-'));
+ project = path.join(tmpDir, 'project');
+ fs.mkdirSync(project, {recursive: true});
+ fs.writeFileSync(
+ path.join(project, 'package.json'),
+ JSON.stringify({name: 'my-app', version: '1.0.0'}),
+ );
+});
+
+afterEach(() => {
+ fs.rmSync(tmpDir, {recursive: true, force: true});
+});
+
+describe('astryx discover --available with no source', () => {
+ it('explains what discover sources are and where to find packages', async () => {
+ const {status, stdout} = await runCli(['discover', '--available'], {
+ cwd: project,
+ });
+
+ expect(status).toBe(0);
+ expect(stdout).toContain('No discover source is configured.');
+ expect(stdout).toContain('discover sources');
+ expect(stdout).toContain('npm search @astryxdesign');
+ expect(stdout).toContain('docs cli/integrations');
+ // Must not show the old misleading message
+ expect(stdout).not.toContain('Add integration package names');
+ });
+
+ it('returns an empty list with configured=false in --json', async () => {
+ const {status, stdout} = await runCli(
+ ['discover', '--available', '--json'],
+ {cwd: project},
+ );
+
+ expect(status).toBe(0);
+ const result = JSON.parse(stdout);
+ expect(result.type).toBe('discover.list');
+ expect(result.data).toEqual([]);
+ expect(result.meta).toEqual({configured: false});
+ });
+});
+
+describe('astryx discover with nothing configured', () => {
+ it('shows the config snippet and a pointer to npm and docs', async () => {
+ const {status, stdout} = await runCli(['discover'], {cwd: project});
+
+ expect(status).toBe(0);
+ expect(stdout).toContain('No integrations configured.');
+ expect(stdout).toContain("integrations: ['@scope/your-integration']");
+ expect(stdout).toContain('npm search @astryxdesign');
+ expect(stdout).toContain('docs cli/integrations');
+ });
+});