diff --git a/package.json b/package.json index 71f5500..606865f 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "test:list": "node --loader ts-node/esm src/index.ts list", "test:install": "node --loader ts-node/esm src/index.ts install", "test:installed": "node --loader ts-node/esm src/index.ts installed", + "test:update": "node --loader ts-node/esm src/index.ts update", "extract": "node --loader ts-node/esm src/extractors/modelcontextprotocol-extractor.ts", "test:uninstall": "node --loader ts-node/esm src/index.ts uninstall", "version:patch": "npm version patch", diff --git a/src/__tests__/auto-update.test.ts b/src/__tests__/auto-update.test.ts index b5e0cd5..45e7546 100644 --- a/src/__tests__/auto-update.test.ts +++ b/src/__tests__/auto-update.test.ts @@ -52,7 +52,7 @@ await jest.unstable_mockModule('fs', () => ({ const { updatePackage } = await import('../auto-update.js'); // Helper to create exec result -const createExecResult = (stdout: string): ExecResult => ({ stdout, stderr: '' }); +const createExecResult = (stdout: string, stderr: string = ''): ExecResult => ({ stdout, stderr }); describe('updatePackage', () => { beforeEach(() => { @@ -73,7 +73,7 @@ describe('updatePackage', () => { await updatePackage(); expect(mockExecPromise).toHaveBeenNthCalledWith(1, 'npm show @michaellatman/mcp-get version'); - expect(mockExecPromise).toHaveBeenNthCalledWith(2, 'npx --yes @michaellatman/mcp-get@latest'); + expect(mockExecPromise).toHaveBeenNthCalledWith(2, 'npm install -g @michaellatman/mcp-get@latest'); expect(console.log).toHaveBeenNthCalledWith(1, '\nA new version of mcp-get is available: 1.0.50 (current: 1.0.48)' @@ -82,6 +82,9 @@ describe('updatePackage', () => { 'Installing update...' ); expect(console.log).toHaveBeenNthCalledWith(3, + 'success' + ); + expect(console.log).toHaveBeenNthCalledWith(4, '✓ Update complete\n' ); }); diff --git a/src/auto-update.ts b/src/auto-update.ts index 68f487d..f29ae04 100644 --- a/src/auto-update.ts +++ b/src/auto-update.ts @@ -29,17 +29,31 @@ export async function updatePackage(silent: boolean = false): Promise { } try { - await execAsync('npx --yes @michaellatman/mcp-get@latest'); - if (!silent) console.log(chalk.green('✓ Update complete\n')); + const { stdout, stderr } = await execAsync('npm install -g @michaellatman/mcp-get@latest'); + if (!silent) { + if (stdout) console.log(stdout); + if (stderr) console.error(chalk.yellow('Update process output:'), stderr); + console.log(chalk.green('✓ Update complete\n')); + } } catch (installError: any) { - if (!silent) console.error(chalk.red('Failed to install update:'), installError.message); + if (!silent) { + console.error(chalk.red('Failed to install update:'), installError.message); + if (installError.stdout) console.log('stdout:', installError.stdout); + if (installError.stderr) console.error('stderr:', installError.stderr); + console.error(chalk.yellow('Try running the update manually with sudo:')); + console.error(chalk.cyan(' sudo npm install -g @michaellatman/mcp-get@latest')); + } return; } } else { if (!silent) console.log(chalk.green('✓ mcp-get is already up to date\n')); } } catch (error: any) { - if (!silent) console.error(chalk.red('Failed to check for updates:'), error.message); + if (!silent) { + console.error(chalk.red('Failed to check for updates:'), error.message); + if (error.stdout) console.log('stdout:', error.stdout); + if (error.stderr) console.error('stderr:', error.stderr); + } return; } }