generated from denorg/starter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod.ts
53 lines (46 loc) · 1.49 KB
/
mod.ts
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 * as path from "https://deno.land/[email protected]/path/mod.ts";
var decoder = new TextDecoder("utf-8");
/**
* Returns the operating system's CPU architecture.
*/
export default async function arch() {
/**
* The running binary is 64-bit, so the OS is clearly 64-bit.
*/
if (Deno.build.arch === 'x86_64') {
return 'x64'
}
/**
* All recent versions of Mac OS are 64-bit.
*/
if (Deno.build.os === 'darwin') {
return '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 (Deno.build.os === 'windows') {
let systemRoot = Deno.env.get("SystemRoot");
var sysRoot = systemRoot && Deno.statSync(systemRoot) ? systemRoot : 'C:\\Windows'
// If %SystemRoot%\SysNative exists, we are in a WOW64 FS Redirected application.
var isWOW64 = false
try {
isWOW64 = sysRoot ? !!Deno.statSync(path.join(sysRoot, 'sysnative')) : false
} catch (err) { }
return isWOW64 ? 'x64' : 'x86'
}
/**
* On Linux, use the `getconf` command to get the architecture.
*/
if (Deno.build.os === 'linux') {
var process = Deno.run({ cmd: ['getconf', 'LONG_BIT'], stdout: "piped" });
var output = decoder.decode(await process.output());
return output === '64\n' ? 'x64' : 'x86'
}
/**
* If none of the above, assume the architecture is 32-bit.
*/
return 'x86'
}