@yao-pkg/pkg-fetch 3.5.31 → 3.5.33

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.
package/lib-es5/build.js CHANGED
@@ -1,91 +1,35 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
- if (ar || !(i in from)) {
52
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
- ar[i] = from[i];
54
- }
55
- }
56
- return to.concat(ar || Array.prototype.slice.call(from));
57
- };
58
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
59
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
60
4
  };
61
5
  Object.defineProperty(exports, "__esModule", { value: true });
62
6
  exports.prepBuildPath = exports.fetchExtractApply = void 0;
63
- var zlib_1 = require("zlib");
64
- var crypto_1 = __importDefault(require("crypto"));
65
- var fs_1 = require("fs");
66
- var promises_1 = require("fs/promises");
67
- var os_1 = __importDefault(require("os"));
68
- var path_1 = __importDefault(require("path"));
69
- var stream_1 = require("stream");
70
- var util_1 = require("util");
71
- var tar_fs_1 = __importDefault(require("tar-fs"));
72
- var places_1 = require("./places");
73
- var utils_1 = require("./utils");
74
- var system_1 = require("./system");
75
- var log_1 = require("./log");
76
- var patches_json_1 = __importDefault(require("../patches/patches.json"));
77
- var buildPath = path_1.default.resolve(process.env.PKG_BUILD_PATH ||
78
- path_1.default.join(os_1.default.tmpdir(), "pkg.".concat(crypto_1.default.randomBytes(12).toString('hex'))));
79
- var nodePath = path_1.default.join(buildPath, 'node');
80
- var patchesPath = path_1.default.resolve(__dirname, '../patches');
81
- var nodeRepo = 'https://nodejs.org/dist';
82
- var nodeArchivePath = path_1.default.join(places_1.cachePath, 'node');
7
+ const zlib_1 = require("zlib");
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const fs_1 = require("fs");
10
+ const promises_1 = require("fs/promises");
11
+ const os_1 = __importDefault(require("os"));
12
+ const path_1 = __importDefault(require("path"));
13
+ const stream_1 = require("stream");
14
+ const util_1 = require("util");
15
+ const tar_fs_1 = __importDefault(require("tar-fs"));
16
+ const places_1 = require("./places");
17
+ const utils_1 = require("./utils");
18
+ const system_1 = require("./system");
19
+ const log_1 = require("./log");
20
+ const patches_json_1 = __importDefault(require("../patches/patches.json"));
21
+ const buildPath = path_1.default.resolve(process.env.PKG_BUILD_PATH ||
22
+ path_1.default.join(os_1.default.tmpdir(), `pkg.${crypto_1.default.randomBytes(12).toString('hex')}`));
23
+ const nodePath = path_1.default.join(buildPath, 'node');
24
+ const patchesPath = path_1.default.resolve(__dirname, '../patches');
25
+ const nodeRepo = 'https://nodejs.org/dist';
26
+ const nodeArchivePath = path_1.default.join(places_1.cachePath, 'node');
83
27
  function getMajor(nodeVersion) {
84
- var _a = nodeVersion.match(/^v?(\d+)/) || ['', 0], version = _a[1];
28
+ const [, version] = nodeVersion.match(/^v?(\d+)/) || ['', 0];
85
29
  return Number(version) | 0;
86
30
  }
87
31
  function getConfigureArgs(major, targetPlatform, targetArch) {
88
- var args = [];
32
+ const args = [];
89
33
  // first of all v8_inspector introduces the use
90
34
  // of `prime_rehash_policy` symbol that requires
91
35
  // GLIBCXX_3.4.18 on some systems
@@ -131,336 +75,196 @@ function getConfigureArgs(major, targetPlatform, targetArch) {
131
75
  }
132
76
  return args;
133
77
  }
