(installTarget: string, locator: Locator, {spec}: {spec: PackageManagerSpec})
| 206 | } |
| 207 | |
| 208 | export async function installVersion(installTarget: string, locator: Locator, {spec}: {spec: PackageManagerSpec}): Promise<InstallSpec> { |
| 209 | const locatorIsASupportedPackageManager = isSupportedPackageManagerLocator(locator); |
| 210 | const locatorReference = locatorIsASupportedPackageManager ? semverParse(locator.reference)! : parseURLReference(locator); |
| 211 | const {version, build} = locatorReference; |
| 212 | |
| 213 | const installFolder = path.join(installTarget, locator.name, version); |
| 214 | |
| 215 | try { |
| 216 | const corepackFile = path.join(installFolder, `.corepack`); |
| 217 | const corepackContent = await fs.promises.readFile(corepackFile, `utf8`); |
| 218 | |
| 219 | const corepackData = JSON.parse(corepackContent); |
| 220 | |
| 221 | debugUtils.log(`Reusing ${locator.name}@${locator.reference} found in ${installFolder}`); |
| 222 | |
| 223 | return { |
| 224 | hash: corepackData.hash as string, |
| 225 | location: installFolder, |
| 226 | bin: corepackData.bin, |
| 227 | }; |
| 228 | } catch (err) { |
| 229 | if (nodeUtils.isNodeError(err) && err.code !== `ENOENT`) { |
| 230 | throw err; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | let url: string; |
| 235 | let signatures: Array<{keyid: string, sig: string}>; |
| 236 | let integrity: string; |
| 237 | let binPath: string | null = null; |
| 238 | if (locatorIsASupportedPackageManager) { |
| 239 | url = spec.url.replace(`{}`, version); |
| 240 | if (process.env.COREPACK_NPM_REGISTRY) { |
| 241 | const registry = getRegistryFromPackageManagerSpec(spec); |
| 242 | if (registry.type === `npm`) { |
| 243 | ({tarball: url, signatures, integrity} = await npmRegistryUtils.fetchTarballURLAndSignature(registry.package, version)); |
| 244 | if (registry.bin) { |
| 245 | binPath = registry.bin; |
| 246 | } |
| 247 | } |
| 248 | url = url.replace( |
| 249 | npmRegistryUtils.DEFAULT_NPM_REGISTRY_URL, |
| 250 | () => process.env.COREPACK_NPM_REGISTRY!, |
| 251 | ); |
| 252 | } |
| 253 | } else { |
| 254 | url = decodeURIComponent(version); |
| 255 | if (process.env.COREPACK_NPM_REGISTRY && url.startsWith(npmRegistryUtils.DEFAULT_NPM_REGISTRY_URL)) { |
| 256 | url = url.replace( |
| 257 | npmRegistryUtils.DEFAULT_NPM_REGISTRY_URL, |
| 258 | () => process.env.COREPACK_NPM_REGISTRY!, |
| 259 | ); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | debugUtils.log(`Installing ${locator.name}@${version} from ${url}`); |
| 264 | const algo = build[0] ?? `sha512`; |
| 265 | const {tmpFolder, outputFile, hash: actualHash} = await download(installTarget, url, algo, binPath); |
nothing calls this directly
no test coverage detected
searching dependent graphs…