-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect-platform-arch.ts
More file actions
45 lines (40 loc) · 1.79 KB
/
Copy pathdetect-platform-arch.ts
File metadata and controls
45 lines (40 loc) · 1.79 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
/**
* @file `getJreArch()` — resolves the current machine to a `platform-arch`
* string suitable for the Adoptium `ADOPTIUM_QUERY_MAP` keys (e.g.
* `darwin-arm64`, `linux-x64-musl`, `win-x64`). Self-contained: owns the
* Adoptium vocabulary end to end (Node's `win32` → `win`, an Alpine `-musl`
* suffix on Linux) rather than reusing the shared `getPlatformArch` /
* `detectLibc` — Adoptium ships a distinct `alpine-linux` channel, so the JRE
* key set differs from both the release-binary naming and
* python-build-standalone (see `getPythonArch`). Returns `undefined` on an
* unsupported platform/arch.
*/
import process from 'node:process'
import { getLibc } from '../../constants/platform'
import { ObjectFreeze } from '../../primordials/object'
// node platform → Adoptium platform segment. Node reports `win32`; the JRE keys
// use `win`. macOS/Linux pass through.
const NODE_PLATFORM_TO_JRE: Readonly<Record<string, string>> = ObjectFreeze({
__proto__: null,
darwin: 'darwin',
linux: 'linux',
win32: 'win',
}) as unknown as Readonly<Record<string, string>>
// node arch → Adoptium arch segment.
const NODE_ARCH_TO_JRE: Readonly<Record<string, string>> = ObjectFreeze({
__proto__: null,
arm64: 'arm64',
x64: 'x64',
}) as unknown as Readonly<Record<string, string>>
export function getJreArch(): string | undefined {
/* c8 ignore start - depends on process.platform/arch + libc probe. */
const platform = NODE_PLATFORM_TO_JRE[process.platform]
const arch = NODE_ARCH_TO_JRE[process.arch]
if (!platform || !arch) {
return undefined
}
// Adoptium ships a separate `alpine-linux` channel, keyed here as `-musl`.
const muslSuffix = platform === 'linux' && getLibc() === 'musl' ? '-musl' : ''
return `${platform}-${arch}${muslSuffix}`
/* c8 ignore stop */
}