-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.ts
More file actions
66 lines (55 loc) · 1.36 KB
/
platform.ts
File metadata and controls
66 lines (55 loc) · 1.36 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/** @fileoverview Platform detection and OS-specific constants. */
let _os: typeof import('node:os') | undefined
/**
* Lazily load the os module to avoid Webpack errors.
* Uses non-'node:' prefixed require to prevent Webpack bundling issues.
*
* @private
*/
/*@__NO_SIDE_EFFECTS__*/
function getOs() {
if (_os === undefined) {
// Use non-'node:' prefixed require to avoid Webpack errors.
_os = /*@__PURE__*/ require('node:os')
}
return _os as typeof import('node:os')
}
/**
* CPU architecture type.
*/
export type Arch = NodeJS.Architecture
/**
* Linux libc variant.
*/
export type Libc = 'glibc' | 'musl'
/**
* Operating system platform type.
*/
export type Platform = NodeJS.Platform
let _arch: Arch | undefined
/**
* Get the current CPU architecture (memoized).
*/
export function getArch(): Arch {
if (_arch === undefined) {
_arch = getOs().arch()
}
return _arch
}
let _platform: Platform | undefined
/**
* Get the current platform (memoized).
*/
export function getPlatform(): Platform {
if (_platform === undefined) {
_platform = getOs().platform()
}
return _platform
}
// Platform detection (memoized at module load).
export const DARWIN = getPlatform() === 'darwin'
export const WIN32 = getPlatform() === 'win32'
// File permission modes.
export const S_IXUSR = 0o100
export const S_IXGRP = 0o010
export const S_IXOTH = 0o001