MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / cachePlugin

Function cachePlugin

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

Source from the content-addressed store, hash-verified

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

Callers 3

cacheAndRegisterPluginFunction · 0.85
performPluginUpdateFunction · 0.85

Calls 15

getPluginCachePathFunction · 0.85
getFsImplementationFunction · 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
readFileFunction · 0.85

Tested by

no test coverage detected