134
- function tarFetch(nodeVersion) {
135
- return __awaiter(this, void 0, void 0, function () {
136
- var distUrl, tarName, archivePath, hashPath, _a, _b;
137
- return __generator(this, function (_c) {
138
- switch (_c.label) {
139
- case 0:
140
- log_1.log.info('Fetching Node.js source archive from nodejs.org...');
141
- distUrl = "".concat(nodeRepo, "/").concat(nodeVersion);
142
- tarName = "node-".concat(nodeVersion, ".tar.gz");
143
- archivePath = path_1.default.join(nodeArchivePath, tarName);
144
- hashPath = path_1.default.join(nodeArchivePath, "".concat(tarName, ".sha256sum"));
145
- if ((0, fs_1.existsSync)(hashPath) && (0, fs_1.existsSync)(archivePath)) {
146
- return [2 /*return*/];
147
- }
148
- return [4 /*yield*/, (0, promises_1.rm)(hashPath, { recursive: true, force: true }).catch(function () { return undefined; })];
149
- case 1:
150
- _c.sent();
151
- return [4 /*yield*/, (0, promises_1.rm)(archivePath, { recursive: true, force: true }).catch(function () { return undefined; })];
152
- case 2:
153
- _c.sent();
154
- return [4 /*yield*/, (0, utils_1.downloadUrl)("".concat(distUrl, "/SHASUMS256.txt"), hashPath)];
155
- case 3:
156
- _c.sent();
157
- _a = promises_1.writeFile;
158
- _b = [hashPath];
159
- return [4 /*yield*/, (0, promises_1.readFile)(hashPath, 'utf8')];
160
- case 4: return [4 /*yield*/, _a.apply(void 0, _b.concat([(_c.sent())
161
- .split('\n')
162
- .filter(function (l) { return l.includes(tarName); })[0]]))];
163
- case 5:
164
- _c.sent();
165
- return [4 /*yield*/, (0, utils_1.downloadUrl)("".concat(distUrl, "/").concat(tarName), archivePath)];
166
- case 6:
167
- _c.sent();
168
- return [2 /*return*/];
169
- }
170
- });
171
- });
78
+ async function tarFetch(nodeVersion) {
79
+ log_1.log.info('Fetching Node.js source archive from nodejs.org...');
80
+ const distUrl = `${nodeRepo}/${nodeVersion}`;
81
+ const tarName = `node-${nodeVersion}.tar.gz`;
82
+ const archivePath = path_1.default.join(nodeArchivePath, tarName);
83
+ const hashPath = path_1.default.join(nodeArchivePath, `${tarName}.sha256sum`);
84
+ if ((0, fs_1.existsSync)(hashPath) && (0, fs_1.existsSync)(archivePath)) {
85
+ return;
86
+ }
87
+ await (0, promises_1.rm)(hashPath, { recursive: true, force: true }).catch(() => undefined);
88
+ await (0, promises_1.rm)(archivePath, { recursive: true, force: true }).catch(() => undefined);
89
+ await (0, utils_1.downloadUrl)(`${distUrl}/SHASUMS256.txt`, hashPath);
90
+ await (0, promises_1.writeFile)(hashPath, (await (0, promises_1.readFile)(hashPath, 'utf8'))
91
+ .split('\n')
92
+ .filter((l) => l.includes(tarName))[0]);
93
+ await (0, utils_1.downloadUrl)(`${distUrl}/${tarName}`, archivePath);
172
94
  }
173
- function tarExtract(nodeVersion, suppressTarOutput) {
174
- return __awaiter(this, void 0, void 0, function () {
175
- var tarName, expectedHash, actualHash, pipe, source, gunzip, extract;
176
- return __generator(this, function (_a) {
177
- switch (_a.label) {
178
- case 0:
179
- log_1.log.info('Extracting Node.js source archive...');
180
- tarName = "node-".concat(nodeVersion, ".tar.gz");
181
- return [4 /*yield*/, (0, promises_1.readFile)(path_1.default.join(nodeArchivePath, "".concat(tarName, ".sha256sum")), 'utf8')];
182
- case 1:
183
- expectedHash = (_a.sent()).split(' ')[0];
184
- return [4 /*yield*/, (0, utils_1.hash)(path_1.default.join(nodeArchivePath, tarName))];
185
- case 2:
186
- actualHash = _a.sent();
187
- if (!(expectedHash !== actualHash)) return [3 /*break*/, 5];
188
- return [4 /*yield*/, (0, promises_1.rm)(path_1.default.join(nodeArchivePath, tarName), {
189
- recursive: true,
190
- force: true,
191
- })];
192
- case 3:
193
- _a.sent();
194
- return [4 /*yield*/, (0, promises_1.rm)(path_1.default.join(nodeArchivePath, "".concat(tarName, ".sha256sum")), {
195
- recursive: true,
196
- force: true,
197
- })];
198
- case 4:
199
- _a.sent();
200
- throw (0, log_1.wasReported)("Hash mismatch for ".concat(tarName));
201
- case 5:
202
- pipe = (0, util_1.promisify)(stream_1.pipeline);
203
- source = (0, fs_1.createReadStream)(path_1.default.join(nodeArchivePath, tarName));
204
- gunzip = (0, zlib_1.createGunzip)();
205
- extract = tar_fs_1.default.extract(nodePath, {
206
- strip: 1,
207
- map: function (header) {
208
- if (!suppressTarOutput) {
209
- // disabled for now - can't get cmdline flag to work with all builds
210
- // log.info(header.name);
211
- }
212
- return header;
213
- },
214
- });
215
- return [4 /*yield*/, pipe(source, gunzip, extract)];
216
- case 6:
217
- _a.sent();
218
- return [2 /*return*/];
219
- }
95
+ async function tarExtract(nodeVersion, suppressTarOutput) {
96
+ log_1.log.info('Extracting Node.js source archive...');
97
+ const tarName = `node-${nodeVersion}.tar.gz`;
98
+ const expectedHash = (await (0, promises_1.readFile)(path_1.default.join(nodeArchivePath, `${tarName}.sha256sum`), 'utf8')).split(' ')[0];
99
+ const actualHash = await (0, utils_1.hash)(path_1.default.join(nodeArchivePath, tarName));
100
+ if (expectedHash !== actualHash) {
101
+ await (0, promises_1.rm)(path_1.default.join(nodeArchivePath, tarName), {
102
+ recursive: true,
103
+ force: true,
220
104
  });
221
- });
222
- }
223
- function applyPatches(nodeVersion) {
224
- return __awaiter(this, void 0, void 0, function () {
225
- var storedPatches, storedPatch, patches, _i, patches_1, patch, patchPath, args;
226
- return __generator(this, function (_a) {
227
- switch (_a.label) {
228
- case 0:
229
- log_1.log.info('Applying patches');
230
- storedPatches = patches_json_1.default[nodeVersion];
231
- storedPatch = 'patches' in storedPatches ? storedPatches.patches : storedPatches;
232
- patches = 'sameAs' in storedPatch
233
- ? patches_json_1.default[storedPatch.sameAs]
234
- : storedPatch;
235
- _i = 0, patches_1 = patches;
236
- _a.label = 1;
237
- case 1:
238
- if (!(_i < patches_1.length)) return [3 /*break*/, 4];
239
- patch = patches_1[_i];
240
- patchPath = path_1.default.join(patchesPath, patch);
241
- args = ['-p1', '-i', patchPath];
242
- return [4 /*yield*/, (0, utils_1.spawn)('patch', args, { cwd: nodePath, stdio: 'inherit' })];
243
- case 2:
244
- _a.sent();
245
- _a.label = 3;
246
- case 3:
247
- _i++;
248
- return [3 /*break*/, 1];
249
- case 4: return [2 /*return*/];
250
- }
105
+ await (0, promises_1.rm)(path_1.default.join(nodeArchivePath, `${tarName}.sha256sum`), {
106
+ recursive: true,
107
+ force: true,
251
108
  });
252
- });
253
- }
254
- function fetchExtractApply(nodeVersion, quietExtraction) {
255
- return __awaiter(this, void 0, void 0, function () {
256
- return __generator(this, function (_a) {
257
- switch (_a.label) {
258
- case 0: return [4 /*yield*/, tarFetch(nodeVersion)];
259
- case 1:
260
- _a.sent();
261
- return [4 /*yield*/, tarExtract(nodeVersion, quietExtraction)];
262
- case 2:
263
- _a.sent();
264
- return [4 /*yield*/, applyPatches(nodeVersion)];
265
- case 3:
266
- _a.sent();
267
- return [2 /*return*/];
109
+ throw (0, log_1.wasReported)(`Hash mismatch for ${tarName}`);
110
+ }
111
+ const pipe = (0, util_1.promisify)(stream_1.pipeline);
112
+ const source = (0, fs_1.createReadStream)(path_1.default.join(nodeArchivePath, tarName));
113
+ const gunzip = (0, zlib_1.createGunzip)();
114
+ const extract = tar_fs_1.default.extract(nodePath, {
115
+ strip: 1,
116
+ map: (header) => {
117
+ if (!suppressTarOutput) {
118
+ // disabled for now - can't get cmdline flag to work with all builds
119
+ // log.info(header.name);
268
120
  }
269
- });
121
+ return header;
122
+ },
270
123
  });
124
+ await pipe(source, gunzip, extract);
125
+ }
126
+ async function applyPatches(nodeVersion) {
127
+ log_1.log.info('Applying patches');
128
+ const storedPatches = patches_json_1.default[nodeVersion];
129
+ const storedPatch = 'patches' in storedPatches ? storedPatches.patches : storedPatches;
130
+ const patches = 'sameAs' in storedPatch
131
+ ? patches_json_1.default[storedPatch.sameAs]
132
+ : storedPatch;
133
+ for (const patch of patches) {
134
+ const patchPath = path_1.default.join(patchesPath, patch);
135
+ const args = ['-p1', '-i', patchPath];
136
+ await (0, utils_1.spawn)('patch', args, { cwd: nodePath, stdio: 'inherit' });
137
+ }
138
+ }
139
+ async function fetchExtractApply(nodeVersion, quietExtraction) {
140
+ await tarFetch(nodeVersion);
141
+ await tarExtract(nodeVersion, quietExtraction);
142
+ await applyPatches(nodeVersion);
271
143
  }
272
144
  exports.fetchExtractApply = fetchExtractApply;
273
- function compileOnWindows(nodeVersion, targetArch, targetPlatform) {
274
- return __awaiter(this, void 0, void 0, function () {
275
- var args, major, config_flags;
276
- return __generator(this, function (_a) {
277
- switch (_a.label) {
278
- case 0:
279
- args = ['/c', 'vcbuild.bat', targetArch];
280
- major = getMajor(nodeVersion);
281
- config_flags = getConfigureArgs(major, targetPlatform, targetArch);
282
- // The dtrace and etw support was removed in https://github.com/nodejs/node/commit/aa3a572e6bee116cde69508dc29478b40f40551a
283
- if (major <= 18) {
284
- // Event Tracing for Windows
285
- args.push('noetw');
286
- }
287
- // Performance counters on Windows
288
- if (major <= 10) {
289
- args.push('noperfctr');
290
- }
291
- // Link Time Code Generation
292
- if (major >= 12) {
293
- args.push('ltcg');
294
- }
295
- // Node24 builds on Windows crash with small-icu at icudat codegen
296
- // workaround for now is to enable full-icu
297
- // TODO check with newer node/tooling/gh-image versions
298
- if (major >= 24) {
299
- args.push('full-icu');
300
- }
301
- // Can't cross compile for arm64 with small-icu
302
- if (major < 24 &&
303
- system_1.hostArch !== targetArch &&
304
- !config_flags.includes('--with-intl=full-icu')) {
305
- config_flags.push('--without-intl');
306
- }
307
- return [4 /*yield*/, (0, utils_1.spawn)('cmd', args, {
308
- cwd: nodePath,
309
- env: __assign(__assign({}, process.env), { config_flags: config_flags.join(' ') }),
310
- stdio: 'inherit',
311
- })];
312
- case 1:
313
- _a.sent();
314
- if (major <= 10) {
315
- return [2 /*return*/, path_1.default.join(nodePath, 'Release/node.exe')];
316
- }
317
- return [2 /*return*/, path_1.default.join(nodePath, 'out/Release/node.exe')];
318
- }
319
- });
145
+ async function compileOnWindows(nodeVersion, targetArch, targetPlatform) {
146
+ const args = ['/c', 'vcbuild.bat', targetArch];
147
+ const major = getMajor(nodeVersion);
148
+ const config_flags = getConfigureArgs(major, targetPlatform, targetArch);
149
+ // The dtrace and etw support was removed in https://github.com/nodejs/node/commit/aa3a572e6bee116cde69508dc29478b40f40551a
150
+ if (major <= 18) {
151
+ // Event Tracing for Windows
152
+ args.push('noetw');
153
+ }
154
+ // Performance counters on Windows
155
+ if (major <= 10) {
156
+ args.push('noperfctr');
157
+ }
158
+ // Link Time Code Generation
159
+ if (major >= 12) {
160
+ args.push('ltcg');
161
+ }
162
+ // Node24 builds on Windows crash with small-icu at icudat codegen
163
+ // workaround for now is to enable full-icu
164
+ // TODO check with newer node/tooling/gh-image versions
165
+ if (major >= 24) {
166
+ args.push('full-icu');
167
+ }
168
+ // Can't cross compile for arm64 with small-icu
169
+ if (major < 24 &&
170
+ system_1.hostArch !== targetArch &&
171
+ !config_flags.includes('--with-intl=full-icu')) {
172
+ config_flags.push('--without-intl');
173
+ }
174
+ await (0, utils_1.spawn)('cmd', args, {
175
+ cwd: nodePath,
176
+ env: { ...process.env, config_flags: config_flags.join(' ') },
177
+ stdio: 'inherit',
320
178
  });
179
+ if (major <= 10) {
180
+ return path_1.default.join(nodePath, 'Release/node.exe');
181
+ }
182
+ return path_1.default.join(nodePath, 'out/Release/node.exe');
321
183
  }
322
- var _a = process.env.MAKE_JOB_COUNT, MAKE_JOB_COUNT = _a === void 0 ? os_1.default.cpus().length : _a;
323
- function compileOnUnix(nodeVersion, targetArch, targetPlatform) {
324
- return __awaiter(this, void 0, void 0, function () {
325
- var args, cpu, _a, _b, CFLAGS, _c, CXXFLAGS, _d, _e, CFLAGS, _f, CXXFLAGS, _g, LDFLAGS, output;
326
- return __generator(this, function (_h) {
327
- switch (_h.label) {
328
- case 0:
329
- args = [];
330
- cpu = {
331
- x86: 'ia32',
332
- x64: 'x64',
333
- armv6: 'arm',
334
- armv7: 'arm',
335
- arm64: 'arm64',
336
- ppc64: 'ppc64',
337
- s390x: 's390x',
338
- }[targetArch];
339
- if (cpu) {
340
- args.push('--dest-cpu', cpu);
341
- }
342
- if (targetArch === 'armv7') {
343
- _a = process.env, _b = _a.CFLAGS, CFLAGS = _b === void 0 ? '' : _b, _c = _a.CXXFLAGS, CXXFLAGS = _c === void 0 ? '' : _c;
344
- process.env.CFLAGS = "".concat(CFLAGS, " -marm -mcpu=cortex-a7 -mfpu=vfpv3");
345
- process.env.CXXFLAGS = "".concat(CXXFLAGS, " -marm -mcpu=cortex-a7 -mfpu=vfpv3");
346
- args.push('--with-arm-float-abi=hard');
347
- args.push('--with-arm-fpu=vfpv3');
348
- }
349
- // macos cross-build from arm64 to x64
350
- if (targetPlatform === "macos" && system_1.hostArch === 'arm64' && targetArch === 'x64') {
351
- _d = process.env, _e = _d.CFLAGS, CFLAGS = _e === void 0 ? '' : _e, _f = _d.CXXFLAGS, CXXFLAGS = _f === void 0 ? '' : _f, _g = _d.LDFLAGS, LDFLAGS = _g === void 0 ? '' : _g;
352
- process.env.CFLAGS = "".concat(CFLAGS, " -arch x86_64");
353
- process.env.CXXFLAGS = "".concat(CXXFLAGS, " -arch x86_64");
354
- process.env.LDFLAGS = "".concat(LDFLAGS, " -arch x86_64");
355
- }
356
- if (system_1.hostArch !== targetArch) {
357
- log_1.log.warn('Cross compiling!');
358
- log_1.log.warn('You are responsible for appropriate env like CC, CC_host, etc.');
359
- args.push('--cross-compiling');
360
- }
361
- args.push.apply(args, getConfigureArgs(getMajor(nodeVersion), targetPlatform, targetArch));
362
- log_1.log.info("Running configure with: ", args.join(" "));
363
- // TODO same for windows?
364
- return [4 /*yield*/, (0, utils_1.spawn)('/bin/sh', __spreadArray(['./configure'], args, true), {
365
- cwd: nodePath,
366
- stdio: 'inherit',
367
- })];
368
- case 1:
369
- // TODO same for windows?
370
- _h.sent();
371
- return [4 /*yield*/, (0, utils_1.spawn)(system_1.hostPlatform === 'freebsd' ? 'gmake' : 'make', ['-j', String(MAKE_JOB_COUNT)], {
372
- cwd: nodePath,
373
- stdio: 'inherit',
374
- })];
375
- case 2:
376
- _h.sent();
377
- output = path_1.default.join(nodePath, 'out/Release/node');
378
- return [4 /*yield*/, (0, utils_1.spawn)(process.env.STRIP || 'strip', __spreadArray(__spreadArray([], (targetPlatform === 'macos' ? ['-x'] : []), true), [output], false), {
379
- stdio: 'inherit',
380
- })];
381
- case 3:
382
- _h.sent();
383
- if (!(targetPlatform === 'macos')) return [3 /*break*/, 5];
384
- // Newer versions of Apple Clang automatically ad-hoc sign the compiled executable.
385
- // However, for final executable to be signable, base binary MUST NOT have an existing signature.
386
- return [4 /*yield*/, (0, utils_1.spawn)('codesign', ['--remove-signature', output], {
387
- stdio: 'inherit',
388
- })];
389
- case 4:
390
- // Newer versions of Apple Clang automatically ad-hoc sign the compiled executable.
391
- // However, for final executable to be signable, base binary MUST NOT have an existing signature.
392
- _h.sent();
393
- _h.label = 5;
394
- case 5: return [2 /*return*/, output];
395
- }
396
- });
184
+ const { MAKE_JOB_COUNT = os_1.default.cpus().length } = process.env;
185
+ async function compileOnUnix(nodeVersion, targetArch, targetPlatform) {
186
+ const args = [];
187
+ const cpu = {
188
+ x86: 'ia32',
189
+ x64: 'x64',
190
+ armv6: 'arm',
191
+ armv7: 'arm',
192
+ arm64: 'arm64',
193
+ ppc64: 'ppc64',
194
+ s390x: 's390x',
195
+ }[targetArch];
196
+ if (cpu) {
197
+ args.push('--dest-cpu', cpu);
198
+ }
199
+ if (targetArch === 'armv7') {
200
+ const { CFLAGS = '', CXXFLAGS = '' } = process.env;
201
+ process.env.CFLAGS = `${CFLAGS} -marm -mcpu=cortex-a7 -mfpu=vfpv3`;
202
+ process.env.CXXFLAGS = `${CXXFLAGS} -marm -mcpu=cortex-a7 -mfpu=vfpv3`;
203
+ args.push('--with-arm-float-abi=hard');
204
+ args.push('--with-arm-fpu=vfpv3');
205
+ }
206
+ // macos cross-build from arm64 to x64
207
+ if (targetPlatform === "macos" && system_1.hostArch === 'arm64' && targetArch === 'x64') {
208
+ const { CFLAGS = '', CXXFLAGS = '', LDFLAGS = '' } = process.env;
209
+ process.env.CFLAGS = `${CFLAGS} -arch x86_64`;
210
+ process.env.CXXFLAGS = `${CXXFLAGS} -arch x86_64`;
211
+ process.env.LDFLAGS = `${LDFLAGS} -arch x86_64`;
212
+ }
213
+ if (system_1.hostArch !== targetArch) {
214
+ log_1.log.warn('Cross compiling!');
215
+ log_1.log.warn('You are responsible for appropriate env like CC, CC_host, etc.');
216
+ args.push('--cross-compiling');
217
+ }
218
+ args.push(...getConfigureArgs(getMajor(nodeVersion), targetPlatform, targetArch));
219
+ log_1.log.info("Running configure with: ", args.join(" "));
220
+ // TODO same for windows?
221
+ await (0, utils_1.spawn)('/bin/sh', ['./configure', ...args], {
222
+ cwd: nodePath,
223
+ stdio: 'inherit',
397
224
  });
398
- }
399
- function compile(nodeVersion, targetArch, targetPlatform) {
400
- return __awaiter(this, void 0, void 0, function () {
401
- var win;
402
- return __generator(this, function (_a) {
403
- log_1.log.info('Compiling Node.js from sources...');
404
- win = system_1.hostPlatform === 'win';
405
- if (win) {
406
- return [2 /*return*/, compileOnWindows(nodeVersion, targetArch, targetPlatform)];
407
- }
408
- return [2 /*return*/, compileOnUnix(nodeVersion, targetArch, targetPlatform)];
409
- });
225
+ await (0, utils_1.spawn)(system_1.hostPlatform === 'freebsd' ? 'gmake' : 'make', ['-j', String(MAKE_JOB_COUNT)], {
226
+ cwd: nodePath,
227
+ stdio: 'inherit',
410
228
  });
411
- }
412
- function prepBuildPath() {
413
- return __awaiter(this, void 0, void 0, function () {
414
- return __generator(this, function (_a) {
415
- switch (_a.label) {
416
- case 0: return [4 /*yield*/, (0, promises_1.rm)(buildPath, { recursive: true, force: true })];
417
- case 1:
418
- _a.sent();
419
- return [4 /*yield*/, (0, promises_1.mkdir)(nodePath, { recursive: true })];
420
- case 2:
421
- _a.sent();
422
- return [4 /*yield*/, (0, promises_1.mkdir)(nodeArchivePath, { recursive: true })];
423
- case 3:
424
- _a.sent();
425
- return [2 /*return*/];
426
- }
427
- });
229
+ const output = path_1.default.join(nodePath, 'out/Release/node');
230
+ await (0, utils_1.spawn)(process.env.STRIP || 'strip',
231
+ // global symbols are required for native bindings on macOS
232
+ [...(targetPlatform === 'macos' ? ['-x'] : []), output], {
233
+ stdio: 'inherit',
428
234
  });
235
+ if (targetPlatform === 'macos') {
236
+ // Newer versions of Apple Clang automatically ad-hoc sign the compiled executable.
237
+ // However, for final executable to be signable, base binary MUST NOT have an existing signature.
238
+ await (0, utils_1.spawn)('codesign', ['--remove-signature', output], {
239
+ stdio: 'inherit',
240
+ });
241
+ }
242
+ return output;
243
+ }
244
+ async function compile(nodeVersion, targetArch, targetPlatform) {
245
+ log_1.log.info('Compiling Node.js from sources...');
246
+ const win = system_1.hostPlatform === 'win';
247
+ if (win) {
248
+ return compileOnWindows(nodeVersion, targetArch, targetPlatform);
249
+ }
250
+ return compileOnUnix(nodeVersion, targetArch, targetPlatform);
251
+ }
252
+ async function prepBuildPath() {
253
+ await (0, promises_1.rm)(buildPath, { recursive: true, force: true });
254
+ await (0, promises_1.mkdir)(nodePath, { recursive: true });
255
+ await (0, promises_1.mkdir)(nodeArchivePath, { recursive: true });
429
256
  }
430
257
  exports.prepBuildPath = prepBuildPath;
431
- function build(nodeVersion, targetArch, targetPlatform, local) {
432
- return __awaiter(this, void 0, void 0, function () {
433
- var output, outputHash;
434
- return __generator(this, function (_a) {
435
- switch (_a.label) {
436
- case 0: return [4 /*yield*/, prepBuildPath()];
437
- case 1:
438
- _a.sent();
439
- return [4 /*yield*/, fetchExtractApply(nodeVersion, false)];
440
- case 2:
441
- _a.sent();
442
- return [4 /*yield*/, compile(nodeVersion, targetArch, targetPlatform)];
443
- case 3:
444
- output = _a.sent();
445
- return [4 /*yield*/, (0, utils_1.hash)(output)];
446
- case 4:
447
- outputHash = _a.sent();
448
- return [4 /*yield*/, (0, promises_1.mkdir)(path_1.default.dirname(local), { recursive: true })];
449
- case 5:
450
- _a.sent();
451
- return [4 /*yield*/, (0, promises_1.cp)(output, local)];
452
- case 6:
453
- _a.sent();
454
- return [4 /*yield*/, (0, promises_1.writeFile)("".concat(local, ".sha256sum"), "".concat(outputHash, " ").concat(path_1.default.basename(local), "\n"))];
455
- case 7:
456
- _a.sent();
457
- return [4 /*yield*/, (0, promises_1.rm)(buildPath, { recursive: true, force: true })];
458
- case 8:
459
- _a.sent();
460
- return [2 /*return*/];
461
- }
462
- });
463
- });
258
+ async function build(nodeVersion, targetArch, targetPlatform, local) {
259
+ await prepBuildPath();
260
+ await fetchExtractApply(nodeVersion, false);
261
+ const output = await compile(nodeVersion, targetArch, targetPlatform);
262
+ const outputHash = await (0, utils_1.hash)(output);
263
+ await (0, promises_1.mkdir)(path_1.default.dirname(local), { recursive: true });
264
+ await (0, promises_1.cp)(output, local);
265
+ await (0, promises_1.writeFile)(`${local}.sha256sum`, `${outputHash} ${path_1.default.basename(local)}
266
+ `);
267
+ await (0, promises_1.rm)(buildPath, { recursive: true, force: true });
464
268
  }
465
269
  exports.default = build;
466
270
  //# sourceMappingURL=build.js.map