Skip to content

Commit 55e563b

Browse files
authored
fix: remove plugins.json check and update error handling in plugin search (#31)
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1 parent b707216 commit 55e563b

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/commands/plugin-search.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { z } from 'zod';
2-
import { getConfigPaths, loadPluginsConfig } from '../config/loader';
3-
import { fileExists } from '../helpers/fs';
2+
import { loadPluginsConfig } from '../config/loader';
43
import { resolveMarketplacePath } from '../helpers/git';
54
import { defaultIO } from '../helpers/io';
65
import { getAvailablePlugins, getMarketplaceType, loadMarketplaceManifest } from '../helpers/marketplace';
@@ -22,17 +21,15 @@ export async function pluginSearch(options: unknown): Promise<void> {
2221
const cmd = PluginSearchOptionsSchema.parse(options);
2322

2423
const cwd = cmd.cwd || process.cwd();
25-
const paths = getConfigPaths(cwd);
2624

2725
try {
28-
if (!(await fileExists(paths.plugins))) {
29-
const error = new Error("No plugins.json found. Run 'aipm init' first.");
30-
defaultIO.logError(error.message);
31-
throw error;
32-
}
33-
3426
const { config } = await loadPluginsConfig(cwd);
3527

28+
if (Object.keys(config.marketplaces).length === 0) {
29+
defaultIO.logInfo('No marketplaces configured. Add a marketplace first with: aipm marketplace add <name> <path>');
30+
return;
31+
}
32+
3633
const allPlugins: PluginInfo[] = [];
3734

3835
for (const [marketplaceName, marketplace] of Object.entries(config.marketplaces)) {

tests/commands/plugin-search.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
1+
import { afterEach, beforeEach, describe, expect, spyOn, test } from 'bun:test';
22
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
33
import { tmpdir } from 'node:os';
44
import { join } from 'node:path';
55
import { pluginSearch } from '../../src/commands/plugin-search';
6+
import * as claudeCodeConfig from '../../src/helpers/claude-code-config';
7+
import { defaultIO } from '../../src/helpers/io';
68

79
describe('plugin-search', () => {
810
let testDir: string;
@@ -277,12 +279,23 @@ describe('plugin-search', () => {
277279
});
278280

279281
describe('error handling', () => {
280-
test('should error if no plugins.json found', async () => {
282+
test('should log info if no marketplaces configured', async () => {
281283
const options = {
282284
cwd: testDir,
283285
};
284286

285-
await expect(pluginSearch(options)).rejects.toThrow('No plugins.json found');
287+
// Mock Claude Code as not installed to ensure no auto-discovered marketplaces
288+
const claudeSpy = spyOn(claudeCodeConfig, 'isClaudeCodeInstalled').mockResolvedValue(false);
289+
const infoSpy = spyOn(defaultIO, 'logInfo');
290+
291+
await pluginSearch(options);
292+
293+
expect(infoSpy).toHaveBeenCalledWith(
294+
'No marketplaces configured. Add a marketplace first with: aipm marketplace add <name> <path>',
295+
);
296+
297+
claudeSpy.mockRestore();
298+
infoSpy.mockRestore();
286299
});
287300

288301
test('should handle marketplaces with invalid paths', async () => {

0 commit comments

Comments
 (0)