MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / installFromNpm

Function installFromNpm

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

Source from the content-addressed store, hash-verified

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

Callers 1

cachePluginFunction · 0.85

Calls 6

getPluginsDirectoryFunction · 0.85
getFsImplementationFunction · 0.85
pathExistsFunction · 0.85
logForDebuggingFunction · 0.85
execFileNoThrowFunction · 0.85
copyDirFunction · 0.85

Tested by

no test coverage detected