@yao-pkg/pkg-fetch 3.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.system = exports.need = exports.getNodeVersion = exports.satisfyingNodeVersion = void 0;
66
+ var fs_extra_1 = __importDefault(require("fs-extra"));
67
+ var path_1 = __importDefault(require("path"));
68
+ var semver_1 = __importDefault(require("semver"));
69
+ var expected_1 = require("./expected");
70
+ var system_1 = require("./system");
71
+ var system = __importStar(require("./system"));
72
+ exports.system = system;
73
+ var places_1 = require("./places");
74
+ var log_1 = require("./log");
75
+ var build_1 = __importDefault(require("./build"));
76
+ var utils_1 = require("./utils");
77
+ var patches_json_1 = __importDefault(require("../patches/patches.json"));
78
+ var package_json_1 = require("../package.json");
79
+ function download(_a, local) {
80
+ var tag = _a.tag, name = _a.name;
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ var url, _b;
83
+ return __generator(this, function (_c) {
84
+ switch (_c.label) {
85
+ case 0:
86
+ url = "https://github.com/yao-pkg/pkg-fetch/releases/download/".concat(tag, "/").concat(name);
87
+ _c.label = 1;
88
+ case 1:
89
+ _c.trys.push([1, 4, , 5]);
90
+ return [4 /*yield*/, (0, utils_1.downloadUrl)(url, local)];
91
+ case 2:
92
+ _c.sent();
93
+ return [4 /*yield*/, (0, utils_1.plusx)(local)];
94
+ case 3:
95
+ _c.sent();
96
+ return [3 /*break*/, 5];
97
+ case 4:
98
+ _b = _c.sent();
99
+ return [2 /*return*/, false];
100
+ case 5: return [2 /*return*/, true];
101
+ }
102
+ });
103
+ });
104
+ }
105
+ function exists(file) {
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ var error_1;
108
+ return __generator(this, function (_a) {
109
+ switch (_a.label) {
110
+ case 0:
111
+ _a.trys.push([0, 2, , 3]);
112
+ return [4 /*yield*/, fs_extra_1.default.stat(file)];
113
+ case 1:
114
+ _a.sent();
115
+ return [2 /*return*/, true];
116
+ case 2:
117
+ error_1 = _a.sent();
118
+ return [2 /*return*/, false];
119
+ case 3: return [2 /*return*/];
120
+ }
121
+ });
122
+ });
123
+ }
124
+ function satisfyingNodeVersion(nodeRange) {
125
+ var versions = Object.keys(patches_json_1.default)
126
+ .filter(function (nv) { return semver_1.default.satisfies(nv, nodeRange) || nodeRange === 'latest'; })
127
+ .sort(function (nv1, nv2) { return (semver_1.default.gt(nv1, nv2) ? 1 : -1); });
128
+ var nodeVersion = versions.pop();
129
+ if (!nodeVersion) {
130
+ throw (0, log_1.wasReported)("No available node version satisfies '".concat(nodeRange, "'"));
131
+ }
132
+ return nodeVersion;
133
+ }
134
+ exports.satisfyingNodeVersion = satisfyingNodeVersion;
135
+ function getNodeVersion(nodeRange) {
136
+ nodeRange = (0, system_1.abiToNodeRange)(nodeRange); // 'm48' -> 'node6'
137
+ if (!(0, system_1.isValidNodeRange)(nodeRange)) {
138
+ throw (0, log_1.wasReported)("nodeRange must start with 'node'");
139
+ }
140
+ if (nodeRange !== 'latest') {
141
+ nodeRange = "v".concat(nodeRange.slice(4)); // 'node6' -> 'v6' for semver
142
+ }
143
+ var nodeVersion = satisfyingNodeVersion(nodeRange);
144
+ return nodeVersion;
145
+ }
146
+ exports.getNodeVersion = getNodeVersion;
147
+ function need(opts) {
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ var _a, forceFetch, forceBuild, dryRun, output, nodeRange, _b, platform, arch, nodeVersion, fetched, built, remote, fetchFailed;
150
+ return __generator(this, function (_c) {
151
+ switch (_c.label) {
152
+ case 0:
153
+ _a = opts || {}, forceFetch = _a.forceFetch, forceBuild = _a.forceBuild, dryRun = _a.dryRun, output = _a.output, nodeRange = _a.nodeRange;
154
+ _b = opts || {}, platform = _b.platform, arch = _b.arch;
155
+ if (!nodeRange)
156
+ throw (0, log_1.wasReported)('nodeRange not specified');
157
+ if (!platform)
158
+ throw (0, log_1.wasReported)('platform not specified');
159
+ if (!arch)
160
+ throw (0, log_1.wasReported)('arch not specified');
161
+ platform = (0, system_1.toFancyPlatform)(platform); // win32 -> win
162
+ arch = (0, system_1.toFancyArch)(arch); // ia32 -> x86
163
+ nodeVersion = getNodeVersion(nodeRange);
164
+ fetched = (0, places_1.localPlace)({
165
+ from: 'fetched',
166
+ arch: arch,
167
+ nodeVersion: nodeVersion,
168
+ platform: platform,
169
+ version: package_json_1.version,
170
+ output: output,
171
+ });
172
+ built = (0, places_1.localPlace)({
173
+ from: 'built',
174
+ arch: arch,
175
+ nodeVersion: nodeVersion,
176
+ platform: platform,
177
+ version: package_json_1.version,
178
+ output: output,
179
+ });
180
+ remote = (0, places_1.remotePlace)({ arch: arch, nodeVersion: nodeVersion, platform: platform, version: package_json_1.version });
181
+ if (!!forceBuild) return [3 /*break*/, 3];
182
+ return [4 /*yield*/, exists(fetched)];
183
+ case 1:
184
+ if (!_c.sent()) return [3 /*break*/, 3];
185
+ if (dryRun) {
186
+ return [2 /*return*/, 'exists'];
187
+ }
188
+ return [4 /*yield*/, (0, utils_1.hash)(fetched)];
189
+ case 2:
190
+ if ((_c.sent()) === expected_1.EXPECTED_HASHES[remote.name]) {
191
+ return [2 /*return*/, fetched];
192
+ }
193
+ log_1.log.info('Binary hash does NOT match. Re-fetching...');
194
+ fs_extra_1.default.unlinkSync(fetched);
195
+ _c.label = 3;
196
+ case 3:
197
+ if (!!forceFetch) return [3 /*break*/, 5];
198
+ return [4 /*yield*/, exists(built)];
199
+ case 4:
200
+ if (_c.sent()) {
201
+ if (dryRun)
202
+ return [2 /*return*/, 'exists'];
203
+ if (forceBuild)
204
+ log_1.log.info('Reusing base binaries built locally:', built);
205
+ return [2 /*return*/, built];
206
+ }
207
+ _c.label = 5;
208
+ case 5:
209
+ if (!!forceBuild) return [3 /*break*/, 9];
210
+ if (dryRun)
211
+ return [2 /*return*/, 'fetched'];
212
+ return [4 /*yield*/, download(remote, fetched)];
213
+ case 6:
214
+ if (!_c.sent()) return [3 /*break*/, 8];
215
+ return [4 /*yield*/, (0, utils_1.hash)(fetched)];
216
+ case 7:
217
+ if ((_c.sent()) === expected_1.EXPECTED_HASHES[remote.name]) {
218
+ return [2 /*return*/, fetched];
219
+ }
220
+ fs_extra_1.default.unlinkSync(fetched);
221
+ throw (0, log_1.wasReported)('Binary hash does NOT match.');
222
+ case 8:
223
+ fetchFailed = true;
224
+ _c.label = 9;
225
+ case 9:
226
+ if (!dryRun && fetchFailed) {
227
+ log_1.log.info('Not found in remote cache:', JSON.stringify(remote));
228
+ if (forceFetch) {
229
+ throw (0, log_1.wasReported)("Failed to fetch.");
230
+ }
231
+ }
232
+ if (!dryRun) {
233
+ log_1.log.info('Building base binary from source:', path_1.default.basename(built));
234
+ }
235
+ if (system_1.hostPlatform !== platform) {
236
+ if (system_1.hostPlatform !== 'alpine' || platform !== 'linuxstatic') {
237
+ throw (0, log_1.wasReported)("Not able to build for '".concat(opts.platform, "' here, only for '").concat(system_1.hostPlatform, "'"));
238
+ }
239
+ }
240
+ if (system_1.knownArchs.indexOf(arch) < 0) {
241
+ throw (0, log_1.wasReported)("Unknown arch '".concat(opts.arch, "'. Specify ").concat(system_1.knownArchs.join(', ')));
242
+ }
243
+ if (dryRun) {
244
+ return [2 /*return*/, 'built'];
245
+ }
246
+ return [4 /*yield*/, (0, build_1.default)(nodeVersion, arch, platform, built)];
247
+ case 10:
248
+ _c.sent();
249
+ return [2 /*return*/, built];
250
+ }
251
+ });
252
+ });
253
+ }
254
+ exports.need = need;
255
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,20 @@
1
+ declare class Log {
2
+ debugMode: boolean;
3
+ private bar?;
4
+ private lines;
5
+ debug(text: string, lines?: string[] | string): void;
6
+ info(text: string, lines?: string[] | string): void;
7
+ warn(text: string, lines?: string[] | string): void;
8
+ error(text: Error | string, lines?: string[] | string): void;
9
+ enableProgress(text: string): void;
10
+ showProgress(percentage: number): void;
11
+ disableProgress(): void;
12
+ }
13
+ export declare const log: Log;
14
+ declare class ReportedError extends Error {
15
+ name: string;
16
+ wasReported: boolean;
17
+ }
18
+ export declare function wasReported(error?: string, lines?: string[] | string | string): ReportedError;
19
+ export {};
20
+ //# sourceMappingURL=log.d.ts.map
package/lib-es5/log.js ADDED
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ /* eslint-disable no-underscore-dangle, no-console */
3
+ var __extends = (this && this.__extends) || (function () {
4
+ var extendStatics = function (d, b) {
5
+ extendStatics = Object.setPrototypeOf ||
6
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
8
+ return extendStatics(d, b);
9
+ };
10
+ return function (d, b) {
11
+ if (typeof b !== "function" && b !== null)
12
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
13
+ extendStatics(d, b);
14
+ function __() { this.constructor = d; }
15
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16
+ };
17
+ })();
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.wasReported = exports.log = void 0;
23
+ var progress_1 = __importDefault(require("progress"));
24
+ var assert_1 = __importDefault(require("assert"));
25
+ var chalk_1 = __importDefault(require("chalk"));
26
+ var Log = /** @class */ (function () {
27
+ function Log() {
28
+ this.debugMode = false;
29
+ }
30
+ Log.prototype.lines = function (lines) {
31
+ if (lines === undefined) {
32
+ return;
33
+ }
34
+ if (!Array.isArray(lines)) {
35
+ console.log(" ".concat(lines));
36
+ return;
37
+ }
38
+ for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
39
+ var line = lines_1[_i];
40
+ console.log(" ".concat(line));
41
+ }
42
+ };
43
+ Log.prototype.debug = function (text, lines) {
44
+ if (!this.debugMode) {
45
+ return;
46
+ }
47
+ console.log("> ".concat(chalk_1.default.green('[debug]'), " ").concat(text));
48
+ this.lines(lines);
49
+ };
50
+ Log.prototype.info = function (text, lines) {
51
+ console.log("> ".concat(text));
52
+ this.lines(lines);
53
+ };
54
+ Log.prototype.warn = function (text, lines) {
55
+ console.log("> ".concat(chalk_1.default.blue('Warning'), " ").concat(text));
56
+ this.lines(lines);
57
+ };
58
+ Log.prototype.error = function (text, lines) {
59
+ var message = text instanceof Error ? text.stack : text;
60
+ console.log("> ".concat(chalk_1.default.red('Error!'), " ").concat(message));
61
+ this.lines(lines);
62
+ };
63
+ Log.prototype.enableProgress = function (text) {
64
+ (0, assert_1.default)(!this.bar);
65
+ text += ' '.repeat(35 - text.length);
66
+ this.bar = new progress_1.default(" ".concat(text, " [:bar] :percent"), {
67
+ stream: process.stdout,
68
+ width: 20,
69
+ complete: '=',
70
+ incomplete: ' ',
71
+ total: 100,
72
+ });
73
+ };
74
+ Log.prototype.showProgress = function (percentage) {
75
+ if (!this.bar) {
76
+ return;
77
+ }
78
+ this.bar.update(percentage / 100);
79
+ };
80
+ Log.prototype.disableProgress = function () {
81
+ if (!this.bar) {
82
+ return;
83
+ }
84
+ // avoid empty line
85
+ if (!this.bar.complete) {
86
+ this.bar.terminate();
87
+ }
88
+ delete this.bar;
89
+ };
90
+ return Log;
91
+ }());
92
+ exports.log = new Log();
93
+ var ReportedError = /** @class */ (function (_super) {
94
+ __extends(ReportedError, _super);
95
+ function ReportedError() {
96
+ var _this = _super !== null && _super.apply(this, arguments) || this;
97
+ _this.name = 'ReportedError';
98
+ _this.wasReported = true;
99
+ return _this;
100
+ }
101
+ return ReportedError;
102
+ }(Error));
103
+ function wasReported(error, lines) {
104
+ var reportedError = new ReportedError('No message');
105
+ if (typeof error === 'string') {
106
+ exports.log.error(error, lines);
107
+ reportedError = new ReportedError(error);
108
+ }
109
+ return reportedError;
110
+ }
111
+ exports.wasReported = wasReported;
112
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1,19 @@
1
+ export declare const cachePath: string;
2
+ interface PlaceOptions {
3
+ version: string;
4
+ nodeVersion: string;
5
+ platform: string;
6
+ arch: string;
7
+ }
8
+ interface LocalPlaceOptions extends PlaceOptions {
9
+ from: string;
10
+ output?: string;
11
+ }
12
+ export declare function localPlace({ from, output, version, nodeVersion, platform, arch, }: LocalPlaceOptions): string;
13
+ export interface Remote {
14
+ tag: string;
15
+ name: string;
16
+ }
17
+ export declare function remotePlace({ version, nodeVersion, platform, arch, }: PlaceOptions): Remote;
18
+ export {};
19
+ //# sourceMappingURL=places.d.ts.map
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.remotePlace = exports.localPlace = exports.cachePath = void 0;
7
+ var semver_1 = require("semver");
8
+ var os_1 = __importDefault(require("os"));
9
+ var path_1 = __importDefault(require("path"));
10
+ var PKG_CACHE_PATH = process.env.PKG_CACHE_PATH;
11
+ var IGNORE_TAG = Boolean(process.env.PKG_IGNORE_TAG);
12
+ exports.cachePath = PKG_CACHE_PATH || path_1.default.join(os_1.default.homedir(), '.pkg-cache');
13
+ function tagFromVersion(version) {
14
+ var mj = (0, semver_1.major)(version);
15
+ var mn = (0, semver_1.minor)(version);
16
+ return "v".concat(mj, ".").concat(mn);
17
+ }
18
+ function localPlace(_a) {
19
+ var from = _a.from, output = _a.output, version = _a.version, nodeVersion = _a.nodeVersion, platform = _a.platform, arch = _a.arch;
20
+ var binDir;
21
+ if (output) {
22
+ binDir = path_1.default.resolve(output);
23
+ }
24
+ else {
25
+ binDir = IGNORE_TAG
26
+ ? path_1.default.join(exports.cachePath)
27
+ : path_1.default.join(exports.cachePath, tagFromVersion(version));
28
+ }
29
+ return path_1.default.resolve(binDir, "".concat(output ? 'node' : from, "-").concat(nodeVersion, "-").concat(platform, "-").concat(arch));
30
+ }
31
+ exports.localPlace = localPlace;
32
+ function remotePlace(_a) {
33
+ var version = _a.version, nodeVersion = _a.nodeVersion, platform = _a.platform, arch = _a.arch;
34
+ return {
35
+ tag: tagFromVersion(version),
36
+ name: "node-".concat(nodeVersion, "-").concat(platform, "-").concat(arch),
37
+ };
38
+ }
39
+ exports.remotePlace = remotePlace;
40
+ //# sourceMappingURL=places.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=print-hashes.d.ts.map
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var expected_1 = require("./expected");
4
+ var utils_1 = require("./utils");
5
+ /* eslint-disable no-console */
6
+ function main() {
7
+ for (var _i = 0, _a = Object.keys(expected_1.EXPECTED_HASHES).sort(utils_1.nodeBinarySortFunction); _i < _a.length; _i++) {
8
+ var nodeVersion = _a[_i];
9
+ console.log("".concat(expected_1.EXPECTED_HASHES[nodeVersion], " ").concat(nodeVersion));
10
+ }
11
+ }
12
+ main();
13
+ //# sourceMappingURL=print-hashes.js.map
@@ -0,0 +1,11 @@
1
+ export declare function abiToNodeRange(abi: string): string;
2
+ export declare function isValidNodeRange(nodeRange: string): boolean;
3
+ export declare function toFancyPlatform(platform: string): string;
4
+ export declare function toFancyArch(arch: string): string;
5
+ export declare const hostAbi: string;
6
+ export declare const hostPlatform: string;
7
+ export declare const knownPlatforms: string[];
8
+ export declare const hostArch: string;
9
+ export declare const targetArchs: string[];
10
+ export declare const knownArchs: string[];
11
+ //# sourceMappingURL=system.d.ts.map
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.knownArchs = exports.targetArchs = exports.hostArch = exports.knownPlatforms = exports.hostPlatform = exports.hostAbi = exports.toFancyArch = exports.toFancyPlatform = exports.isValidNodeRange = exports.abiToNodeRange = void 0;
7
+ var fs_1 = __importDefault(require("fs"));
8
+ var child_process_1 = require("child_process");
9
+ function getHostAbi() {
10
+ return "m".concat(process.versions.modules);
11
+ }
12
+ function 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
+ }
39
+ exports.abiToNodeRange = abiToNodeRange;
40
+ function isValidNodeRange(nodeRange) {
41
+ if (nodeRange === 'latest')
42
+ return true;
43
+ if (!/^node/.test(nodeRange))
44
+ return false;
45
+ return true;
46
+ }
47
+ exports.isValidNodeRange = isValidNodeRange;
48
+ function 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
+ }
63
+ exports.toFancyPlatform = toFancyPlatform;
64
+ function detectAlpine() {
65
+ var _a;
66
+ var platform = process.platform;
67
+ if (platform !== 'linux') {
68
+ return false;
69
+ }
70
+ // https://github.com/sass/node-sass/issues/1589#issuecomment-265292579
71
+ var ldd = (_a = (0, child_process_1.spawnSync)('ldd').stderr) === null || _a === void 0 ? void 0 : _a.toString();
72
+ if (ldd == null) {
73
+ return fs_1.default.readdirSync('/lib').some(function (file) { return file.startsWith('libc.musl'); });
74
+ }
75
+ if (/\bmusl\b/.test(ldd)) {
76
+ return true;
77
+ }
78
+ var lddNode = (0, child_process_1.spawnSync)('ldd', [process.execPath]).stdout.toString();
79
+ return /\bmusl\b/.test(lddNode);
80
+ }
81
+ var isAlpine = detectAlpine();
82
+ function getHostPlatform() {
83
+ var platform = process.platform;
84
+ if (isAlpine) {
85
+ return 'alpine';
86
+ }
87
+ return toFancyPlatform(platform);
88
+ }
89
+ function getKnownPlatforms() {
90
+ return ['alpine', 'freebsd', 'linux', 'linuxstatic', 'macos', 'win'];
91
+ }
92
+ function toFancyArch(arch) {
93
+ if (arch === 'ia32')
94
+ return 'x86';
95
+ if (arch === 'x86_64')
96
+ return 'x64';
97
+ return arch;
98
+ }
99
+ exports.toFancyArch = toFancyArch;
100
+ function getArmUnameArch() {
101
+ var uname = (0, child_process_1.spawnSync)('uname', ['-a']);
102
+ if (uname.error) {
103
+ return '';
104
+ }
105
+ var unameOut = uname.stdout && uname.stdout.toString();
106
+ unameOut = (unameOut || '').toLowerCase();
107
+ if (unameOut.includes('aarch64'))
108
+ return 'arm64';
109
+ if (unameOut.includes('arm64'))
110
+ return 'arm64';
111
+ if (unameOut.includes('armv7'))
112
+ return 'armv7';
113
+ return '';
114
+ }
115
+ function getArmHostArch() {
116
+ var _a;
117
+ var cpu = fs_1.default.readFileSync('/proc/cpuinfo', 'utf8');
118
+ if (cpu.indexOf('vfpv3') >= 0) {
119
+ return 'armv7';
120
+ }
121
+ var name = cpu.split('model name')[1];
122
+ if (name)
123
+ _a = name.split(':'), name = _a[1];
124
+ if (name)
125
+ name = name.split('\n')[0];
126
+ if (name && name.indexOf('ARMv7') >= 0)
127
+ return 'armv7';
128
+ return 'armv6';
129
+ }
130
+ function getHostArch() {
131
+ var arch = process.arch;
132
+ if (arch === 'arm') {
133
+ return getArmUnameArch() || getArmHostArch();
134
+ }
135
+ return toFancyArch(arch);
136
+ }
137
+ function getTargetArchs() {
138
+ var arch = getHostArch();
139
+ if (arch === 'x64') {
140
+ return ['x64', 'x86'];
141
+ }
142
+ return [arch];
143
+ }
144
+ function getKnownArchs() {
145
+ return ['x64', 'x86', 'armv7', 'arm64', 'ppc64', 's390x'];
146
+ }
147
+ exports.hostAbi = getHostAbi();
148
+ exports.hostPlatform = getHostPlatform();
149
+ exports.knownPlatforms = getKnownPlatforms();
150
+ exports.hostArch = getHostArch();
151
+ exports.targetArchs = getTargetArchs();
152
+ exports.knownArchs = getKnownArchs();
153
+ //# sourceMappingURL=system.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": ".",
5
+ "outDir": "../lib-es5",
6
+ "resolveJsonModule": true
7
+ },
8
+ "include": ["**/*", "../typings/**/*", "**/*.json"],
9
+ "references": [{ "path": "../" }]
10
+ }
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import { SpawnSyncOptions } from 'child_process';
3
+ export declare function downloadUrl(url: string, file: string): Promise<void>;
4
+ export declare function hash(filePath: string): Promise<string>;
5
+ export declare function plusx(file: string): Promise<void>;
6
+ export declare function spawn(command: string, args?: ReadonlyArray<string>, options?: SpawnSyncOptions): Promise<void>;
7
+ export declare function nodeBinarySortFunction(a: string, b: string): number;
8
+ //# sourceMappingURL=utils.d.ts.map