-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrom-path.ts
More file actions
27 lines (23 loc) · 883 Bytes
/
Copy pathfrom-path.ts
File metadata and controls
27 lines (23 loc) · 883 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
/**
* @file `jreFromPath()` — looks for `java` (or `java.exe`) on the system PATH
* via socket-lib's `which`. Returns the resolved- shape object if found;
* otherwise `undefined`. Derives `javaHome` by walking up two directories
* from the resolved `java` path (`<javaHome>/bin/java`). That's the JDK/JRE
* convention every distribution follows.
*/
import path from 'node:path'
import { which } from '../../bin/which'
import type { ResolvedJre } from './types'
export async function jreFromPath(): Promise<ResolvedJre | undefined> {
const javaOnPath = await which('java', { nothrow: true })
/* c8 ignore start - reached only when java is NOT on PATH. */
if (typeof javaOnPath !== 'string') {
return undefined
}
/* c8 ignore stop */
return {
javaPath: javaOnPath,
javaHome: path.dirname(path.dirname(javaOnPath)),
source: 'path',
}
}