MCPcopy
hub / github.com/claude-code-best/claude-code / installFromNpm

Function installFromNpm

src/utils/plugins/pluginLoader.ts:493–525  ·  view source on GitHub ↗
(
  packageName: string,
  targetPath: string,
  options: { registry?: string; version?: string } = {},
)

Source from the content-addressed store, hash-verified

491 * Install a plugin from npm using a global cache (exported for testing)
492 */
493export async function installFromNpm(
494 packageName: string,
495 targetPath: string,
496 options: { registry?: string; version?: string } = {},
497): Promise<void> {
498 const npmCachePath = join(getPluginsDirectory(), 'npm-cache')
499
500 await getFsImplementation().mkdir(npmCachePath)
501
502 const packageSpec = options.version
503 ? `${packageName}@${options.version}`
504 : packageName
505 const packagePath = join(npmCachePath, 'node_modules', packageName)
506 const needsInstall = !(await pathExists(packagePath))
507
508 if (needsInstall) {
509 logForDebugging(`Installing npm package ${packageSpec} to cache`)
510 const args = ['install', packageSpec, '--prefix', npmCachePath]
511 if (options.registry) {
512 args.push('--registry', options.registry)
513 }
514 const result = await execFileNoThrow('npm', args, { useCwd: false })
515
516 if (result.code !== 0) {
517 throw new Error(`Failed to install npm package: ${result.stderr}`)
518 }
519 }
520
521 await copyDir(packagePath, targetPath)
522 logForDebugging(
523 `Copied npm package ${packageName} from cache to ${targetPath}`,
524 )
525}
526
527/**
528 * Clone a git repository (exported for testing)

Callers 1

cachePluginFunction · 0.85

Calls 7

getPluginsDirectoryFunction · 0.85
getFsImplementationFunction · 0.85
pathExistsFunction · 0.85
copyDirFunction · 0.85
logForDebuggingFunction · 0.50
execFileNoThrowFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected