react-native-update-cli 2.29.0 → 2.29.1
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/api.js +9 -29
- package/lib/bundle-pack.js +6 -38
- package/lib/bundle-runner.js +36 -67
- package/lib/diff.js +18 -49
- package/lib/native-package.js +10 -42
- package/lib/package.js +6 -38
- package/lib/utils/app-info-parser/aab.js +6 -38
- package/lib/utils/app-info-parser/resource-finder.d.ts +5 -13
- package/lib/utils/app-info-parser/resource-finder.js +63 -60
- package/lib/utils/fs-helpers.d.ts +13 -0
- package/lib/utils/fs-helpers.js +65 -0
- package/lib/utils/hermes-base.js +50 -47
- package/lib/utils/plugin-config.js +6 -36
- package/lib/utils/runtime.d.ts +1 -1
- package/lib/utils/runtime.js +2 -10
- package/lib/utils/upload-request.d.ts +33 -0
- package/lib/utils/upload-request.js +120 -0
- package/lib/utils/zip-entries.js +7 -39
- package/lib/utils/zip-range.js +4 -4
- package/lib/utils/zip-raw-writer.js +6 -5
- package/package.json +1 -7
package/lib/utils/hermes-base.js
CHANGED
|
@@ -76,13 +76,14 @@ exports.verifyHermesBaseEquivalence = verifyHermesBaseEquivalence;
|
|
|
76
76
|
const node_string_decoder_1 = require("node:string_decoder");
|
|
77
77
|
const child_process_1 = require("child_process");
|
|
78
78
|
const crypto_1 = require("crypto");
|
|
79
|
-
const
|
|
79
|
+
const fs_1 = __importDefault(require("fs"));
|
|
80
80
|
const os_1 = __importDefault(require("os"));
|
|
81
81
|
const path_1 = __importDefault(require("path"));
|
|
82
82
|
const stream_1 = require("stream");
|
|
83
83
|
const promises_1 = require("stream/promises");
|
|
84
84
|
const constants_1 = require("./constants");
|
|
85
85
|
const failure_fingerprint_1 = require("./failure-fingerprint");
|
|
86
|
+
const fs_helpers_1 = require("./fs-helpers");
|
|
86
87
|
const hbcTransform_1 = require("./hbcTransform");
|
|
87
88
|
const hermes_cached_object_1 = require("./hermes-cached-object");
|
|
88
89
|
const hermes_literals_1 = require("./hermes-literals");
|
|
@@ -162,7 +163,7 @@ function classifyHermesCommand(hermesCommand) {
|
|
|
162
163
|
const packageRoot = normalized.slice(0, match.index + match[0].length);
|
|
163
164
|
let version = '';
|
|
164
165
|
try {
|
|
165
|
-
version = String(JSON.parse(
|
|
166
|
+
version = String(JSON.parse(fs_1.default.readFileSync(path_1.default.join(packageRoot, 'package.json'), 'utf8')).version ?? '');
|
|
166
167
|
}
|
|
167
168
|
catch {
|
|
168
169
|
return {
|
|
@@ -230,23 +231,23 @@ function sha256Hex(data) {
|
|
|
230
231
|
/** sha256 of a file, streamed (a cached base can be tens of MB) */
|
|
231
232
|
async function sha256File(file) {
|
|
232
233
|
const hash = (0, crypto_1.createHash)('sha256');
|
|
233
|
-
for await (const chunk of
|
|
234
|
+
for await (const chunk of fs_1.default.createReadStream(file))
|
|
234
235
|
hash.update(chunk);
|
|
235
236
|
return hash.digest('hex');
|
|
236
237
|
}
|
|
237
238
|
/** HBC version from the first bytes of a file, without reading the rest */
|
|
238
239
|
async function readFileHbcVersion(file) {
|
|
239
240
|
const header = Buffer.alloc(128);
|
|
240
|
-
const
|
|
241
|
+
const handle = await fs_1.default.promises.open(file, 'r');
|
|
241
242
|
try {
|
|
242
|
-
const { bytesRead } = await
|
|
243
|
+
const { bytesRead } = await handle.read(header, 0, 128, 0);
|
|
243
244
|
return (0, hbcTransform_1.getHbcVersion)(header.subarray(0, bytesRead));
|
|
244
245
|
}
|
|
245
246
|
catch {
|
|
246
247
|
return null;
|
|
247
248
|
}
|
|
248
249
|
finally {
|
|
249
|
-
await
|
|
250
|
+
await handle.close();
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
const PROBE_CACHE_FILE = 'hbc-versions.json';
|
|
@@ -254,7 +255,7 @@ const PROBE_CACHE_ENTRIES = 16;
|
|
|
254
255
|
/** identity of a hermesc binary for the probe cache: path + size + mtime */
|
|
255
256
|
function probeCacheKey(hermesCommand) {
|
|
256
257
|
try {
|
|
257
|
-
const stat =
|
|
258
|
+
const stat = fs_1.default.statSync(hermesCommand);
|
|
258
259
|
return `${path_1.default.resolve(hermesCommand)}|${stat.size}|${Math.floor(stat.mtimeMs)}`;
|
|
259
260
|
}
|
|
260
261
|
catch {
|
|
@@ -263,7 +264,7 @@ function probeCacheKey(hermesCommand) {
|
|
|
263
264
|
}
|
|
264
265
|
function readProbeCache() {
|
|
265
266
|
try {
|
|
266
|
-
const parsed = JSON.parse(
|
|
267
|
+
const parsed = JSON.parse(fs_1.default.readFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), 'utf8'));
|
|
267
268
|
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
268
269
|
}
|
|
269
270
|
catch {
|
|
@@ -275,8 +276,8 @@ function writeProbeCache(entries) {
|
|
|
275
276
|
const keys = Object.keys(entries);
|
|
276
277
|
// keep the most recently inserted entries only
|
|
277
278
|
const trimmed = Object.fromEntries(keys.slice(-PROBE_CACHE_ENTRIES).map((key) => [key, entries[key]]));
|
|
278
|
-
|
|
279
|
-
|
|
279
|
+
(0, fs_helpers_1.ensureDirSync)(cacheDir());
|
|
280
|
+
fs_1.default.writeFileSync(path_1.default.join(cacheDir(), PROBE_CACHE_FILE), JSON.stringify(trimmed));
|
|
280
281
|
}
|
|
281
282
|
catch {
|
|
282
283
|
// the cache is a convenience; probing again next time is fine
|
|
@@ -303,26 +304,26 @@ function probeHbcVersion(hermesCommand) {
|
|
|
303
304
|
}
|
|
304
305
|
/** Compile an empty file to learn which HBC version this hermesc emits. */
|
|
305
306
|
function compileProbe(hermesCommand) {
|
|
306
|
-
const dir =
|
|
307
|
+
const dir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'rnu-hermes-probe-'));
|
|
307
308
|
try {
|
|
308
309
|
const input = path_1.default.join(dir, 'probe.js');
|
|
309
310
|
const output = path_1.default.join(dir, 'probe.hbc');
|
|
310
|
-
|
|
311
|
+
fs_1.default.writeFileSync(input, '');
|
|
311
312
|
const result = (0, child_process_1.spawnSync)(hermesCommand, ['-emit-binary', '-out', output, input, '-O', '-w'], {
|
|
312
313
|
stdio: 'ignore',
|
|
313
314
|
timeout: (0, hermes_timeout_1.hermesTimeout)(process.env.PUSHY_HERMES_PROBE_TIMEOUT_MS, 30_000),
|
|
314
315
|
killSignal: 'SIGKILL',
|
|
315
316
|
});
|
|
316
|
-
if (result.status !== 0 || !
|
|
317
|
+
if (result.status !== 0 || !fs_1.default.existsSync(output)) {
|
|
317
318
|
return null;
|
|
318
319
|
}
|
|
319
320
|
const header = Buffer.alloc(128);
|
|
320
|
-
const fd =
|
|
321
|
+
const fd = fs_1.default.openSync(output, 'r');
|
|
321
322
|
try {
|
|
322
|
-
|
|
323
|
+
fs_1.default.readSync(fd, header, 0, 128, 0);
|
|
323
324
|
}
|
|
324
325
|
finally {
|
|
325
|
-
|
|
326
|
+
fs_1.default.closeSync(fd);
|
|
326
327
|
}
|
|
327
328
|
return (0, hbcTransform_1.getHbcVersion)(header);
|
|
328
329
|
}
|
|
@@ -330,7 +331,7 @@ function compileProbe(hermesCommand) {
|
|
|
330
331
|
return null;
|
|
331
332
|
}
|
|
332
333
|
finally {
|
|
333
|
-
|
|
334
|
+
(0, fs_helpers_1.removeSync)(dir);
|
|
334
335
|
}
|
|
335
336
|
}
|
|
336
337
|
exports.BUNDLE_ENTRY_NAMES = [
|
|
@@ -362,7 +363,7 @@ async function extractBundleFromArchive(filePath) {
|
|
|
362
363
|
ext === '.jsbundle' ||
|
|
363
364
|
ext === '.bundlejs' ||
|
|
364
365
|
ext === '.js') {
|
|
365
|
-
return
|
|
366
|
+
return fs_1.default.promises.readFile(filePath);
|
|
366
367
|
}
|
|
367
368
|
if (ext === '.ppk' || ext === '.apk' || ext === '.ipa') {
|
|
368
369
|
return readFirstZipEntry(filePath, bundleEntryMatcher(ext.slice(1)));
|
|
@@ -378,7 +379,7 @@ async function extractBundleFromArchive(filePath) {
|
|
|
378
379
|
}
|
|
379
380
|
// unknown extension: try as zip, then as raw file
|
|
380
381
|
const fromZip = await readFirstZipEntry(filePath, (name) => exports.BUNDLE_ENTRY_NAMES.includes(name)).catch(() => null);
|
|
381
|
-
return fromZip ??
|
|
382
|
+
return fromZip ?? fs_1.default.promises.readFile(filePath);
|
|
382
383
|
}
|
|
383
384
|
async function readFirstZipEntry(zipPath, matches) {
|
|
384
385
|
let found = null;
|
|
@@ -414,53 +415,53 @@ async function cacheLookup(bundleHash) {
|
|
|
414
415
|
if (!/^[0-9a-f]{64}$/.test(bundleHash))
|
|
415
416
|
return null;
|
|
416
417
|
const file = path_1.default.join(cacheDir(), bundleHash);
|
|
417
|
-
if (!(await
|
|
418
|
+
if (!(await (0, fs_helpers_1.pathExists)(file)))
|
|
418
419
|
return null;
|
|
419
420
|
if ((await sha256File(file).catch(() => '')) !== bundleHash) {
|
|
420
421
|
// corrupt entry: never trust cache content
|
|
421
|
-
await
|
|
422
|
+
await (0, fs_helpers_1.remove)(file).catch(() => { });
|
|
422
423
|
return null;
|
|
423
424
|
}
|
|
424
425
|
const now = new Date();
|
|
425
|
-
await
|
|
426
|
+
await fs_1.default.promises.utimes(file, now, now).catch(() => { });
|
|
426
427
|
return file;
|
|
427
428
|
}
|
|
428
429
|
/** Store a bundle under its sha256 (LRU-evicting to the configured limits). */
|
|
429
430
|
async function cachePut(bundle, maxMb, knownHash) {
|
|
430
431
|
const bundleHash = knownHash ?? sha256Hex(bundle);
|
|
431
432
|
const dir = cacheDir();
|
|
432
|
-
await
|
|
433
|
+
await (0, fs_helpers_1.ensureDir)(dir);
|
|
433
434
|
const file = path_1.default.join(dir, bundleHash);
|
|
434
|
-
if (!(await
|
|
435
|
+
if (!(await (0, fs_helpers_1.pathExists)(file))) {
|
|
435
436
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
436
|
-
await
|
|
437
|
-
await
|
|
437
|
+
await fs_1.default.promises.writeFile(tmp, bundle);
|
|
438
|
+
await fs_1.default.promises.rename(tmp, file);
|
|
438
439
|
}
|
|
439
440
|
else {
|
|
440
441
|
const now = new Date();
|
|
441
|
-
await
|
|
442
|
+
await fs_1.default.promises.utimes(file, now, now).catch(() => { });
|
|
442
443
|
}
|
|
443
444
|
await enforceCacheLimits(maxMb, bundleHash);
|
|
444
445
|
return { path: file, bundleHash };
|
|
445
446
|
}
|
|
446
447
|
async function enforceCacheLimits(maxMb, keep) {
|
|
447
448
|
const dir = cacheDir();
|
|
448
|
-
if (!(await
|
|
449
|
+
if (!(await (0, fs_helpers_1.pathExists)(dir)))
|
|
449
450
|
return;
|
|
450
451
|
const { maxBytes, maxFiles } = cacheLimits(maxMb);
|
|
451
452
|
const entries = [];
|
|
452
453
|
const staleTmpCutoff = Date.now() - STALE_CACHE_TMP_MS;
|
|
453
|
-
for (const name of await
|
|
454
|
+
for (const name of await fs_1.default.promises.readdir(dir)) {
|
|
454
455
|
const isTmp = isCacheTmpName(name);
|
|
455
456
|
if (!isTmp && !/^[0-9a-f]{64}$/.test(name))
|
|
456
457
|
continue;
|
|
457
|
-
const stat = await
|
|
458
|
+
const stat = await fs_1.default.promises.stat(path_1.default.join(dir, name)).catch(() => null);
|
|
458
459
|
if (!stat?.isFile())
|
|
459
460
|
continue;
|
|
460
461
|
if (isTmp) {
|
|
461
462
|
// an interrupted cachePut; nothing will ever rename it into place
|
|
462
463
|
if (stat.mtimeMs < staleTmpCutoff)
|
|
463
|
-
await
|
|
464
|
+
await (0, fs_helpers_1.remove)(path_1.default.join(dir, name)).catch(() => { });
|
|
464
465
|
continue;
|
|
465
466
|
}
|
|
466
467
|
entries.push({ name, size: stat.size, mtime: stat.mtimeMs });
|
|
@@ -472,7 +473,7 @@ async function enforceCacheLimits(maxMb, keep) {
|
|
|
472
473
|
total += entry.size;
|
|
473
474
|
count += 1;
|
|
474
475
|
if (entry.name !== keep && (total > maxBytes || count > maxFiles)) {
|
|
475
|
-
await
|
|
476
|
+
await (0, fs_helpers_1.remove)(path_1.default.join(dir, entry.name)).catch(() => { });
|
|
476
477
|
}
|
|
477
478
|
}
|
|
478
479
|
}
|
|
@@ -483,14 +484,14 @@ function isCacheTmpName(name) {
|
|
|
483
484
|
/** Remove every cached bundle (and staging leftovers); returns the bundle count. */
|
|
484
485
|
async function cleanCache() {
|
|
485
486
|
const dir = cacheDir();
|
|
486
|
-
if (!(await
|
|
487
|
+
if (!(await (0, fs_helpers_1.pathExists)(dir)))
|
|
487
488
|
return 0;
|
|
488
489
|
let bundles = 0;
|
|
489
|
-
for (const name of await
|
|
490
|
+
for (const name of await fs_1.default.promises.readdir(dir)) {
|
|
490
491
|
const isBundle = /^[0-9a-f]{64}$/.test(name);
|
|
491
492
|
if (!isBundle && !isCacheTmpName(name))
|
|
492
493
|
continue;
|
|
493
|
-
await
|
|
494
|
+
await (0, fs_helpers_1.remove)(path_1.default.join(dir, name));
|
|
494
495
|
if (isBundle)
|
|
495
496
|
bundles += 1;
|
|
496
497
|
}
|
|
@@ -500,11 +501,13 @@ async function cacheStats() {
|
|
|
500
501
|
const dir = cacheDir();
|
|
501
502
|
let files = 0;
|
|
502
503
|
let bytes = 0;
|
|
503
|
-
if (await
|
|
504
|
-
for (const name of await
|
|
504
|
+
if (await (0, fs_helpers_1.pathExists)(dir)) {
|
|
505
|
+
for (const name of await fs_1.default.promises.readdir(dir)) {
|
|
505
506
|
if (!/^[0-9a-f]{64}$/.test(name))
|
|
506
507
|
continue;
|
|
507
|
-
const stat = await
|
|
508
|
+
const stat = await fs_1.default.promises
|
|
509
|
+
.stat(path_1.default.join(dir, name))
|
|
510
|
+
.catch(() => null);
|
|
508
511
|
if (stat?.isFile()) {
|
|
509
512
|
files += 1;
|
|
510
513
|
bytes += stat.size;
|
|
@@ -516,14 +519,14 @@ async function cacheStats() {
|
|
|
516
519
|
/** Remove leftovers of interrupted runs (older than 24h) from the tmp dir. */
|
|
517
520
|
async function cleanStaleTmp(maxAgeMs = 24 * 60 * 60 * 1000) {
|
|
518
521
|
const dir = tmpDir();
|
|
519
|
-
if (!(await
|
|
522
|
+
if (!(await (0, fs_helpers_1.pathExists)(dir)))
|
|
520
523
|
return;
|
|
521
524
|
const cutoff = Date.now() - maxAgeMs;
|
|
522
|
-
for (const name of await
|
|
525
|
+
for (const name of await fs_1.default.promises.readdir(dir)) {
|
|
523
526
|
const file = path_1.default.join(dir, name);
|
|
524
|
-
const stat = await
|
|
527
|
+
const stat = await fs_1.default.promises.stat(file).catch(() => null);
|
|
525
528
|
if (stat && stat.mtimeMs < cutoff)
|
|
526
|
-
await
|
|
529
|
+
await (0, fs_helpers_1.remove)(file).catch(() => { });
|
|
527
530
|
}
|
|
528
531
|
}
|
|
529
532
|
// ---------------------------------------------------------------------------
|
|
@@ -562,7 +565,7 @@ function hasBundleLocation(record) {
|
|
|
562
565
|
async function saveResponse(response, destination, controller = new AbortController()) {
|
|
563
566
|
if (!response.body)
|
|
564
567
|
throw new Error('empty response body');
|
|
565
|
-
await
|
|
568
|
+
await (0, fs_helpers_1.ensureDir)(path_1.default.dirname(destination));
|
|
566
569
|
const abort = () => controller.abort(new Error(`download stalled for ${STREAM_IDLE_TIMEOUT_MS / 1000}s`));
|
|
567
570
|
let idle = setTimeout(abort, STREAM_IDLE_TIMEOUT_MS);
|
|
568
571
|
const watchdog = new stream_1.PassThrough({
|
|
@@ -573,7 +576,7 @@ async function saveResponse(response, destination, controller = new AbortControl
|
|
|
573
576
|
},
|
|
574
577
|
});
|
|
575
578
|
try {
|
|
576
|
-
await (0, promises_1.pipeline)(stream_1.Readable.fromWeb(response.body), watchdog,
|
|
579
|
+
await (0, promises_1.pipeline)(stream_1.Readable.fromWeb(response.body), watchdog, fs_1.default.createWriteStream(destination), { signal: controller.signal });
|
|
577
580
|
}
|
|
578
581
|
finally {
|
|
579
582
|
clearTimeout(idle);
|
|
@@ -794,7 +797,7 @@ async function resolveHermesBase(params) {
|
|
|
794
797
|
// 2. download, extract, verify, cache — transport errors get a second try
|
|
795
798
|
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
796
799
|
const dir = tmpDir();
|
|
797
|
-
await
|
|
800
|
+
await (0, fs_helpers_1.ensureDir)(dir);
|
|
798
801
|
const artifactType = [
|
|
799
802
|
'ppk',
|
|
800
803
|
'apk',
|
|
@@ -849,7 +852,7 @@ async function resolveHermesBase(params) {
|
|
|
849
852
|
}
|
|
850
853
|
}
|
|
851
854
|
finally {
|
|
852
|
-
await
|
|
855
|
+
await (0, fs_helpers_1.remove)(archive).catch(() => { });
|
|
853
856
|
}
|
|
854
857
|
}
|
|
855
858
|
return null;
|
|
@@ -1169,7 +1172,7 @@ class DumpReader {
|
|
|
1169
1172
|
const pass = (this.pass = new stream_1.PassThrough());
|
|
1170
1173
|
proc.stdout.pipe(pass);
|
|
1171
1174
|
if (dumpTo) {
|
|
1172
|
-
const output = (this.debugOutput =
|
|
1175
|
+
const output = (this.debugOutput = fs_1.default.createWriteStream(dumpTo));
|
|
1173
1176
|
this.debugFinished = new Promise((resolve) => {
|
|
1174
1177
|
output.once('finish', resolve);
|
|
1175
1178
|
output.once('error', (error) => {
|
|
@@ -1,40 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
35
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
6
|
exports.plugins = void 0;
|
|
37
|
-
const
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
38
8
|
exports.plugins = [
|
|
39
9
|
{
|
|
40
10
|
name: 'sentry',
|
|
@@ -44,12 +14,12 @@ exports.plugins = [
|
|
|
44
14
|
},
|
|
45
15
|
detect: async () => {
|
|
46
16
|
try {
|
|
47
|
-
await
|
|
17
|
+
await fs_1.default.promises.access('ios/sentry.properties');
|
|
48
18
|
return true;
|
|
49
19
|
}
|
|
50
20
|
catch {
|
|
51
21
|
try {
|
|
52
|
-
await
|
|
22
|
+
await fs_1.default.promises.access('android/sentry.properties');
|
|
53
23
|
return true;
|
|
54
24
|
}
|
|
55
25
|
catch {
|
package/lib/utils/runtime.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare function resolveProxy(targetUrl: string, env?: NodeJS.ProcessEnv)
|
|
|
29
29
|
export declare function webFetch(url: string, init?: RequestInit): Promise<Response>;
|
|
30
30
|
/**
|
|
31
31
|
* An http.Agent routing `targetUrl` through its proxy, for the core
|
|
32
|
-
* http/https APIs
|
|
32
|
+
* http/https APIs (including the streaming uploads); undefined when the
|
|
33
33
|
* connection is direct. Always a CONNECT tunnel (also for http targets, like
|
|
34
34
|
* undici's ProxyAgent above): the absolute-form alternative rewrites the
|
|
35
35
|
* request head after it was buffered, which garbles a streaming body.
|
package/lib/utils/runtime.js
CHANGED
|
@@ -127,20 +127,12 @@ function webFetch(url, init = {}) {
|
|
|
127
127
|
dispatcher,
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
|
|
131
|
-
return globalThis.fetch(url, init);
|
|
132
|
-
}
|
|
133
|
-
// Node < 18 only. Loaded on demand so the built-in fetch path never pays
|
|
134
|
-
// for node-fetch (nor for the punycode deprecation warning it triggers on
|
|
135
|
-
// Node ≥ 21).
|
|
136
|
-
const mod = require('node-fetch');
|
|
137
|
-
const nodeFetch = (mod.default ?? mod);
|
|
138
|
-
return nodeFetch(url, init);
|
|
130
|
+
return globalThis.fetch(url, init);
|
|
139
131
|
}
|
|
140
132
|
const proxyAgents = new Map();
|
|
141
133
|
/**
|
|
142
134
|
* An http.Agent routing `targetUrl` through its proxy, for the core
|
|
143
|
-
* http/https APIs
|
|
135
|
+
* http/https APIs (including the streaming uploads); undefined when the
|
|
144
136
|
* connection is direct. Always a CONNECT tunnel (also for http targets, like
|
|
145
137
|
* undici's ProxyAgent above): the absolute-form alternative rewrites the
|
|
146
138
|
* request head after it was buffered, which garbles a streaming body.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Agent as HttpAgent } from 'http';
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
export interface UploadRequest {
|
|
4
|
+
method: string;
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
body: Readable;
|
|
7
|
+
}
|
|
8
|
+
export interface UploadResponse {
|
|
9
|
+
status: number;
|
|
10
|
+
statusText: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function fileContentType(fileName: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* multipart/form-data with `fields` first and the file last. The file's size
|
|
15
|
+
* is known up front, so the request carries Content-Length instead of a
|
|
16
|
+
* chunked body: what object stores expect, and the only framing that survives
|
|
17
|
+
* a proxy agent's rewrite of the buffered request head.
|
|
18
|
+
*/
|
|
19
|
+
export declare function multipartRequest(fields: Record<string, string>, file: {
|
|
20
|
+
name: string;
|
|
21
|
+
size: number;
|
|
22
|
+
stream: Readable;
|
|
23
|
+
}): UploadRequest;
|
|
24
|
+
/**
|
|
25
|
+
* Send `request` and resolve with the response status once its head arrives
|
|
26
|
+
* (the body is drained and dropped). Network errors reject as they are, with
|
|
27
|
+
* their `code` (ECONNRESET, ...); aborting `signal` rejects with an AbortError.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sendUploadRequest(url: string, request: UploadRequest, options: {
|
|
30
|
+
agent?: HttpAgent;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
userAgent?: string;
|
|
33
|
+
}): Promise<UploadResponse>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Streaming uploads on node:http(s): a multipart form or a raw PUT whose body
|
|
3
|
+
// is read from disk as it is sent, with an exact Content-Length.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.fileContentType = fileContentType;
|
|
9
|
+
exports.multipartRequest = multipartRequest;
|
|
10
|
+
exports.sendUploadRequest = sendUploadRequest;
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const stream_1 = require("stream");
|
|
14
|
+
/**
|
|
15
|
+
* The file part's Content-Type for the extensions the CLI uploads, as the
|
|
16
|
+
* form-data package used to pick them (mime-types): object stores keep it as
|
|
17
|
+
* the stored object's type.
|
|
18
|
+
*/
|
|
19
|
+
const FILE_CONTENT_TYPES = {
|
|
20
|
+
'.aab': 'application/x-authorware-bin',
|
|
21
|
+
'.apk': 'application/vnd.android.package-archive',
|
|
22
|
+
'.json': 'application/json',
|
|
23
|
+
'.map': 'application/json',
|
|
24
|
+
'.zip': 'application/zip',
|
|
25
|
+
};
|
|
26
|
+
function fileContentType(fileName) {
|
|
27
|
+
return (FILE_CONTENT_TYPES[path_1.default.extname(fileName).toLowerCase()] ??
|
|
28
|
+
'application/octet-stream');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* multipart/form-data with `fields` first and the file last. The file's size
|
|
32
|
+
* is known up front, so the request carries Content-Length instead of a
|
|
33
|
+
* chunked body: what object stores expect, and the only framing that survives
|
|
34
|
+
* a proxy agent's rewrite of the buffered request head.
|
|
35
|
+
*/
|
|
36
|
+
function multipartRequest(fields, file) {
|
|
37
|
+
// A 'data' listener (the progress bar) may have set the stream flowing:
|
|
38
|
+
// hold its chunks until the body below reads them.
|
|
39
|
+
file.stream.pause();
|
|
40
|
+
const boundary = `--------------------------${(0, crypto_1.randomBytes)(12).toString('hex')}`;
|
|
41
|
+
let head = '';
|
|
42
|
+
for (const [name, value] of Object.entries(fields)) {
|
|
43
|
+
head += `--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`;
|
|
44
|
+
}
|
|
45
|
+
head +=
|
|
46
|
+
`--${boundary}\r\n` +
|
|
47
|
+
`Content-Disposition: form-data; name="file"; filename="${path_1.default.basename(file.name)}"\r\n` +
|
|
48
|
+
`Content-Type: ${fileContentType(file.name)}\r\n\r\n`;
|
|
49
|
+
const headBytes = Buffer.from(head);
|
|
50
|
+
const tailBytes = Buffer.from(`\r\n--${boundary}--\r\n`);
|
|
51
|
+
async function* parts() {
|
|
52
|
+
yield headBytes;
|
|
53
|
+
let sent = 0;
|
|
54
|
+
for await (const chunk of file.stream) {
|
|
55
|
+
sent += chunk.length;
|
|
56
|
+
yield chunk;
|
|
57
|
+
}
|
|
58
|
+
// a file that shrank since its size was taken would leave the request
|
|
59
|
+
// short of its Content-Length, waiting out the whole upload deadline
|
|
60
|
+
if (sent !== file.size) {
|
|
61
|
+
throw new Error(`${file.name} changed during the upload: sent ${sent} of ${file.size} bytes`);
|
|
62
|
+
}
|
|
63
|
+
yield tailBytes;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
headers: {
|
|
68
|
+
'content-type': `multipart/form-data;boundary=${boundary}`,
|
|
69
|
+
'content-length': String(headBytes.length + file.size + tailBytes.length),
|
|
70
|
+
},
|
|
71
|
+
body: stream_1.Readable.from(parts(), { objectMode: false }),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Send `request` and resolve with the response status once its head arrives
|
|
76
|
+
* (the body is drained and dropped). Network errors reject as they are, with
|
|
77
|
+
* their `code` (ECONNRESET, ...); aborting `signal` rejects with an AbortError.
|
|
78
|
+
*/
|
|
79
|
+
function sendUploadRequest(url, request, options) {
|
|
80
|
+
const { request: send } = url.startsWith('https:')
|
|
81
|
+
? require('https')
|
|
82
|
+
: require('http');
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const req = send(url, {
|
|
85
|
+
method: request.method,
|
|
86
|
+
headers: {
|
|
87
|
+
accept: '*/*',
|
|
88
|
+
...(options.userAgent ? { 'user-agent': options.userAgent } : {}),
|
|
89
|
+
...request.headers,
|
|
90
|
+
},
|
|
91
|
+
agent: options.agent,
|
|
92
|
+
});
|
|
93
|
+
const fail = (error) => {
|
|
94
|
+
request.body.destroy();
|
|
95
|
+
req.destroy(error);
|
|
96
|
+
reject(error);
|
|
97
|
+
};
|
|
98
|
+
const { signal } = options;
|
|
99
|
+
const onAbort = () => {
|
|
100
|
+
fail(Object.assign(new Error('The upload was aborted'), {
|
|
101
|
+
name: 'AbortError',
|
|
102
|
+
code: 'ABORT_ERR',
|
|
103
|
+
}));
|
|
104
|
+
};
|
|
105
|
+
if (signal?.aborted)
|
|
106
|
+
return onAbort();
|
|
107
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
108
|
+
req.on('error', fail);
|
|
109
|
+
request.body.on('error', fail);
|
|
110
|
+
req.on('response', (res) => {
|
|
111
|
+
signal?.removeEventListener('abort', onAbort);
|
|
112
|
+
res.resume();
|
|
113
|
+
resolve({
|
|
114
|
+
status: res.statusCode ?? 0,
|
|
115
|
+
statusText: res.statusMessage ?? '',
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
request.body.pipe(req);
|
|
119
|
+
});
|
|
120
|
+
}
|
package/lib/utils/zip-entries.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
@@ -40,11 +7,12 @@ exports.readEntry = readEntry;
|
|
|
40
7
|
exports.writeEntry = writeEntry;
|
|
41
8
|
exports.readEntryPrefix = readEntryPrefix;
|
|
42
9
|
exports.enumZipEntries = enumZipEntries;
|
|
43
|
-
const
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
44
11
|
const os_1 = __importDefault(require("os"));
|
|
45
12
|
const path_1 = __importDefault(require("path"));
|
|
46
13
|
const promises_1 = require("stream/promises");
|
|
47
14
|
const yauzl_1 = require("yauzl");
|
|
15
|
+
const fs_helpers_1 = require("./fs-helpers");
|
|
48
16
|
function readEntry(entry, zipFile) {
|
|
49
17
|
const buffers = [];
|
|
50
18
|
return new Promise((resolve, reject) => {
|
|
@@ -69,7 +37,7 @@ function readEntry(entry, zipFile) {
|
|
|
69
37
|
});
|
|
70
38
|
}
|
|
71
39
|
function writeEntry(entry, zipFile, outputPath) {
|
|
72
|
-
|
|
40
|
+
(0, fs_helpers_1.ensureDirSync)(path_1.default.dirname(outputPath));
|
|
73
41
|
return new Promise((resolve, reject) => {
|
|
74
42
|
zipFile.openReadStream(entry, (err, stream) => {
|
|
75
43
|
if (err) {
|
|
@@ -80,7 +48,7 @@ function writeEntry(entry, zipFile, outputPath) {
|
|
|
80
48
|
reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
|
|
81
49
|
return;
|
|
82
50
|
}
|
|
83
|
-
(0, promises_1.pipeline)(stream,
|
|
51
|
+
(0, promises_1.pipeline)(stream, fs_1.default.createWriteStream(outputPath)).then(resolve, reject);
|
|
84
52
|
});
|
|
85
53
|
});
|
|
86
54
|
}
|
|
@@ -166,14 +134,14 @@ async function enumZipEntries(zipFn, callback, nestedPath = '') {
|
|
|
166
134
|
try {
|
|
167
135
|
if (!entry.fileName.endsWith('/') &&
|
|
168
136
|
entry.fileName.toLowerCase().endsWith('.hap')) {
|
|
169
|
-
const tempDir = await
|
|
137
|
+
const tempDir = await fs_1.default.promises.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'nested_zip_'));
|
|
170
138
|
const tempZipPath = path_1.default.join(tempDir, 'temp.zip');
|
|
171
139
|
try {
|
|
172
140
|
await new Promise((res, rej) => {
|
|
173
141
|
zipfile.openReadStream(entry, async (err, readStream) => {
|
|
174
142
|
if (err)
|
|
175
143
|
return rej(err);
|
|
176
|
-
const writeStream =
|
|
144
|
+
const writeStream = fs_1.default.createWriteStream(tempZipPath);
|
|
177
145
|
readStream.on('error', rej);
|
|
178
146
|
readStream.pipe(writeStream);
|
|
179
147
|
writeStream.on('finish', () => res(void 0));
|
|
@@ -183,7 +151,7 @@ async function enumZipEntries(zipFn, callback, nestedPath = '') {
|
|
|
183
151
|
await enumZipEntries(tempZipPath, callback, `${fullPath}/`);
|
|
184
152
|
}
|
|
185
153
|
finally {
|
|
186
|
-
await
|
|
154
|
+
await (0, fs_helpers_1.remove)(tempDir);
|
|
187
155
|
}
|
|
188
156
|
}
|
|
189
157
|
const result = callback(entry, zipfile, fullPath);
|