Initial commit
This commit is contained in:
commit
e49726988c
5445 files changed
+1089914
No files matched your search
+3
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
export {};
|
||||
//# sourceMappingURL=bin.d.ts.map
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
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;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var yargs_1 = __importDefault(require("yargs"));
|
||||
var system_1 = require("./system");
|
||||
var log_1 = require("./log");
|
||||
var index_1 = require("./index");
|
||||
var verify_1 = require("./verify");
|
||||
var package_json_1 = require("../package.json");
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var argv, nodeRange, platform, arch, test, forceFetch, forceBuild, output, local;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
argv = yargs_1.default
|
||||
.env('PKG_FETCH_OPTION_')
|
||||
.option('node-range', { alias: 'n', default: 'latest', type: 'string' })
|
||||
.option('platform', { alias: 'p', default: system_1.hostPlatform, type: 'string' })
|
||||
.option('arch', { alias: 'a', default: system_1.hostArch, type: 'string' })
|
||||
.option('test', { alias: 't', type: 'boolean' })
|
||||
.option('force-fetch', {
|
||||
alias: 'f',
|
||||
type: 'boolean',
|
||||
})
|
||||
.option('force-build', {
|
||||
alias: 'b',
|
||||
type: 'boolean',
|
||||
})
|
||||
.conflicts('force-fetch', 'force-build')
|
||||
.option('output', { alias: 'o', type: 'string' })
|
||||
.version(package_json_1.version)
|
||||
.alias('v', 'version')
|
||||
.help()
|
||||
.alias('h', 'help').argv;
|
||||
nodeRange = argv["node-range"], platform = argv.platform, arch = argv.arch, test = argv.test, forceFetch = argv["force-fetch"], forceBuild = argv["force-build"], output = argv.output;
|
||||
return [4 /*yield*/, (0, index_1.need)({
|
||||
nodeRange: nodeRange,
|
||||
platform: platform,
|
||||
arch: arch,
|
||||
forceFetch: forceFetch,
|
||||
forceBuild: forceBuild,
|
||||
output: output,
|
||||
})];
|
||||
case 1:
|
||||
local = _a.sent();
|
||||
log_1.log.info(local);
|
||||
if (!test) return [3 /*break*/, 3];
|
||||
return [4 /*yield*/, (0, verify_1.verify)(local)];
|
||||
case 2:
|
||||
_a.sent();
|
||||
_a.label = 3;
|
||||
case 3: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
main().catch(function (error) {
|
||||
if (!error.wasReported)
|
||||
log_1.log.error(error);
|
||||
process.exit(2);
|
||||
});
|
||||
//# sourceMappingURL=bin.js.map
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export default function build(nodeVersion: string, targetArch: string, targetPlatform: string, local: string): Promise<void>;
|
||||
//# sourceMappingURL=build.d.ts.map
|
||||
+394
@@ -0,0 +1,394 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
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;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var zlib_1 = require("zlib");
|
||||
var crypto_1 = __importDefault(require("crypto"));
|
||||
var fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
var os_1 = __importDefault(require("os"));
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var stream_1 = require("stream");
|
||||
var util_1 = require("util");
|
||||
var tar_fs_1 = __importDefault(require("tar-fs"));
|
||||
var places_1 = require("./places");
|
||||
var utils_1 = require("./utils");
|
||||
var system_1 = require("./system");
|
||||
var log_1 = require("./log");
|
||||
var patches_json_1 = __importDefault(require("../patches/patches.json"));
|
||||
var buildPath = path_1.default.resolve(process.env.PKG_BUILD_PATH ||
|
||||
path_1.default.join(os_1.default.tmpdir(), "pkg." + crypto_1.default.randomBytes(12).toString('hex')));
|
||||
var nodePath = path_1.default.join(buildPath, 'node');
|
||||
var patchesPath = path_1.default.resolve(__dirname, '../patches');
|
||||
var nodeRepo = 'https://nodejs.org/dist';
|
||||
var nodeArchivePath = path_1.default.join(places_1.cachePath, 'node');
|
||||
function getMajor(nodeVersion) {
|
||||
var _a = nodeVersion.match(/^v?(\d+)/) || ['', 0], version = _a[1];
|
||||
return Number(version) | 0;
|
||||
}
|
||||
function getConfigureArgs(major, targetPlatform) {
|
||||
var args = [];
|
||||
// first of all v8_inspector introduces the use
|
||||
// of `prime_rehash_policy` symbol that requires
|
||||
// GLIBCXX_3.4.18 on some systems
|
||||
// also we don't support any kind of debugging
|
||||
// against packaged apps, hence v8_inspector is useless
|
||||
args.push('--without-inspector');
|
||||
if (system_1.hostPlatform === 'alpine') {
|
||||
// Statically Link against libgcc and libstdc++ libraries. See vercel/pkg#555.
|
||||
// libgcc and libstdc++ grant GCC Runtime Library Exception of GPL
|
||||
args.push('--partly-static');
|
||||
}
|
||||
if (targetPlatform === 'linuxstatic') {
|
||||
args.push('--fully-static');
|
||||
}
|
||||
// Link Time Optimization
|
||||
if (major >= 12) {
|
||||
if (system_1.hostPlatform !== 'win') {
|
||||
args.push('--enable-lto');
|
||||
}
|
||||
}
|
||||
// production binaries do NOT take NODE_OPTIONS from end-users
|
||||
args.push('--without-node-options');
|
||||
// DTrace
|
||||
args.push('--without-dtrace');
|
||||
// bundled npm package manager
|
||||
args.push('--without-npm');
|
||||
// Small ICU
|
||||
args.push('--with-intl=small-icu');
|
||||
// Workaround for nodejs/node#39313
|
||||
// All supported macOS versions have zlib as a system library
|
||||
if (targetPlatform === 'macos') {
|
||||
args.push('--shared-zlib');
|
||||
}
|
||||
return args;
|
||||
}
|
||||
function tarFetch(nodeVersion) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var distUrl, tarName, archivePath, hashPath, _a, _b, _c;
|
||||
return __generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
case 0:
|
||||
log_1.log.info('Fetching Node.js source archive from nodejs.org...');
|
||||
distUrl = nodeRepo + "/" + nodeVersion;
|
||||
tarName = "node-" + nodeVersion + ".tar.gz";
|
||||
archivePath = path_1.default.join(nodeArchivePath, tarName);
|
||||
hashPath = path_1.default.join(nodeArchivePath, tarName + ".sha256sum");
|
||||
if (fs_extra_1.default.existsSync(hashPath) && fs_extra_1.default.existsSync(archivePath)) {
|
||||
return [2 /*return*/];
|
||||
}
|
||||
return [4 /*yield*/, fs_extra_1.default.remove(hashPath).catch(function () { return undefined; })];
|
||||
case 1:
|
||||
_d.sent();
|
||||
return [4 /*yield*/, fs_extra_1.default.remove(archivePath).catch(function () { return undefined; })];
|
||||
case 2:
|
||||
_d.sent();
|
||||
return [4 /*yield*/, (0, utils_1.downloadUrl)(distUrl + "/SHASUMS256.txt", hashPath)];
|
||||
case 3:
|
||||
_d.sent();
|
||||
_b = (_a = fs_extra_1.default).writeFile;
|
||||
_c = [hashPath];
|
||||
return [4 /*yield*/, fs_extra_1.default.readFile(hashPath, 'utf8')];
|
||||
case 4: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.sent())
|
||||
.split('\n')
|
||||
.filter(function (l) { return l.includes(tarName); })[0]]))];
|
||||
case 5:
|
||||
_d.sent();
|
||||
return [4 /*yield*/, (0, utils_1.downloadUrl)(distUrl + "/" + tarName, archivePath)];
|
||||
case 6:
|
||||
_d.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function tarExtract(nodeVersion) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var tarName, expectedHash, actualHash, pipe, source, gunzip, extract;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
log_1.log.info('Extracting Node.js source archive...');
|
||||
tarName = "node-" + nodeVersion + ".tar.gz";
|
||||
return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.join(nodeArchivePath, tarName + ".sha256sum"), 'utf8')];
|
||||
case 1:
|
||||
expectedHash = (_a.sent()).split(' ')[0];
|
||||
return [4 /*yield*/, (0, utils_1.hash)(path_1.default.join(nodeArchivePath, tarName))];
|
||||
case 2:
|
||||
actualHash = _a.sent();
|
||||
if (!(expectedHash !== actualHash)) return [3 /*break*/, 5];
|
||||
return [4 /*yield*/, fs_extra_1.default.remove(path_1.default.join(nodeArchivePath, tarName))];
|
||||
case 3:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs_extra_1.default.remove(path_1.default.join(nodeArchivePath, tarName + ".sha256sum"))];
|
||||
case 4:
|
||||
_a.sent();
|
||||
throw (0, log_1.wasReported)("Hash mismatch for " + tarName);
|
||||
case 5:
|
||||
pipe = (0, util_1.promisify)(stream_1.pipeline);
|
||||
source = fs_extra_1.default.createReadStream(path_1.default.join(nodeArchivePath, tarName));
|
||||
gunzip = (0, zlib_1.createGunzip)();
|
||||
extract = tar_fs_1.default.extract(nodePath, {
|
||||
strip: 1,
|
||||
map: function (header) {
|
||||
log_1.log.info(header.name);
|
||||
return header;
|
||||
},
|
||||
});
|
||||
return [4 /*yield*/, pipe(source, gunzip, extract)];
|
||||
case 6:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function applyPatches(nodeVersion) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var storedPatches, storedPatch, patches, _i, patches_1, patch, patchPath, args;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
log_1.log.info('Applying patches');
|
||||
storedPatches = patches_json_1.default[nodeVersion];
|
||||
storedPatch = 'patches' in storedPatches ? storedPatches.patches : storedPatches;
|
||||
patches = 'sameAs' in storedPatch
|
||||
? patches_json_1.default[storedPatch.sameAs]
|
||||
: storedPatch;
|
||||
_i = 0, patches_1 = patches;
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
if (!(_i < patches_1.length)) return [3 /*break*/, 4];
|
||||
patch = patches_1[_i];
|
||||
patchPath = path_1.default.join(patchesPath, patch);
|
||||
args = ['-p1', '-i', patchPath];
|
||||
return [4 /*yield*/, (0, utils_1.spawn)('patch', args, { cwd: nodePath, stdio: 'inherit' })];
|
||||
case 2:
|
||||
_a.sent();
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
_i++;
|
||||
return [3 /*break*/, 1];
|
||||
case 4: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function compileOnWindows(nodeVersion, targetArch, targetPlatform) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var args, major, config_flags;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
args = ['/c', 'vcbuild.bat', targetArch];
|
||||
major = getMajor(nodeVersion);
|
||||
config_flags = getConfigureArgs(major, targetPlatform);
|
||||
// Event Tracing for Windows
|
||||
args.push('noetw');
|
||||
// Performance counters on Windows
|
||||
if (major <= 10) {
|
||||
args.push('noperfctr');
|
||||
}
|
||||
// Link Time Code Generation
|
||||
if (major >= 12) {
|
||||
args.push('ltcg');
|
||||
}
|
||||
// Can't cross compile for arm64 with small-icu
|
||||
if (system_1.hostArch !== targetArch &&
|
||||
!config_flags.includes('--with-intl=full-icu')) {
|
||||
config_flags.push('--without-intl');
|
||||
}
|
||||
return [4 /*yield*/, (0, utils_1.spawn)('cmd', args, {
|
||||
cwd: nodePath,
|
||||
env: __assign(__assign({}, process.env), { config_flags: config_flags.join(' ') }),
|
||||
stdio: 'inherit',
|
||||
})];
|
||||
case 1:
|
||||
_a.sent();
|
||||
if (major <= 10) {
|
||||
return [2 /*return*/, path_1.default.join(nodePath, 'Release/node.exe')];
|
||||
}
|
||||
return [2 /*return*/, path_1.default.join(nodePath, 'out/Release/node.exe')];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
var _a = process.env.MAKE_JOB_COUNT, MAKE_JOB_COUNT = _a === void 0 ? os_1.default.cpus().length : _a;
|
||||
function compileOnUnix(nodeVersion, targetArch, targetPlatform) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var args, cpu, output;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
args = [];
|
||||
cpu = {
|
||||
x86: 'ia32',
|
||||
x64: 'x64',
|
||||
armv6: 'arm',
|
||||
armv7: 'arm',
|
||||
arm64: 'arm64',
|
||||
ppc64: 'ppc64',
|
||||
s390x: 's390x',
|
||||
}[targetArch];
|
||||
if (cpu) {
|
||||
args.push('--dest-cpu', cpu);
|
||||
}
|
||||
if (system_1.hostArch !== targetArch) {
|
||||
log_1.log.warn('Cross compiling!');
|
||||
log_1.log.warn('You are responsible for appropriate env like CC, CC_host, etc.');
|
||||
args.push('--cross-compiling');
|
||||
}
|
||||
args.push.apply(args, getConfigureArgs(getMajor(nodeVersion), targetPlatform));
|
||||
// TODO same for windows?
|
||||
return [4 /*yield*/, (0, utils_1.spawn)('/bin/sh', __spreadArray(['./configure'], args, true), {
|
||||
cwd: nodePath,
|
||||
stdio: 'inherit',
|
||||
})];
|
||||
case 1:
|
||||
// TODO same for windows?
|
||||
_a.sent();
|
||||
return [4 /*yield*/, (0, utils_1.spawn)(system_1.hostPlatform === 'freebsd' ? 'gmake' : 'make', ['-j', String(MAKE_JOB_COUNT)], {
|
||||
cwd: nodePath,
|
||||
stdio: 'inherit',
|
||||
})];
|
||||
case 2:
|
||||
_a.sent();
|
||||
output = path_1.default.join(nodePath, 'out/Release/node');
|
||||
return [4 /*yield*/, (0, utils_1.spawn)(process.env.STRIP || 'strip', __spreadArray(__spreadArray([], (targetPlatform === 'macos' ? ['-x'] : []), true), [output], false), {
|
||||
stdio: 'inherit',
|
||||
})];
|
||||
case 3:
|
||||
_a.sent();
|
||||
if (!(targetPlatform === 'macos')) return [3 /*break*/, 5];
|
||||
// Newer versions of Apple Clang automatically ad-hoc sign the compiled executable.
|
||||
// However, for final executable to be signable, base binary MUST NOT have an existing signature.
|
||||
return [4 /*yield*/, (0, utils_1.spawn)('codesign', ['--remove-signature', output], {
|
||||
stdio: 'inherit',
|
||||
})];
|
||||
case 4:
|
||||
// Newer versions of Apple Clang automatically ad-hoc sign the compiled executable.
|
||||
// However, for final executable to be signable, base binary MUST NOT have an existing signature.
|
||||
_a.sent();
|
||||
_a.label = 5;
|
||||
case 5: return [2 /*return*/, output];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function compile(nodeVersion, targetArch, targetPlatform) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var win;
|
||||
return __generator(this, function (_a) {
|
||||
log_1.log.info('Compiling Node.js from sources...');
|
||||
win = system_1.hostPlatform === 'win';
|
||||
if (win) {
|
||||
return [2 /*return*/, compileOnWindows(nodeVersion, targetArch, targetPlatform)];
|
||||
}
|
||||
return [2 /*return*/, compileOnUnix(nodeVersion, targetArch, targetPlatform)];
|
||||
});
|
||||
});
|
||||
}
|
||||
function build(nodeVersion, targetArch, targetPlatform, local) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var output, outputHash;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, fs_extra_1.default.remove(buildPath)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs_extra_1.default.mkdirp(nodePath)];
|
||||
case 2:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs_extra_1.default.mkdirp(nodeArchivePath)];
|
||||
case 3:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, tarFetch(nodeVersion)];
|
||||
case 4:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, tarExtract(nodeVersion)];
|
||||
case 5:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, applyPatches(nodeVersion)];
|
||||
case 6:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, compile(nodeVersion, targetArch, targetPlatform)];
|
||||
case 7:
|
||||
output = _a.sent();
|
||||
return [4 /*yield*/, (0, utils_1.hash)(output)];
|
||||
case 8:
|
||||
outputHash = _a.sent();
|
||||
return [4 /*yield*/, fs_extra_1.default.mkdirp(path_1.default.dirname(local))];
|
||||
case 9:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs_extra_1.default.copy(output, local)];
|
||||
case 10:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs_extra_1.default.promises.writeFile(local + ".sha256sum", outputHash + " " + path_1.default.basename(local) + "\n")];
|
||||
case 11:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, fs_extra_1.default.remove(buildPath)];
|
||||
case 12:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.default = build;
|
||||
//# sourceMappingURL=build.js.map
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export declare const EXPECTED_HASHES: Record<string, string>;
|
||||
//# sourceMappingURL=expected.d.ts.map
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EXPECTED_HASHES = void 0;
|
||||
exports.EXPECTED_HASHES = {
|
||||
// 2a68741776e74f626c83254941a639ab7dcf6332
|
||||
// alpine: https://github.com/vercel/pkg-fetch/actions/runs/752615021
|
||||
// linux: https://github.com/vercel/pkg-fetch/actions/runs/752615173
|
||||
// linuxstatic: https://github.com/vercel/pkg-fetch/actions/runs/752615423
|
||||
// macos: https://github.com/vercel/pkg-fetch/actions/runs/752615807
|
||||
// win: https://github.com/vercel/pkg-fetch/actions/runs/752615557
|
||||
'node-v10.24.1-alpine-arm64': 'f6a59f1ace2ef1f4bf976ff85d9a74bdc71bda098e8aa018e2a089c590aeedea',
|
||||
'node-v10.24.1-alpine-x64': '24f862b22a59ac0adb746d5bd3f2226c8eb2f6e1565a1cb4d2418c9cb0f3769e',
|
||||
'node-v10.24.1-linux-x64': 'c59574f4ea7b1423bd7ef586887ea41c43cfb2a63431126af0de20291a3a94db',
|
||||
'node-v10.24.1-linuxstatic-arm64': '01bc2cfbf7a7dd1a74201ae34a6cfafc1ad1c6d77039f587111738a81637bc5b',
|
||||
'node-v10.24.1-linuxstatic-x64': 'a7bbd62b712b3a7ac54953b646f0802e84bc7ecadb0b8a0756323fcffe3310a5',
|
||||
'node-v10.24.1-win-x64': '958647af177a9089bb4f3495e352d5348a1b42858d0111004ca26c3a2ece3f73',
|
||||
'node-v8.17.0-alpine-arm64': '807df81524ec8e1e266ac7fbed434c6b2281ae20b9fa7eaa524de90f3330c4d7',
|
||||
'node-v8.17.0-alpine-x64': '83a3914de57ee6be7d68ebaac8a10c1a2972d554800f1bee218cc4a23650e0fb',
|
||||
'node-v8.17.0-linux-arm64': 'f06855896bfa10bead1f08fac080305fb6fbfb2cc691168a3f0f0e834e12bfba',
|
||||
'node-v8.17.0-linux-x64': '14d75d43de1ff86469d354bf42a83b9494e09502fa7bc23a975e2cb82b1608b0',
|
||||
'node-v8.17.0-linuxstatic-arm64': '84de8fe30b2bd1dcb3615cf1d1b538aa48e1fcf66620ef97dce6b7ae85b45025',
|
||||
'node-v8.17.0-linuxstatic-x64': '5206878079f160e75a02ad33b7559b4a869e8181ee03d51d7211b52995f9ca7b',
|
||||
'node-v8.17.0-macos-x64': 'dffa71e39100f4daa57de73fda7b4debecd09f552b15cf11854c8475380d3817',
|
||||
'node-v8.17.0-win-x64': '4556a06dc59a0196453ba5962ea077ea71fe566e4de1c92f73f057446d422251',
|
||||
// 27e00d1d72ab4afda203edcd7a4f9601bc1d641c
|
||||
// linux: https://github.com/vercel/pkg-fetch/actions/runs/888438143
|
||||
// linuxstatic: https://github.com/vercel/pkg-fetch/actions/runs/888438190
|
||||
// macos: https://github.com/vercel/pkg-fetch/actions/runs/888438236
|
||||
'node-v10.24.1-linux-arm64': 'e3a3e5197e3f3d1063e3178786890b29493b8dfc31362f3417cce90ca7eb3e98',
|
||||
'node-v10.24.1-linuxstatic-armv7': '4933be03e394a82f5aa5fc4600b29392b2ce7eac24bd2ef8759f9a8e8c841990',
|
||||
// 55a34ad0afe75749a14260c45d39cc9b265995ed
|
||||
// macos: https://github.com/vercel/pkg-fetch/actions/runs/918633749
|
||||
'node-v10.24.1-macos-x64': 'f2e4679262a1cc6f3213cc4f0453d662e48c021975b651534fcbf26d6fdab474',
|
||||
// e34c57f612d4cf56646450f75fe38e029ff2b0d6
|
||||
// alpine: https://github.com/vercel/pkg-fetch/actions/runs/2068735040
|
||||
// linux: https://github.com/vercel/pkg-fetch/actions/runs/2068735307
|
||||
// linuxstatic: https://github.com/vercel/pkg-fetch/actions/runs/2068735697
|
||||
// macos: https://github.com/vercel/pkg-fetch/actions/runs/2068736404
|
||||
// win: https://github.com/vercel/pkg-fetch/actions/runs/2068736093
|
||||
'node-v12.22.11-alpine-x64': '2ec8d7b761f03b2172bcf3b1b56c648e844116ab08a5484d7932138c374cf18c',
|
||||
'node-v12.22.11-linux-x64': '617d58e81711d3a1d34a737db39e751caa05040a1a586e6dd688241cfb3f3eed',
|
||||
'node-v12.22.11-linuxstatic-x64': '37714fc3ae8b1d0c92b124f8ab353c77e40494075646e43ce8e20bd4038b5b83',
|
||||
'node-v12.22.11-macos-x64': '5394093f0fd2bb5ea38ee2a5eaec9e00d3d1da9e3f7c3c99c68eecfe17354286',
|
||||
'node-v12.22.11-win-x64': '24bedd07eb0cad64d505ec731c438765370bbed32d8e1f47129fe3612fadfcdb',
|
||||
// e34c57f612d4cf56646450f75fe38e029ff2b0d6
|
||||
// alpine: https://github.com/jesec/pkg-fetch/actions/runs/2068737927
|
||||
// linux: https://github.com/jesec/pkg-fetch/actions/runs/2068738228
|
||||
// linuxstatic: https://github.com/jesec/pkg-fetch/actions/runs/2068738548
|
||||
// macos: https://github.com/jesec/pkg-fetch/actions/runs/2068742592
|
||||
'node-v12.22.11-alpine-arm64': '0933ab559bb34c720f0a7e0066f32608960a4d6290977c3af15529f7abfe7265',
|
||||
'node-v12.22.11-linux-arm64': '3a50d85ebd5ba7e1e62165b9df237925789ef9ed0ed92fd9d0f3a9df7503f751',
|
||||
'node-v12.22.11-linuxstatic-arm64': '0c5b03cbe32ce50f16dbb35769a2a897b30e8fdb2137c4799edb55898b475622',
|
||||
// 6ffa969bc037f33cd5c926b8706324740c8818af
|
||||
// alpine: https://github.com/vercel/pkg-fetch/actions/runs/2638965835
|
||||
// linux: https://github.com/vercel/pkg-fetch/actions/runs/2638965968
|
||||
// linuxstatic: https://github.com/vercel/pkg-fetch/actions/runs/2638966056
|
||||
// macos: https://github.com/vercel/pkg-fetch/actions/runs/2638966552
|
||||
// win: https://github.com/vercel/pkg-fetch/actions/runs/2638966247
|
||||
'node-v14.20.0-alpine-x64': 'bd48f87a845825d7321ff436ab0ecf59c71ac53356fed3b6ba2a841e06a75945',
|
||||
'node-v14.20.0-linux-x64': 'f3149f4772c6bc41180017d325e27b1465213acd684164e26fbc64e1f2f97dcf',
|
||||
'node-v14.20.0-linuxstatic-x64': 'a23a2fe6f1d75bb6d1faed1221e47fb3ff4789a23018709d919c5d24a3b17ce2',
|
||||
'node-v14.20.0-macos-x64': 'afda9c14e5f3fc18d40b7cd05c6a8ba42284c28928b29e47b9b99125d41ebce6',
|
||||
'node-v14.20.0-win-arm64': 'd9911fcdcedd1f5b227bd7d0ac3ef819a411976f6eb9550e2275a3c4fe93b97b',
|
||||
'node-v14.20.0-win-x64': 'f71330035700705ae39bfaac80b9270c8f75631b06b25f21b06d7359d9cd6c24',
|
||||
'node-v16.16.0-alpine-x64': '2c4caf90c620f4839277edf8dfb4fd1d259294a2bfbed2b90bb6063a6e0c9d23',
|
||||
'node-v16.16.0-linux-x64': 'f1a561aadf78e438e73b043a3c5d7b9fe075d7abcaaec6f29d9e2a0ba00d3a69',
|
||||
'node-v16.16.0-linuxstatic-x64': '8a888553a4855f3b01ea91a398eb3112b0d5f58f5f0112e9fecf6621615201ce',
|
||||
'node-v16.16.0-macos-x64': '321fcef798383c6e19d7ae242bc73dd1f1c7471499b00ee6b105c764645d9263',
|
||||
'node-v16.16.0-win-x64': 'b6c5f9a5bce3b451b6d59153eae6db1a87016edc3775ef9eae39f86485735672',
|
||||
'node-v18.5.0-alpine-x64': '8cdc988b31d52b5c5e8112f82f798aa9c815b7d861e689f40ba2e33b782e0e35',
|
||||
'node-v18.5.0-linux-x64': '25ea58e212ecac6c36df03281676aca934f4fec6a05fe9f0da8d3e01778df12c',
|
||||
'node-v18.5.0-linuxstatic-x64': '18f09486dae0ca6ebc48c7bf3f68fa85baeac8279c2b407bb25e8b5941c46556',
|
||||
'node-v18.5.0-macos-x64': '63c5a7f59ea2d4c04c4d033be8844be894ce018c43b2ea61ed5ccc38b833e435',
|
||||
'node-v18.5.0-win-arm64': '02e317e399fecc4a21facc365ff51268555b1a347c4f2720956a12e843b99783',
|
||||
'node-v18.5.0-win-x64': 'e0e9a647d81011612f8cb19c6a41760643eedd27222af548e9ffdff7d8ebb94b',
|
||||
// 6ffa969bc037f33cd5c926b8706324740c8818af
|
||||
// alpine: https://github.com/jesec/pkg-fetch/actions/runs/2639071916
|
||||
// linux: https://github.com/jesec/pkg-fetch/actions/runs/2639072106
|
||||
// linuxstatic: https://github.com/jesec/pkg-fetch/actions/runs/2639072371
|
||||
// macos: https://github.com/jesec/pkg-fetch/actions/runs/2639072571
|
||||
'node-v14.20.0-alpine-arm64': 'b0be3a7904f2c79bdb8e2b61018d9aa7f55e0778c4c768c4d65017931369a762',
|
||||
'node-v14.20.0-linux-arm64': 'fa26fed989a0710e82eaf09bd727f3501ab80d487da4baa076ab50267e47bbde',
|
||||
'node-v14.20.0-linuxstatic-arm64': 'b645ee721e1f12d9a45e1a529e28038c0eb757de4bb74ba3b585999e3160a767',
|
||||
'node-v14.20.0-macos-arm64': 'c101f9378cf40d62400612f57efea3e4b0e9951b110aea6a50dbf3aff84ea45f',
|
||||
'node-v16.16.0-alpine-arm64': 'c38f270d190fd1f5d8e74800b62408d06f4492720fec1fd46414a7f504114847',
|
||||
'node-v16.16.0-linux-arm64': 'e3913ecef725f83ccbd2181d7d33043f8b3e72466d09897c338ee328cffc3bfe',
|
||||
'node-v16.16.0-linuxstatic-arm64': 'aac0039a2b380057085a4b927637c6e5550eabfd55d1ca2f98e022abccfd7390',
|
||||
'node-v16.16.0-linuxstatic-armv7': 'cbe14ff111fd3d1ecb82cf6aaec5a53588537008fdcfab4bc2c880d651f5580a',
|
||||
'node-v16.16.0-macos-arm64': 'd9140eebaa88620b9692d6e11cc2d92b2b56f791a6bbeddd771f5e07d042e1bc',
|
||||
'node-v16.16.0-win-arm64': 'e078fd200f6f0cd2e84ba668711a5cc9c7f0d20d36fae1bfe4bc361f40f5923f',
|
||||
'node-v18.5.0-alpine-arm64': 'e227164d7a0683b42a1a5659a997d7b8a843ffe293b291f0063a8afb08b657ca',
|
||||
'node-v18.5.0-linux-arm64': 'e562c0d81643de3b06b9900936ebde263373ca7bdaf42a8eacca8d020b2ce21e',
|
||||
'node-v18.5.0-linuxstatic-arm64': '073f9252693bd35a4184a24bdc503aa6dc1300def7a96564c83221e4d3272c5a',
|
||||
'node-v18.5.0-linuxstatic-armv7': 'eb32af2e74028d303933b4fd4d13e1fc3c6854cfa65e962dfe31903cff69ef74',
|
||||
'node-v18.5.0-macos-arm64': '242917bdb26a1b53726f82483bc68ce0609cc8772df401b2eb163dc6b3d6ddfe',
|
||||
};
|
||||
//# sourceMappingURL=expected.js.map
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import * as system from './system';
|
||||
interface NeedOptions {
|
||||
forceFetch?: boolean;
|
||||
forceBuild?: boolean;
|
||||
dryRun?: boolean;
|
||||
output?: string;
|
||||
nodeRange: string;
|
||||
platform: string;
|
||||
arch: string;
|
||||
}
|
||||
export declare function need(opts: NeedOptions): Promise<string>;
|
||||
export { system };
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
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;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.system = exports.need = void 0;
|
||||
var fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var semver_1 = __importDefault(require("semver"));
|
||||
var expected_1 = require("./expected");
|
||||
var system_1 = require("./system");
|
||||
var system = __importStar(require("./system"));
|
||||
exports.system = system;
|
||||
var places_1 = require("./places");
|
||||
var log_1 = require("./log");
|
||||
var build_1 = __importDefault(require("./build"));
|
||||
var utils_1 = require("./utils");
|
||||
var patches_json_1 = __importDefault(require("../patches/patches.json"));
|
||||
var package_json_1 = require("../package.json");
|
||||
function download(_a, local) {
|
||||
var tag = _a.tag, name = _a.name;
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var url, _b;
|
||||
return __generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
case 0:
|
||||
url = "https://github.com/vercel/pkg-fetch/releases/download/" + tag + "/" + name;
|
||||
_c.label = 1;
|
||||
case 1:
|
||||
_c.trys.push([1, 4, , 5]);
|
||||
return [4 /*yield*/, (0, utils_1.downloadUrl)(url, local)];
|
||||
case 2:
|
||||
_c.sent();
|
||||
return [4 /*yield*/, (0, utils_1.plusx)(local)];
|
||||
case 3:
|
||||
_c.sent();
|
||||
return [3 /*break*/, 5];
|
||||
case 4:
|
||||
_b = _c.sent();
|
||||
return [2 /*return*/, false];
|
||||
case 5: return [2 /*return*/, true];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function exists(file) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var error_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
_a.trys.push([0, 2, , 3]);
|
||||
return [4 /*yield*/, fs_extra_1.default.stat(file)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [2 /*return*/, true];
|
||||
case 2:
|
||||
error_1 = _a.sent();
|
||||
return [2 /*return*/, false];
|
||||
case 3: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
function need(opts) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
function satisfyingNodeVersion() {
|
||||
var versions = Object.keys(patches_json_1.default)
|
||||
.filter(function (nv) { return semver_1.default.satisfies(nv, nodeRange) || nodeRange === 'latest'; })
|
||||
.sort(function (nv1, nv2) { return (semver_1.default.gt(nv1, nv2) ? 1 : -1); });
|
||||
return versions.pop();
|
||||
}
|
||||
var _a, forceFetch, forceBuild, dryRun, output, _b, nodeRange, platform, arch, nodeVersion, fetched, built, remote, fetchFailed;
|
||||
return __generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
case 0:
|
||||
_a = opts || {}, forceFetch = _a.forceFetch, forceBuild = _a.forceBuild, dryRun = _a.dryRun, output = _a.output;
|
||||
_b = opts || {}, nodeRange = _b.nodeRange, platform = _b.platform, arch = _b.arch;
|
||||
if (!nodeRange)
|
||||
throw (0, log_1.wasReported)('nodeRange not specified');
|
||||
if (!platform)
|
||||
throw (0, log_1.wasReported)('platform not specified');
|
||||
if (!arch)
|
||||
throw (0, log_1.wasReported)('arch not specified');
|
||||
nodeRange = (0, system_1.abiToNodeRange)(nodeRange); // 'm48' -> 'node6'
|
||||
if (!(0, system_1.isValidNodeRange)(nodeRange)) {
|
||||
throw (0, log_1.wasReported)("nodeRange must start with 'node'");
|
||||
}
|
||||
if (nodeRange !== 'latest') {
|
||||
nodeRange = "v" + nodeRange.slice(4); // 'node6' -> 'v6' for semver
|
||||
}
|
||||
platform = (0, system_1.toFancyPlatform)(platform); // win32 -> win
|
||||
arch = (0, system_1.toFancyArch)(arch); // ia32 -> x86
|
||||
nodeVersion = satisfyingNodeVersion();
|
||||
if (!nodeVersion) {
|
||||
throw (0, log_1.wasReported)("No available node version satisfies '" + opts.nodeRange + "'");
|
||||
}
|
||||
fetched = (0, places_1.localPlace)({
|
||||
from: 'fetched',
|
||||
arch: arch,
|
||||
nodeVersion: nodeVersion,
|
||||
platform: platform,
|
||||
version: package_json_1.version,
|
||||
output: output,
|
||||
});
|
||||
built = (0, places_1.localPlace)({
|
||||
from: 'built',
|
||||
arch: arch,
|
||||
nodeVersion: nodeVersion,
|
||||
platform: platform,
|
||||
version: package_json_1.version,
|
||||
output: output,
|
||||
});
|
||||
remote = (0, places_1.remotePlace)({ arch: arch, nodeVersion: nodeVersion, platform: platform, version: package_json_1.version });
|
||||
if (!!forceBuild) return [3 /*break*/, 3];
|
||||
return [4 /*yield*/, exists(fetched)];
|
||||
case 1:
|
||||
if (!_c.sent()) return [3 /*break*/, 3];
|
||||
if (dryRun) {
|
||||
return [2 /*return*/, 'exists'];
|
||||
}
|
||||
return [4 /*yield*/, (0, utils_1.hash)(fetched)];
|
||||
case 2:
|
||||
if ((_c.sent()) === expected_1.EXPECTED_HASHES[remote.name]) {
|
||||
return [2 /*return*/, fetched];
|
||||
}
|
||||
log_1.log.info('Binary hash does NOT match. Re-fetching...');
|
||||
fs_extra_1.default.unlinkSync(fetched);
|
||||
_c.label = 3;
|
||||
case 3:
|
||||
if (!!forceFetch) return [3 /*break*/, 5];
|
||||
return [4 /*yield*/, exists(built)];
|
||||
case 4:
|
||||
if (_c.sent()) {
|
||||
if (dryRun)
|
||||
return [2 /*return*/, 'exists'];
|
||||
if (forceBuild)
|
||||
log_1.log.info('Reusing base binaries built locally:', built);
|
||||
return [2 /*return*/, built];
|
||||
}
|
||||
_c.label = 5;
|
||||
case 5:
|
||||
if (!!forceBuild) return [3 /*break*/, 9];
|
||||
if (dryRun)
|
||||
return [2 /*return*/, 'fetched'];
|
||||
return [4 /*yield*/, download(remote, fetched)];
|
||||
case 6:
|
||||
if (!_c.sent()) return [3 /*break*/, 8];
|
||||
return [4 /*yield*/, (0, utils_1.hash)(fetched)];
|
||||
case 7:
|
||||
if ((_c.sent()) === expected_1.EXPECTED_HASHES[remote.name]) {
|
||||
return [2 /*return*/, fetched];
|
||||
}
|
||||
fs_extra_1.default.unlinkSync(fetched);
|
||||
throw (0, log_1.wasReported)('Binary hash does NOT match.');
|
||||
case 8:
|
||||
fetchFailed = true;
|
||||
_c.label = 9;
|
||||
case 9:
|
||||
if (!dryRun && fetchFailed) {
|
||||
log_1.log.info('Not found in remote cache:', JSON.stringify(remote));
|
||||
if (forceFetch) {
|
||||
throw (0, log_1.wasReported)("Failed to fetch.");
|
||||
}
|
||||
}
|
||||
if (!dryRun) {
|
||||
log_1.log.info('Building base binary from source:', path_1.default.basename(built));
|
||||
}
|
||||
if (system_1.hostPlatform !== platform) {
|
||||
if (system_1.hostPlatform !== 'alpine' || platform !== 'linuxstatic') {
|
||||
throw (0, log_1.wasReported)("Not able to build for '" + opts.platform + "' here, only for '" + system_1.hostPlatform + "'");
|
||||
}
|
||||
}
|
||||
if (system_1.knownArchs.indexOf(arch) < 0) {
|
||||
throw (0, log_1.wasReported)("Unknown arch '" + opts.arch + "'. Specify " + system_1.knownArchs.join(', '));
|
||||
}
|
||||
if (dryRun) {
|
||||
return [2 /*return*/, 'built'];
|
||||
}
|
||||
return [4 /*yield*/, (0, build_1.default)(nodeVersion, arch, platform, built)];
|
||||
case 10:
|
||||
_c.sent();
|
||||
return [2 /*return*/, built];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.need = need;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
declare class Log {
|
||||
debugMode: boolean;
|
||||
private bar?;
|
||||
private lines;
|
||||
debug(text: string, lines?: string[] | string): void;
|
||||
info(text: string, lines?: string[] | string): void;
|
||||
warn(text: string, lines?: string[] | string): void;
|
||||
error(text: Error | string, lines?: string[] | string): void;
|
||||
enableProgress(text: string): void;
|
||||
showProgress(percentage: number): void;
|
||||
disableProgress(): void;
|
||||
}
|
||||
export declare const log: Log;
|
||||
declare class ReportedError extends Error {
|
||||
name: string;
|
||||
wasReported: boolean;
|
||||
}
|
||||
export declare function wasReported(error?: string, lines?: string[] | string | string): ReportedError;
|
||||
export {};
|
||||
//# sourceMappingURL=log.d.ts.map
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
/* eslint-disable no-underscore-dangle, no-console */
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.wasReported = exports.log = void 0;
|
||||
var progress_1 = __importDefault(require("progress"));
|
||||
var assert_1 = __importDefault(require("assert"));
|
||||
var chalk_1 = __importDefault(require("chalk"));
|
||||
var Log = /** @class */ (function () {
|
||||
function Log() {
|
||||
this.debugMode = false;
|
||||
}
|
||||
Log.prototype.lines = function (lines) {
|
||||
if (lines === undefined) {
|
||||
return;
|
||||
}
|
||||
if (!Array.isArray(lines)) {
|
||||
console.log(" " + lines);
|
||||
return;
|
||||
}
|
||||
for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) {
|
||||
var line = lines_1[_i];
|
||||
console.log(" " + line);
|
||||
}
|
||||
};
|
||||
Log.prototype.debug = function (text, lines) {
|
||||
if (!this.debugMode) {
|
||||
return;
|
||||
}
|
||||
console.log("> " + chalk_1.default.green('[debug]') + " " + text);
|
||||
this.lines(lines);
|
||||
};
|
||||
Log.prototype.info = function (text, lines) {
|
||||
console.log("> " + text);
|
||||
this.lines(lines);
|
||||
};
|
||||
Log.prototype.warn = function (text, lines) {
|
||||
console.log("> " + chalk_1.default.blue('Warning') + " " + text);
|
||||
this.lines(lines);
|
||||
};
|
||||
Log.prototype.error = function (text, lines) {
|
||||
var message = text instanceof Error ? text.stack : text;
|
||||
console.log("> " + chalk_1.default.red('Error!') + " " + message);
|
||||
this.lines(lines);
|
||||
};
|
||||
Log.prototype.enableProgress = function (text) {
|
||||
(0, assert_1.default)(!this.bar);
|
||||
text += ' '.repeat(35 - text.length);
|
||||
this.bar = new progress_1.default(" " + text + " [:bar] :percent", {
|
||||
stream: process.stdout,
|
||||
width: 20,
|
||||
complete: '=',
|
||||
incomplete: ' ',
|
||||
total: 100,
|
||||
});
|
||||
};
|
||||
Log.prototype.showProgress = function (percentage) {
|
||||
if (!this.bar) {
|
||||
return;
|
||||
}
|
||||
this.bar.update(percentage / 100);
|
||||
};
|
||||
Log.prototype.disableProgress = function () {
|
||||
if (!this.bar) {
|
||||
return;
|
||||
}
|
||||
// avoid empty line
|
||||
if (!this.bar.complete) {
|
||||
this.bar.terminate();
|
||||
}
|
||||
delete this.bar;
|
||||
};
|
||||
return Log;
|
||||
}());
|
||||
exports.log = new Log();
|
||||
var ReportedError = /** @class */ (function (_super) {
|
||||
__extends(ReportedError, _super);
|
||||
function ReportedError() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.name = 'ReportedError';
|
||||
_this.wasReported = true;
|
||||
return _this;
|
||||
}
|
||||
return ReportedError;
|
||||
}(Error));
|
||||
function wasReported(error, lines) {
|
||||
var reportedError = new ReportedError('No message');
|
||||
if (typeof error === 'string') {
|
||||
exports.log.error(error, lines);
|
||||
reportedError = new ReportedError(error);
|
||||
}
|
||||
return reportedError;
|
||||
}
|
||||
exports.wasReported = wasReported;
|
||||
//# sourceMappingURL=log.js.map
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
export declare const cachePath: string;
|
||||
interface PlaceOptions {
|
||||
version: string;
|
||||
nodeVersion: string;
|
||||
platform: string;
|
||||
arch: string;
|
||||
}
|
||||
interface LocalPlaceOptions extends PlaceOptions {
|
||||
from: string;
|
||||
output?: string;
|
||||
}
|
||||
export declare function localPlace({ from, output, version, nodeVersion, platform, arch, }: LocalPlaceOptions): string;
|
||||
export interface Remote {
|
||||
tag: string;
|
||||
name: string;
|
||||
}
|
||||
export declare function remotePlace({ version, nodeVersion, platform, arch, }: PlaceOptions): Remote;
|
||||
export {};
|
||||
//# sourceMappingURL=places.d.ts.map
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.remotePlace = exports.localPlace = exports.cachePath = void 0;
|
||||
var semver_1 = require("semver");
|
||||
var os_1 = __importDefault(require("os"));
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var PKG_CACHE_PATH = process.env.PKG_CACHE_PATH;
|
||||
var IGNORE_TAG = Boolean(process.env.PKG_IGNORE_TAG);
|
||||
exports.cachePath = PKG_CACHE_PATH || path_1.default.join(os_1.default.homedir(), '.pkg-cache');
|
||||
function tagFromVersion(version) {
|
||||
var mj = (0, semver_1.major)(version);
|
||||
var mn = (0, semver_1.minor)(version);
|
||||
return "v" + mj + "." + mn;
|
||||
}
|
||||
function localPlace(_a) {
|
||||
var from = _a.from, output = _a.output, version = _a.version, nodeVersion = _a.nodeVersion, platform = _a.platform, arch = _a.arch;
|
||||
var binDir;
|
||||
if (output) {
|
||||
binDir = path_1.default.resolve(output);
|
||||
}
|
||||
else {
|
||||
binDir = IGNORE_TAG
|
||||
? path_1.default.join(exports.cachePath)
|
||||
: path_1.default.join(exports.cachePath, tagFromVersion(version));
|
||||
}
|
||||
return path_1.default.resolve(binDir, (output ? 'node' : from) + "-" + nodeVersion + "-" + platform + "-" + arch);
|
||||
}
|
||||
exports.localPlace = localPlace;
|
||||
function remotePlace(_a) {
|
||||
var version = _a.version, nodeVersion = _a.nodeVersion, platform = _a.platform, arch = _a.arch;
|
||||
return {
|
||||
tag: tagFromVersion(version),
|
||||
name: "node-" + nodeVersion + "-" + platform + "-" + arch,
|
||||
};
|
||||
}
|
||||
exports.remotePlace = remotePlace;
|
||||
//# sourceMappingURL=places.js.map
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
export declare function abiToNodeRange(abi: string): string;
|
||||
export declare function isValidNodeRange(nodeRange: string): boolean;
|
||||
export declare function toFancyPlatform(platform: string): string;
|
||||
export declare function toFancyArch(arch: string): string;
|
||||
export declare const hostAbi: string;
|
||||
export declare const hostPlatform: string;
|
||||
export declare const knownPlatforms: string[];
|
||||
export declare const hostArch: string;
|
||||
export declare const targetArchs: string[];
|
||||
export declare const knownArchs: string[];
|
||||
//# sourceMappingURL=system.d.ts.map
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.knownArchs = exports.targetArchs = exports.hostArch = exports.knownPlatforms = exports.hostPlatform = exports.hostAbi = exports.toFancyArch = exports.toFancyPlatform = exports.isValidNodeRange = exports.abiToNodeRange = void 0;
|
||||
var fs_1 = __importDefault(require("fs"));
|
||||
var child_process_1 = require("child_process");
|
||||
function getHostAbi() {
|
||||
return "m" + process.versions.modules;
|
||||
}
|
||||
function abiToNodeRange(abi) {
|
||||
if (/^m?14/.test(abi))
|
||||
return 'node0.12';
|
||||
if (/^m?46/.test(abi))
|
||||
return 'node4';
|
||||
if (/^m?47/.test(abi))
|
||||
return 'node5';
|
||||
if (/^m?48/.test(abi))
|
||||
return 'node6';
|
||||
if (/^m?51/.test(abi))
|
||||
return 'node7';
|
||||
if (/^m?57/.test(abi))
|
||||
return 'node8';
|
||||
if (/^m?59/.test(abi))
|
||||
return 'node9';
|
||||
if (/^m?64/.test(abi))
|
||||
return 'node10';
|
||||
if (/^m?67/.test(abi))
|
||||
return 'node11';
|
||||
if (/^m?72/.test(abi))
|
||||
return 'node12';
|
||||
if (/^m?79/.test(abi))
|
||||
return 'node13';
|
||||
if (/^m?83/.test(abi))
|
||||
return 'node14';
|
||||
return abi;
|
||||
}
|
||||
exports.abiToNodeRange = abiToNodeRange;
|
||||
function isValidNodeRange(nodeRange) {
|
||||
if (nodeRange === 'latest')
|
||||
return true;
|
||||
if (!/^node/.test(nodeRange))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
exports.isValidNodeRange = isValidNodeRange;
|
||||
function toFancyPlatform(platform) {
|
||||
if (platform === 'darwin')
|
||||
return 'macos';
|
||||
if (platform === 'lin')
|
||||
return 'linux';
|
||||
if (platform === 'mac')
|
||||
return 'macos';
|
||||
if (platform === 'osx')
|
||||
return 'macos';
|
||||
if (platform === 'win32')
|
||||
return 'win';
|
||||
if (platform === 'windows')
|
||||
return 'win';
|
||||
return platform;
|
||||
}
|
||||
exports.toFancyPlatform = toFancyPlatform;
|
||||
function detectAlpine() {
|
||||
var _a;
|
||||
var platform = process.platform;
|
||||
if (platform !== 'linux') {
|
||||
return false;
|
||||
}
|
||||
// https://github.com/sass/node-sass/issues/1589#issuecomment-265292579
|
||||
var ldd = (_a = (0, child_process_1.spawnSync)('ldd').stderr) === null || _a === void 0 ? void 0 : _a.toString();
|
||||
if (ldd == null) {
|
||||
return fs_1.default.readdirSync('/lib').some(function (file) { return file.startsWith('libc.musl'); });
|
||||
}
|
||||
if (/\bmusl\b/.test(ldd)) {
|
||||
return true;
|
||||
}
|
||||
var lddNode = (0, child_process_1.spawnSync)('ldd', [process.execPath]).stdout.toString();
|
||||
return /\bmusl\b/.test(lddNode);
|
||||
}
|
||||
var isAlpine = detectAlpine();
|
||||
function getHostPlatform() {
|
||||
var platform = process.platform;
|
||||
if (isAlpine) {
|
||||
return 'alpine';
|
||||
}
|
||||
return toFancyPlatform(platform);
|
||||
}
|
||||
function getKnownPlatforms() {
|
||||
return ['alpine', 'freebsd', 'linux', 'linuxstatic', 'macos', 'win'];
|
||||
}
|
||||
function toFancyArch(arch) {
|
||||
if (arch === 'arm')
|
||||
return 'armv7';
|
||||
if (arch === 'ia32')
|
||||
return 'x86';
|
||||
if (arch === 'x86_64')
|
||||
return 'x64';
|
||||
return arch;
|
||||
}
|
||||
exports.toFancyArch = toFancyArch;
|
||||
function getHostArch() {
|
||||
return toFancyArch(process.arch);
|
||||
}
|
||||
function getTargetArchs() {
|
||||
var arch = getHostArch();
|
||||
if (arch === 'x64') {
|
||||
return ['x64', 'x86'];
|
||||
}
|
||||
return [arch];
|
||||
}
|
||||
function getKnownArchs() {
|
||||
return ['x64', 'x86', 'armv7', 'arm64', 'ppc64', 's390x'];
|
||||
}
|
||||
exports.hostAbi = getHostAbi();
|
||||
exports.hostPlatform = getHostPlatform();
|
||||
exports.knownPlatforms = getKnownPlatforms();
|
||||
exports.hostArch = getHostArch();
|
||||
exports.targetArchs = getTargetArchs();
|
||||
exports.knownArchs = getKnownArchs();
|
||||
//# sourceMappingURL=system.js.map
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/// <reference types="node" />
|
||||
import { SpawnSyncOptions } from 'child_process';
|
||||
export declare function downloadUrl(url: string, file: string): Promise<void>;
|
||||
export declare function hash(filePath: string): Promise<string>;
|
||||
export declare function plusx(file: string): Promise<void>;
|
||||
export declare function spawn(command: string, args?: ReadonlyArray<string>, options?: SpawnSyncOptions): Promise<void>;
|
||||
//# sourceMappingURL=utils.d.ts.map
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
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;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.spawn = exports.plusx = exports.hash = exports.downloadUrl = void 0;
|
||||
var node_fetch_1 = __importDefault(require("node-fetch"));
|
||||
var crypto_1 = __importDefault(require("crypto"));
|
||||
var fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
var https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var child_process_1 = require("child_process");
|
||||
var stream_1 = __importDefault(require("stream"));
|
||||
var log_1 = require("./log");
|
||||
function downloadUrl(url, file) {
|
||||
var _a, _b, _c;
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var proxy, res, tempFile, ws, totalSize, currentSize;
|
||||
return __generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
case 0:
|
||||
log_1.log.enableProgress(path_1.default.basename(file));
|
||||
log_1.log.showProgress(0);
|
||||
proxy = (_c = (_b = (_a = process.env.HTTPS_PROXY) !== null && _a !== void 0 ? _a : process.env.https_proxy) !== null && _b !== void 0 ? _b : process.env.HTTP_PROXY) !== null && _c !== void 0 ? _c : process.env.http_proxy;
|
||||
return [4 /*yield*/, (0, node_fetch_1.default)(url, proxy ? { agent: (0, https_proxy_agent_1.default)(proxy) } : undefined)];
|
||||
case 1:
|
||||
res = _d.sent();
|
||||
if (!res.ok) {
|
||||
log_1.log.disableProgress();
|
||||
throw (0, log_1.wasReported)(res.status + ": " + res.statusText);
|
||||
}
|
||||
tempFile = file + ".downloading";
|
||||
fs_extra_1.default.mkdirpSync(path_1.default.dirname(tempFile));
|
||||
ws = fs_extra_1.default.createWriteStream(tempFile);
|
||||
totalSize = Number(res.headers.get('content-length'));
|
||||
currentSize = 0;
|
||||
res.body.on('data', function (chunk) {
|
||||
if (totalSize != null && totalSize !== 0) {
|
||||
currentSize += chunk.length;
|
||||
log_1.log.showProgress((currentSize / totalSize) * 100);
|
||||
}
|
||||
});
|
||||
res.body.pipe(ws);
|
||||
return [2 /*return*/, new Promise(function (resolve, reject) {
|
||||
stream_1.default.finished(ws, function (err) {
|
||||
if (err) {
|
||||
log_1.log.disableProgress();
|
||||
fs_extra_1.default.rmSync(tempFile);
|
||||
reject((0, log_1.wasReported)(err.name + ": " + err.message));
|
||||
}
|
||||
else {
|
||||
log_1.log.showProgress(100);
|
||||
log_1.log.disableProgress();
|
||||
fs_extra_1.default.moveSync(tempFile, file);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
})];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.downloadUrl = downloadUrl;
|
||||
function hash(filePath) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, new Promise(function (resolve, reject) {
|
||||
var resultHash = crypto_1.default.createHash('sha256');
|
||||
var input = fs_extra_1.default.createReadStream(filePath);
|
||||
input.on('error', function (e) {
|
||||
reject(e);
|
||||
});
|
||||
input.on('readable', function () {
|
||||
var data = input.read();
|
||||
if (data) {
|
||||
resultHash.update(data);
|
||||
}
|
||||
else {
|
||||
resolve(resultHash.digest('hex'));
|
||||
}
|
||||
});
|
||||
})];
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.hash = hash;
|
||||
function plusx(file) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var s, newMode, base8;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, fs_extra_1.default.stat(file)];
|
||||
case 1:
|
||||
s = _a.sent();
|
||||
newMode = s.mode | 64 | 8 | 1;
|
||||
if (s.mode === newMode)
|
||||
return [2 /*return*/];
|
||||
base8 = newMode.toString(8).slice(-3);
|
||||
return [4 /*yield*/, fs_extra_1.default.chmod(file, base8)];
|
||||
case 2:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.plusx = plusx;
|
||||
function spawn(command, args, options) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var error;
|
||||
return __generator(this, function (_a) {
|
||||
error = (0, child_process_1.spawnSync)(command, args, options).error;
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
return [2 /*return*/];
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.spawn = spawn;
|
||||
//# sourceMappingURL=utils.js.map
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export declare function verify(local: string): Promise<void>;
|
||||
//# sourceMappingURL=verify.d.ts.map
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
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;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.verify = void 0;
|
||||
var child_process_1 = require("child_process");
|
||||
var utils_1 = require("./utils");
|
||||
var script = "\n var vm = require('vm');\n var assert = require('assert');\n var text = '(function () { return 42; })';\n var cd, fn, result;\n var modules = process.versions.modules | 0;\n var v8 = process.versions.v8.split('.').slice(0, 2).join('.');\n\n var s1 = new vm.Script(text, { filename: 's1', produceCachedData: true, sourceless: true });\n assert(s1.cachedDataProduced);\n cd = s1.cachedData;\n\n var kCpuFeaturesOffset, cpuFeatures;\n\n if (modules === 14) {\n } else\n if (modules === 46 || modules === 48 || modules === 51) {\n kCpuFeaturesOffset = 0x0c;\n } else\n if (modules === 57) {\n if (v8 === '6.2') {\n kCpuFeaturesOffset = 0x0c;\n } else\n if (v8 === '5.8') {\n kCpuFeaturesOffset = 0x0c;\n } else {\n kCpuFeaturesOffset = 0x10;\n }\n } else\n if (modules === 59) {\n kCpuFeaturesOffset = 0x0c;\n } else\n if (modules === 64) {\n kCpuFeaturesOffset = 0x0c;\n } else\n if (modules === 72) {\n // no cpu features anymore\n } else\n if (modules === 79) {\n // no cpu features anymore\n } else\n if (modules === 83) {\n // no cpu features anymore\n } else {\n assert(false, modules);\n }\n\n if (modules >= 46 && // no cpu_features field in 0.12\n process.arch !== 'arm' && // non-zero features even in sourceless mode in arm\n modules < 72) { // no cpu_features field in 12+\n cpuFeatures = cd.readUInt32LE(kCpuFeaturesOffset);\n assert(cpuFeatures === 0, 'CPU_FEATURES must be zero');\n }\n\n var s2 = new vm.Script(undefined, { filename: 's2', cachedData: cd, sourceless: true });\n fn = s2.runInThisContext();\n result = fn();\n assert.equal(result, 42);\n\n if (modules === 14) {\n } else\n if (modules === 46 || modules === 48 ||\n modules === 51 || modules === 57 || modules === 59 || modules === 64) {\n var paddedPayloadOffset = 0x48; // see SerializedCodeData::Payload()\n var index = paddedPayloadOffset + 10;\n cd[index] ^= 0xf0;\n var s3 = new vm.Script(undefined, { filename: 's3', cachedData: cd, sourceless: true });\n assert(s3.cachedDataRejected, 's3.cachedDataRejected must be true');\n } else\n if (modules === 72) {\n } else\n if (modules === 79) {\n } else\n if (modules === 83) {\n } else {\n assert(false, modules);\n }\n\n var s4 = new vm.Script(text, { filename: 's4', produceCachedData: true });\n assert(s4.cachedDataProduced, 's4.cachedDataProduced must be true');\n cd = s4.cachedData;\n\n if (modules >= 46 && // no cpu_features field in 0.12\n process.arch !== 'arm' && // zero features even in non-sourceless mode in arm\n modules < 72) { // no cpu_features field in 12+\n cpuFeatures = cd.readUInt32LE(kCpuFeaturesOffset);\n assert(cpuFeatures !== 0, 'CPU_FEATURES must be non-zero');\n }\n\n console.log('ok');\n";
|
||||
function verify(local) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, (0, utils_1.plusx)(local)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
(0, child_process_1.spawnSync)(local, ['-e', script], {
|
||||
env: { PKG_EXECPATH: 'PKG_INVOKE_NODEJS' },
|
||||
stdio: 'inherit',
|
||||
});
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.verify = verify;
|
||||
//# sourceMappingURL=verify.js.map
|
||||
Reference in new issue
Block a user