-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrom-vfs.ts
More file actions
45 lines (40 loc) · 1.25 KB
/
Copy pathfrom-vfs.ts
File metadata and controls
45 lines (40 loc) · 1.25 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 `jreFromVfs()` — extracts the JRE directory tree from the smol binary's
* VFS and returns the resolved-shape pointing into the extracted directory.
* Uses the post-alignment `getSmolVfs()` API (matches upstream `node:vfs`).
* Returns `undefined` when:
*
* - Not running on a smol binary with the aligned binding
* - The binary has no SEA payload (`getSmolVfs() === undefined`)
* - The `jre` key doesn't exist in the payload
*/
import path from 'node:path'
import process from 'node:process'
import { getSmolVfs } from '../../smol/vfs'
import type { ResolvedJre } from './types'
/**
* Relative VFS key for the bundled JRE. Passed as a bare suffix to
* `vfs.extract()` — the binding handles prefix concatenation.
*/
export const JRE_VFS_KEY = 'jre'
export async function jreFromVfs(): Promise<ResolvedJre | undefined> {
const vfs = getSmolVfs()
if (!vfs) {
return undefined
}
/* c8 ignore start - smol Node binary only. */
if (!vfs.has(JRE_VFS_KEY)) {
return undefined
}
const javaHome = await vfs.extract(JRE_VFS_KEY)
return {
javaPath: path.join(
javaHome,
'bin',
process.platform === 'win32' ? 'java.exe' : 'java',
),
javaHome,
source: 'vfs',
}
/* c8 ignore stop */
}