(
source: PluginSource,
options?: {
manifest?: PluginManifest
},
)
| 910 | * Cache a plugin from an external source |
| 911 | */ |
| 912 | export 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 { |
no test coverage detected