-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolve.ts
More file actions
46 lines (40 loc) · 1.29 KB
/
resolve.ts
File metadata and controls
46 lines (40 loc) · 1.29 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
/**
* @fileoverview `resolveBazel()` — Bazel resolution entry point.
*
* Tries each source in order:
*
* 1. VFS — smol binary's embedded Bazel (if packed)
* 2. PATH — `bazelisk` (preferred) or `bazel` on the system PATH
*
* Returns `undefined` if neither source turned up Bazel. The caller
* (socket-cli or another consumer) decides what to do then — usually
* download Bazel into a managed cache and retry, or surface an
* actionable error.
*
* Memoized per-process: the first call walks the chain; subsequent
* calls return the cached promise.
*/
import { bazelFromPath } from './from-path'
import { bazelFromVfs } from './from-vfs'
import type { ResolvedBazel } from './types'
let _resolved: Promise<ResolvedBazel | undefined> | undefined
/* c8 ignore start - test-only escape hatch. */
export function _resetBazelResolution(): void {
_resolved = undefined
}
/* c8 ignore stop */
export async function doResolveBazel(): Promise<ResolvedBazel | undefined> {
const fromVfs = await bazelFromVfs()
/* c8 ignore start - smol Node binary only. */
if (fromVfs) {
return fromVfs
}
/* c8 ignore stop */
return bazelFromPath()
}
export function resolveBazel(): Promise<ResolvedBazel | undefined> {
if (!_resolved) {
_resolved = doResolveBazel()
}
return _resolved
}