-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrom-java-home.ts
More file actions
32 lines (29 loc) · 914 Bytes
/
from-java-home.ts
File metadata and controls
32 lines (29 loc) · 914 Bytes
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
/**
* @fileoverview `jreFromJavaHome()` — checks `$JAVA_HOME` for an
* existing JRE/JDK. Returns the resolved-shape object if the env var
* is set; otherwise `undefined`.
*
* Does NOT verify that the path actually contains a working `bin/java`
* — that's the caller's job (or the spawn will fail loudly at the
* use site). Keeping this leaf cheap means socket-cli can call it
* unconditionally without paying a stat per resolution.
*/
import path from 'node:path'
import process from 'node:process'
import type { ResolvedJre } from './types'
export function jreFromJavaHome(): ResolvedJre | undefined {
const javaHomeEnv = process.env['JAVA_HOME']
if (!javaHomeEnv) {
return undefined
}
const javaPath = path.join(
javaHomeEnv,
'bin',
process.platform === 'win32' ? 'java.exe' : 'java',
)
return {
javaPath,
javaHome: javaHomeEnv,
source: 'java-home',
}
}