-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
65 lines (56 loc) · 2.04 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
/*! arch. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
var cp = require('child_process')
var fs = require('fs')
var path = require('path')
/**
* Returns the operating system's CPU architecture. This is different than
* `process.arch` or `os.arch()` which returns the architecture the Node.js (or
* Electron) binary was compiled for.
*/
module.exports = function arch () {
/**
* The running binary is 64-bit, so the OS is clearly 64-bit.
*/
if (process.arch === 'x64') {
return 'x64'
}
/**
* On macOS, we need to detect if x64 Node is running because the CPU is truly
* an Intel chip, or if it's running on Apple Silicon via Rosetta 2:
* https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment
*/
if (process.platform === 'darwin') {
var nativeArm = process.arch === 'arm64'
var rosettaArm = cp.execSync('sysctl -in sysctl.proc_translated', { encoding: 'utf8' }) === '1\n'
return (nativeArm || rosettaArm) ? 'arm64' : 'x64'
}
/**
* On Windows, the most reliable way to detect a 64-bit OS from within a 32-bit
* app is based on the presence of a WOW64 file: %SystemRoot%\SysNative.
* See: https://twitter.com/feross/status/776949077208510464
*/
if (process.platform === 'win32') {
var useEnv = false
try {
useEnv = !!(process.env.SYSTEMROOT && fs.statSync(process.env.SYSTEMROOT))
} catch (err) {}
var sysRoot = useEnv ? process.env.SYSTEMROOT : 'C:\\Windows'
// If %SystemRoot%\SysNative exists, we are in a WOW64 FS Redirected application.
var isWOW64 = false
try {
isWOW64 = !!fs.statSync(path.join(sysRoot, 'sysnative'))
} catch (err) {}
return isWOW64 ? 'x64' : 'x86'
}
/**
* On Linux, use the `getconf` command to get the architecture.
*/
if (process.platform === 'linux') {
var output = cp.execSync('getconf LONG_BIT', { encoding: 'utf8' })
return output === '64\n' ? 'x64' : 'x86'
}
/**
* If none of the above, assume the architecture is 32-bit.
*/
return 'x86'
}