-
-
Notifications
You must be signed in to change notification settings - Fork 263
/
index.js
53 lines (41 loc) · 1005 Bytes
/
index.js
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
47
48
49
50
51
52
53
import {execSync} from 'node:child_process';
function getElectronEnv() {
return JSON.parse(execSync(
`npx electron -p "JSON.stringify(process.versions)"`,
{
encoding: 'utf-8',
env: {
...process.env,
ELECTRON_RUN_AS_NODE: 1,
}
}
));
}
function createElectronEnvLoader() {
let inMemoryCache = null;
return () => {
if (inMemoryCache) {
return inMemoryCache;
}
return inMemoryCache = getElectronEnv();
}
}
const envLoader = createElectronEnvLoader();
export function getElectronVersions() {
return envLoader();
}
export function getChromeVersion() {
return getElectronVersions().chrome;
}
export function getChromeMajorVersion() {
return getMajorVersion(getChromeVersion());
}
export function getNodeVersion() {
return getElectronVersions().node;
}
export function getNodeMajorVersion() {
return getMajorVersion(getNodeVersion());
}
function getMajorVersion(version) {
return parseInt(version.split('.')[0]);
}