-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrom-download.ts
More file actions
78 lines (73 loc) · 2.44 KB
/
Copy pathfrom-download.ts
File metadata and controls
78 lines (73 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* @file `bazelFromDownload()` — fetches the upstream Bazel binary and returns a
* `ResolvedBazel` pointing at the cached executable. Bazel ships as a single
* executable per platform (no tar/zip wrapper), so this tier uses
* `downloadToolArchive` directly — no extraction step. The dlx downloader
* already chmods the file to 0o755 on POSIX, so the cached path is runnable
* as soon as it lands on disk. Returns `undefined` when Bazel doesn't publish
* a build for the target `platformArch` (no entry in `BAZEL_ASSET_MAP`).
* Trust-on-first-use: pass `integrity` from `external-tools.json` when
* available. Omit on first install; the underlying call computes the SRI and
* writes it into the dlx cache metadata so a follow-up `external-tools.json`
* update can pin it.
*/
import { downloadToolArchive } from '../from-download'
import { getBazelDownloadUrl } from './asset-names'
import type { BinaryDownloader } from '../from-download'
import type { HashSpec } from '../../integrity'
import type { ResolvedBazel } from './types'
export interface BazelFromDownloadOptions {
/**
* Bazel release version, e.g. `'7.4.1'`.
*/
version: string
/**
* Fleet platform-arch token, e.g. `'darwin-arm64'`.
*/
platformArch: string
/**
* Optional pinned integrity from `external-tools.json`.
*/
integrity?: HashSpec | undefined
/**
* Inject a custom downloader. Forwarded to the underlying
* `downloadToolArchive`. Defaults to dlx.
*/
downloader?: BinaryDownloader | undefined
}
/**
* Resolve Bazel by downloading the upstream binary. Returns the standard
* `ResolvedBazel` shape with `source: 'download'`.
*
* @example
* ;```typescript
* const bazel = await bazelFromDownload({
* version: '7.4.1',
* platformArch: 'darwin-arm64',
* })
* // → { path: '/.../bazel-7.4.1-darwin-arm64', source: 'download' }
* ```
*/
export async function bazelFromDownload(
options: BazelFromDownloadOptions,
): Promise<ResolvedBazel | undefined> {
const { downloader, integrity, platformArch, version } = {
__proto__: null,
...options,
} as typeof options
const url = getBazelDownloadUrl({ version, platformArch })
if (!url) {
return undefined
}
const archive = await downloadToolArchive({
url,
name: `bazel-${version}-${platformArch}`,
integrity,
downloader,
})
return {
path: archive.archivePath,
source: 'download',
integrity: archive.integrity,
}
}