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

Function cachePlugin

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

Source from the content-addressed store, hash-verified

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