UNPKG

4.42 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.knownArchs = exports.targetArchs = exports.hostArch = exports.knownPlatforms = exports.hostPlatform = exports.hostAbi = exports.toFancyArch = exports.toFancyPlatform = exports.isValidNodeRange = exports.abiToNodeRange = void 0;
7var fs_1 = __importDefault(require("fs"));
8var child_process_1 = require("child_process");
9function getHostAbi() {
10 return "m" + process.versions.modules;
11}
12function abiToNodeRange(abi) {
13 if (/^m?14/.test(abi))
14 return 'node0.12';
15 if (/^m?46/.test(abi))
16 return 'node4';
17 if (/^m?47/.test(abi))
18 return 'node5';
19 if (/^m?48/.test(abi))
20 return 'node6';
21 if (/^m?51/.test(abi))
22 return 'node7';
23 if (/^m?57/.test(abi))
24 return 'node8';
25 if (/^m?59/.test(abi))
26 return 'node9';
27 if (/^m?64/.test(abi))
28 return 'node10';
29 if (/^m?67/.test(abi))
30 return 'node11';
31 if (/^m?72/.test(abi))
32 return 'node12';
33 if (/^m?79/.test(abi))
34 return 'node13';
35 if (/^m?83/.test(abi))
36 return 'node14';
37 return abi;
38}
39exports.abiToNodeRange = abiToNodeRange;
40function isValidNodeRange(nodeRange) {
41 if (nodeRange === 'latest')
42 return true;
43 if (!/^node/.test(nodeRange))
44 return false;
45 return true;
46}
47exports.isValidNodeRange = isValidNodeRange;
48function toFancyPlatform(platform) {
49 if (platform === 'darwin')
50 return 'macos';
51 if (platform === 'lin')
52 return 'linux';
53 if (platform === 'mac')
54 return 'macos';
55 if (platform === 'osx')
56 return 'macos';
57 if (platform === 'win32')
58 return 'win';
59 if (platform === 'windows')
60 return 'win';
61 return platform;
62}
63exports.toFancyPlatform = toFancyPlatform;
64function detectAlpine() {
65 var platform = process.platform;
66 if (platform !== 'linux') {
67 return false;
68 }
69 // https://github.com/sass/node-sass/issues/1589#issuecomment-265292579
70 var ldd = child_process_1.spawnSync('ldd').stderr.toString();
71 if (/\bmusl\b/.test(ldd)) {
72 return true;
73 }
74 var lddNode = child_process_1.spawnSync('ldd', [process.execPath]).stdout.toString();
75 return /\bmusl\b/.test(lddNode);
76}
77var isAlpine = detectAlpine();
78function getHostPlatform() {
79 var platform = process.platform;
80 if (isAlpine) {
81 return 'alpine';
82 }
83 return toFancyPlatform(platform);
84}
85function getKnownPlatforms() {
86 return ['alpine', 'freebsd', 'linux', 'linuxstatic', 'macos', 'win'];
87}
88function toFancyArch(arch) {
89 if (arch === 'ia32')
90 return 'x86';
91 if (arch === 'x86_64')
92 return 'x64';
93 return arch;
94}
95exports.toFancyArch = toFancyArch;
96function getArmUnameArch() {
97 var uname = child_process_1.spawnSync('uname', ['-a']);
98 if (uname.error) {
99 return '';
100 }
101 var unameOut = uname.stdout && uname.stdout.toString();
102 unameOut = (unameOut || '').toLowerCase();
103 if (unameOut.includes('aarch64'))
104 return 'arm64';
105 if (unameOut.includes('arm64'))
106 return 'arm64';
107 if (unameOut.includes('armv7'))
108 return 'armv7';
109 return '';
110}
111function getArmHostArch() {
112 var _a;
113 var cpu = fs_1.default.readFileSync('/proc/cpuinfo', 'utf8');
114 if (cpu.indexOf('vfpv3') >= 0) {
115 return 'armv7';
116 }
117 var name = cpu.split('model name')[1];
118 if (name)
119 _a = name.split(':'), name = _a[1];
120 if (name)
121 name = name.split('\n')[0];
122 if (name && name.indexOf('ARMv7') >= 0)
123 return 'armv7';
124 return 'armv6';
125}
126function getHostArch() {
127 var arch = process.arch;
128 if (arch === 'arm') {
129 return getArmUnameArch() || getArmHostArch();
130 }
131 return toFancyArch(arch);
132}
133function getTargetArchs() {
134 var arch = getHostArch();
135 if (arch === 'x64') {
136 return ['x64', 'x86'];
137 }
138 return [arch];
139}
140function getKnownArchs() {
141 return ['x64', 'x86', 'armv6', 'armv7', 'arm64', 'ppc64', 's390x'];
142}
143exports.hostAbi = getHostAbi();
144exports.hostPlatform = getHostPlatform();
145exports.knownPlatforms = getKnownPlatforms();
146exports.hostArch = getHostArch();
147exports.targetArchs = getTargetArchs();
148exports.knownArchs = getKnownArchs();
149//# sourceMappingURL=system.js.map
\No newline at end of file