-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcurrent-env.js
63 lines (57 loc) · 1.26 KB
/
current-env.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
54
55
56
57
58
59
60
61
62
63
const process = require('node:process')
const nodeOs = require('node:os')
function isMusl (file) {
return file.includes('libc.musl-') || file.includes('ld-musl-')
}
function os () {
return process.platform
}
function cpu () {
return process.arch
}
function libc (osName) {
// this is to make it faster on non linux machines
if (osName !== 'linux') {
return undefined
}
let family
const originalExclude = process.report.excludeNetwork
process.report.excludeNetwork = true
const report = process.report.getReport()
process.report.excludeNetwork = originalExclude
if (report.header?.glibcVersionRuntime) {
family = 'glibc'
} else if (Array.isArray(report.sharedObjects) && report.sharedObjects.some(isMusl)) {
family = 'musl'
}
return family
}
function devEngines (env = {}) {
const osName = env.os || os()
return {
cpu: {
name: env.cpu || cpu(),
},
libc: {
name: env.libc || libc(osName),
},
os: {
name: osName,
version: env.osVersion || nodeOs.release(),
},
packageManager: {
name: 'npm',
version: env.npmVersion,
},
runtime: {
name: 'node',
version: env.nodeVersion || process.version,
},
}
}
module.exports = {
cpu,
libc,
os,
devEngines,
}