MCPcopy Create free account
hub / github.com/vercel/vercel / downloadUvBinaryForTarget

Function downloadUvBinaryForTarget

packages/python/src/uv.ts:507–569  ·  view source on GitHub ↗
(
  cacheDir: string
)

Source from the content-addressed store, hash-verified

505 * SHA-256 is verified against {@link UV_BINARY_CHECKSUM}.
506 */
507export async function downloadUvBinaryForTarget(
508 cacheDir: string
509): Promise<string> {
510 const destDir = join(cacheDir, `uv-${UV_VERSION}-${UV_LINUX_TARGET}`);
511 const destBinary = join(destDir, 'uv');
512
513 // Return cached binary if it exists and is executable.
514 try {
515 await fs.promises.access(destBinary, fs.constants.X_OK);
516 debug(`Using cached uv binary at ${destBinary}`);
517 return destBinary;
518 } catch {
519 // Not cached -- continue to download.
520 }
521
522 const tarballName = `uv-${UV_LINUX_TARGET}.tar.gz`;
523 const url = `https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/${tarballName}`;
524
525 debug(`Downloading uv ${UV_VERSION} from ${url}`);
526 console.log(
527 `Downloading uv ${UV_VERSION} (linux x86_64) for runtime dependency installation...`
528 );
529
530 await fs.promises.mkdir(destDir, { recursive: true });
531 const tarballPath = join(destDir, tarballName);
532
533 await downloadUvTarball(url, tarballPath);
534
535 const actualHash = await sha256File(tarballPath);
536 if (actualHash !== UV_BINARY_CHECKSUM) {
537 await fs.promises.unlink(tarballPath).catch(() => {});
538 throw new NowBuildError({
539 code: 'RUNTIME_DEPENDENCY_INSTALLATION_FAILED',
540 message:
541 `checksum mismatch for ${tarballName}: ` +
542 `expected ${UV_BINARY_CHECKSUM}, got ${actualHash}`,
543 });
544 }
545
546 // Archive contains `uv-{target}/uv` (and uvx).
547 try {
548 await execa('tar', [
549 'xzf',
550 tarballPath,
551 '--strip-components=1',
552 '-C',
553 destDir,
554 ]);
555 } catch (err) {
556 throw new NowBuildError({
557 code: 'RUNTIME_DEPENDENCY_INSTALLATION_FAILED',
558 message: `could not extract ${tarballName}: ${
559 err instanceof Error ? err.message : String(err)
560 }`,
561 });
562 }
563
564 await fs.promises.chmod(destBinary, 0o755);

Calls 6

debugFunction · 0.90
downloadUvTarballFunction · 0.85
sha256FileFunction · 0.85
execaFunction · 0.85
unlinkMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected