MCPcopy
hub / github.com/codeaashu/claude-code / cachePlugin

Function cachePlugin

src/utils/plugins/pluginLoader.ts:911–1098  ·  view source on GitHub ↗
(
  source: PluginSource,
  options?: {
    manifest?: PluginManifest
  },
)

Source from the content-addressed store, hash-verified

909 * Cache a plugin from an external source
910 */
911export async function cachePlugin(
912 source: PluginSource,
913 options?: {
914 manifest?: PluginManifest
915 },
916): Promise<{ path: string; manifest: PluginManifest; gitCommitSha?: string }> {
917 const cachePath = getPluginCachePath()
918
919 await getFsImplementation().mkdir(cachePath)
920
921 const tempName = generateTemporaryCacheNameForPlugin(source)
922 const tempPath = join(cachePath, tempName)
923
924 let shouldCleanup = false
925 let gitCommitSha: string | undefined
926
927 try {
928 logForDebugging(
929 `Caching plugin from source: ${jsonStringify(source)} to temporary path ${tempPath}`,
930 )
931
932 shouldCleanup = true
933
934 if (typeof source === 'string') {
935 await installFromLocal(source, tempPath)
936 } else {
937 switch (source.source) {
938 case 'npm':
939 await installFromNpm(source.package, tempPath, {
940 registry: source.registry,
941 version: source.version,
942 })
943 break
944 case 'github':
945 await installFromGitHub(source.repo, tempPath, source.ref, source.sha)
946 break
947 case 'url':
948 await installFromGit(source.url, tempPath, source.ref, source.sha)
949 break
950 case 'git-subdir':
951 gitCommitSha = await installFromGitSubdir(
952 source.url,
953 tempPath,
954 source.path,
955 source.ref,
956 source.sha,
957 )
958 break
959 case 'pip':
960 throw new Error('Python package plugins are not yet supported')
961 default:
962 throw new Error(`Unsupported plugin source type`)
963 }
964 }
965 } catch (error) {
966 if (shouldCleanup && (await pathExists(tempPath))) {
967 logForDebugging(`Cleaning up failed installation at ${tempPath}`)
968 try {

Callers 3

cacheAndRegisterPluginFunction · 0.85
performPluginUpdateFunction · 0.85

Calls 15

getPluginCachePathFunction · 0.85
getFsImplementationFunction · 0.85
logForDebuggingFunction · 0.85
jsonStringifyFunction · 0.85
installFromLocalFunction · 0.85
installFromNpmFunction · 0.85
installFromGitHubFunction · 0.85
installFromGitFunction · 0.85
installFromGitSubdirFunction · 0.85
pathExistsFunction · 0.85
rmFunction · 0.85

Tested by

no test coverage detected