-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor package management and update dependencies
Fixes #22 - Restructured command handling in `src/index.ts` for improved clarity and maintainability. - Removed unused files: `src/installed.ts`, `src/list.ts`, and `src/uninstall.ts`. - Updated `package.json` and `package-lock.json` to include new dependencies: `jest`, `ts-jest`, and `@types/jest`. - Modified `tsconfig.json` to include types for `node` and `jest`. - Enhanced package resolution logic in `src/utils/package-management.ts` to utilize a new `ConfigManager`. - Cleaned up type definitions by consolidating them in `src/types/package.js`. - Improved error handling and user prompts throughout the package management process.
- Loading branch information
1 parent
11ac798
commit 10edf25
Showing
21 changed files
with
4,502 additions
and
1,022 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
const config = { | ||
preset: 'ts-jest/presets/default-esm', | ||
testEnvironment: 'node', | ||
extensionsToTreatAsEsm: ['.ts'], | ||
moduleNameMapper: { | ||
'^(\\.{1,2}/.*)\\.js$': '$1', | ||
}, | ||
transform: { | ||
'^.+\\.tsx?$': [ | ||
'ts-jest', | ||
{ | ||
useESM: true, | ||
}, | ||
], | ||
}, | ||
testMatch: ['**/__tests__/**/*.test.ts'], | ||
testPathIgnorePatterns: ['/node_modules/', '/loaders/'], | ||
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'], | ||
}; | ||
|
||
export default config; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Package } from '../types/package.js'; | ||
import { installPackage as installPkg } from '../utils/package-management.js'; | ||
import inquirer from 'inquirer'; | ||
import chalk from 'chalk'; | ||
import { resolvePackages } from '../utils/package-resolver.js'; | ||
|
||
async function promptForRuntime(): Promise<'node' | 'python'> { | ||
const { runtime } = await inquirer.prompt<{ runtime: 'node' | 'python' }>([ | ||
{ | ||
type: 'list', | ||
name: 'runtime', | ||
message: 'What runtime does this package use?', | ||
choices: [ | ||
{ name: 'Node.js', value: 'node' }, | ||
{ name: 'Python', value: 'python' } | ||
] | ||
} | ||
]); | ||
return runtime; | ||
} | ||
|
||
function createUnknownPackage(packageName: string, runtime: 'node' | 'python'): Package { | ||
return { | ||
name: packageName, | ||
description: 'Unverified package', | ||
runtime, | ||
vendor: '', | ||
sourceUrl: '', | ||
homepage: '', | ||
license: '' | ||
}; | ||
} | ||
|
||
export async function installPackage(pkg: Package): Promise<void> { | ||
return installPkg(pkg); | ||
} | ||
|
||
export async function install(packageName: string): Promise<void> { | ||
const packages = resolvePackages(); | ||
const pkg = packages.find(p => p.name === packageName); | ||
|
||
if (!pkg) { | ||
console.warn(chalk.yellow(`Package ${packageName} not found in the curated list.`)); | ||
|
||
const { proceedWithInstall } = await inquirer.prompt<{ proceedWithInstall: boolean }>([ | ||
{ | ||
type: 'confirm', | ||
name: 'proceedWithInstall', | ||
message: `Would you like to try installing ${packageName} anyway? This package hasn't been verified.`, | ||
default: false | ||
} | ||
]); | ||
|
||
if (proceedWithInstall) { | ||
console.log(chalk.cyan(`Proceeding with installation of ${packageName}...`)); | ||
|
||
// Prompt for runtime for unverified packages | ||
const runtime = await promptForRuntime(); | ||
|
||
// Create a basic package object for unverified packages | ||
const unknownPkg = createUnknownPackage(packageName, runtime); | ||
await installPkg(unknownPkg); | ||
} else { | ||
console.log('Installation cancelled.'); | ||
process.exit(1); | ||
} | ||
return; | ||
} | ||
|
||
await installPkg(pkg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import inquirer from 'inquirer'; | ||
import chalk from 'chalk'; | ||
import { displayPackageDetailsWithActions } from '../utils/display.js'; | ||
import { resolvePackages } from '../utils/package-resolver.js'; | ||
import { ResolvedPackage } from '../types/package.js'; | ||
import AutocompletePrompt from 'inquirer-autocomplete-prompt'; | ||
import { createPackagePrompt, printPackageListHeader } from '../utils/ui.js'; | ||
import { handlePackageAction } from '../utils/package-actions.js'; | ||
|
||
inquirer.registerPrompt('autocomplete', AutocompletePrompt); | ||
|
||
export async function listInstalledPackages(): Promise<void> { | ||
// Get all packages with their resolved status | ||
const allPackages = resolvePackages(); | ||
|
||
// Filter for only installed packages | ||
const installedPackages = allPackages.filter(pkg => pkg.isInstalled); | ||
|
||
if (installedPackages.length === 0) { | ||
console.log(chalk.yellow('\nNo MCP servers are currently installed.')); | ||
return; | ||
} | ||
|
||
printPackageListHeader(installedPackages.length, 'installed'); | ||
|
||
const prompt = createPackagePrompt(installedPackages, { | ||
message: 'Search and select a package:' | ||
}); | ||
const answer = await inquirer.prompt<{ selectedPackage: ResolvedPackage }>([prompt]); | ||
|
||
if (!answer.selectedPackage) { | ||
return; | ||
} | ||
|
||
const action = await displayPackageDetailsWithActions(answer.selectedPackage); | ||
await handlePackageAction(answer.selectedPackage, action, { | ||
onUninstall: () => listInstalledPackages(), | ||
onBack: listInstalledPackages | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import chalk from 'chalk'; | ||
import inquirer from 'inquirer'; | ||
import { displayPackageDetailsWithActions } from '../utils/display.js'; | ||
import { resolvePackages } from '../utils/package-resolver.js'; | ||
import { ResolvedPackage } from '../types/package.js'; | ||
import AutocompletePrompt from 'inquirer-autocomplete-prompt'; | ||
import { createPackagePrompt, printPackageListHeader } from '../utils/ui.js'; | ||
import { handlePackageAction } from '../utils/package-actions.js'; | ||
|
||
// Register the autocomplete prompt | ||
inquirer.registerPrompt('autocomplete', AutocompletePrompt); | ||
|
||
export async function list() { | ||
try { | ||
const packages = resolvePackages(); | ||
printPackageListHeader(packages.length); | ||
|
||
const prompt = createPackagePrompt(packages, { showInstallStatus: true }); | ||
const answer = await inquirer.prompt<{ selectedPackage: ResolvedPackage }>([prompt]); | ||
|
||
if (!answer.selectedPackage) { | ||
return; | ||
} | ||
|
||
const action = await displayPackageDetailsWithActions(answer.selectedPackage); | ||
await handlePackageAction(answer.selectedPackage, action, { | ||
onBack: list | ||
}); | ||
} catch (error) { | ||
console.error(chalk.red('Error loading package list:')); | ||
console.error(chalk.red(error instanceof Error ? error.message : String(error))); | ||
process.exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import chalk from 'chalk'; | ||
import inquirer from 'inquirer'; | ||
import { resolvePackage } from '../utils/package-resolver.js'; | ||
import { uninstallPackage } from '../utils/package-management.js'; | ||
|
||
export async function uninstall(packageName?: string): Promise<void> { | ||
console.error("!"); | ||
try { | ||
// If no package name provided, show error | ||
if (!packageName) { | ||
console.error(chalk.red('Error: Package name is required')); | ||
console.log('Usage: mcp-get uninstall <package-name>'); | ||
process.exit(1); | ||
} | ||
|
||
// Resolve the package | ||
const pkg = resolvePackage(packageName); | ||
if (!pkg) { | ||
console.log(chalk.yellow(`Package ${packageName} not found.`)); | ||
return; | ||
} | ||
|
||
if (!pkg.isInstalled) { | ||
console.log(chalk.yellow(`Package ${packageName} is not installed.`)); | ||
return; | ||
} | ||
|
||
// Confirm uninstallation | ||
const { confirmUninstall } = await inquirer.prompt<{ confirmUninstall: boolean }>([{ | ||
type: 'confirm', | ||
name: 'confirmUninstall', | ||
message: `Are you sure you want to uninstall ${packageName}?`, | ||
default: false | ||
}]); | ||
|
||
if (!confirmUninstall) { | ||
console.log('Uninstallation cancelled.'); | ||
return; | ||
} | ||
|
||
// Perform uninstallation | ||
await uninstallPackage(packageName); | ||
console.log(chalk.green(`\nSuccessfully uninstalled ${packageName}`)); | ||
console.log(chalk.yellow('\nNote: Please restart Claude for the changes to take effect.')); | ||
|
||
} catch (error) { | ||
console.error(chalk.red('Failed to uninstall package:')); | ||
console.error(chalk.red(error instanceof Error ? error.message : String(error))); | ||
process.exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.