(force: bool = False)
| 46 | |
| 47 | |
| 48 | def install_esbuild(force: bool = False) -> Path: |
| 49 | platform, arch = _platform_arch() |
| 50 | install_dir = INSTALL_ROOT / platform / arch / ESBUILD_VERSION |
| 51 | install_dir.mkdir(parents=True, exist_ok=True) |
| 52 | exe_name = "esbuild.exe" if platform == "win32" else "esbuild" |
| 53 | esbuild_path = install_dir / exe_name |
| 54 | done_file = install_dir / "done.txt" |
| 55 | if done_file.exists() and esbuild_path.exists() and not force: |
| 56 | return esbuild_path |
| 57 | |
| 58 | ARCHIVE_CACHE_DIR.mkdir(parents=True, exist_ok=True) |
| 59 | archive_path = ( |
| 60 | ARCHIVE_CACHE_DIR / f"esbuild-{platform}-{arch}-{ESBUILD_VERSION}.tgz" |
| 61 | ) |
| 62 | if force and archive_path.exists(): |
| 63 | archive_path.unlink() |
| 64 | |
| 65 | if not archive_path.exists(): |
| 66 | response = httpx.get( |
| 67 | _tarball_url(platform, arch), follow_redirects=True, timeout=120 |
| 68 | ) |
| 69 | response.raise_for_status() |
| 70 | archive_path.write_bytes(response.content) |
| 71 | |
| 72 | with tarfile.open(archive_path, mode="r:gz") as tf: |
| 73 | member_name = ( |
| 74 | f"package/{exe_name}" if platform == "win32" else "package/bin/esbuild" |
| 75 | ) |
| 76 | member = tf.getmember(member_name) |
| 77 | extracted = tf.extractfile(member) |
| 78 | if extracted is None: |
| 79 | raise RuntimeError(f"Could not extract {member_name} from {archive_path}") |
| 80 | esbuild_path.write_bytes(extracted.read()) |
| 81 | |
| 82 | if platform != "win32": |
| 83 | current_mode = esbuild_path.stat().st_mode |
| 84 | esbuild_path.chmod(current_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) |
| 85 | |
| 86 | done_file.write_text("ok\n", encoding="utf-8") |
| 87 | return esbuild_path |
| 88 | |
| 89 | |
| 90 | def _copy_tree(src: Path, dst: Path) -> None: |
no test coverage detected