react-native-update-cli 2.22.6 → 2.22.8
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/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/cli.json +5 -0
- package/lib/api.d.ts +7 -0
- package/lib/api.js +106 -38
- package/lib/app.js +3 -2
- package/lib/bin.js +16 -2
- package/lib/bundle-runner.d.ts +35 -2
- package/lib/bundle-runner.js +313 -128
- package/lib/bundle.d.ts +1 -0
- package/lib/bundle.js +2 -0
- package/lib/diff.d.ts +9 -0
- package/lib/diff.js +162 -120
- package/lib/locales/en.d.ts +1 -0
- package/lib/locales/en.js +1 -0
- package/lib/locales/zh.d.ts +1 -0
- package/lib/locales/zh.js +1 -0
- package/lib/package.d.ts +7 -3
- package/lib/package.js +31 -12
- package/lib/types.d.ts +2 -0
- package/lib/utils/dep-versions.d.ts +7 -0
- package/lib/utils/dep-versions.js +66 -31
- package/lib/utils/hbcTransform.d.ts +21 -0
- package/lib/utils/hbcTransform.js +146 -5
- package/lib/utils/hermes-base.d.ts +31 -7
- package/lib/utils/hermes-base.js +284 -76
- package/lib/utils/http-helper.d.ts +6 -1
- package/lib/utils/http-helper.js +23 -11
- package/lib/utils/index.d.ts +30 -1
- package/lib/utils/index.js +98 -24
- package/lib/utils/latest-version/index.d.ts +11 -8
- package/lib/utils/latest-version/index.js +63 -18
- package/lib/utils/zip-entries.js +20 -15
- package/lib/utils/zip-options.d.ts +2 -0
- package/lib/utils/zip-options.js +9 -4
- package/lib/utils/zip-range.d.ts +84 -13
- package/lib/utils/zip-range.js +363 -63
- package/lib/versions.js +30 -23
- package/package.json +11 -11
- package/src/api.ts +126 -46
- package/src/app.ts +3 -2
- package/src/bin.ts +17 -2
- package/src/bundle-runner.ts +419 -171
- package/src/bundle.ts +3 -0
- package/src/diff.ts +210 -153
- package/src/locales/en.ts +2 -0
- package/src/locales/zh.ts +2 -0
- package/src/package.ts +42 -14
- package/src/types.ts +2 -0
- package/src/utils/dep-versions.ts +76 -33
- package/src/utils/hbcTransform.ts +194 -5
- package/src/utils/hermes-base.ts +311 -81
- package/src/utils/http-helper.ts +24 -13
- package/src/utils/index.ts +136 -26
- package/src/utils/latest-version/index.ts +82 -29
- package/src/utils/zip-entries.ts +18 -16
- package/src/utils/zip-options.ts +8 -3
- package/src/utils/zip-range.ts +436 -67
- package/src/versions.ts +34 -26
package/lib/diff.js
CHANGED
|
@@ -37,6 +37,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.diffCommands = exports.readEntry = exports.enumZipEntries = void 0;
|
|
40
|
+
exports.zipEntryContentKey = zipEntryContentKey;
|
|
41
|
+
exports.zipEntriesHaveSameContent = zipEntriesHaveSameContent;
|
|
40
42
|
const node_crypto_1 = require("node:crypto");
|
|
41
43
|
const fs = __importStar(require("fs-extra"));
|
|
42
44
|
const global_dirs_1 = require("global-dirs");
|
|
@@ -52,6 +54,18 @@ const zip_entries_1 = require("./utils/zip-entries");
|
|
|
52
54
|
Object.defineProperty(exports, "enumZipEntries", { enumerable: true, get: function () { return zip_entries_1.enumZipEntries; } });
|
|
53
55
|
Object.defineProperty(exports, "readEntry", { enumerable: true, get: function () { return zip_entries_1.readEntry; } });
|
|
54
56
|
const zip_options_1 = require("./utils/zip-options");
|
|
57
|
+
/**
|
|
58
|
+
* 判定两个 zip entry 内容相同的键:crc32 单独并不足以证明内容一致(32 位
|
|
59
|
+
* 校验和碰撞并不罕见,尤其是长度不同的文件),必须同时要求解压后长度相等。
|
|
60
|
+
* 仅用于生成端匹配,manifest 里的 copies / copiesCrc 格式不变。
|
|
61
|
+
*/
|
|
62
|
+
function zipEntryContentKey(entry) {
|
|
63
|
+
return `${entry.crc32}:${entry.uncompressedSize}`;
|
|
64
|
+
}
|
|
65
|
+
function zipEntriesHaveSameContent(left, right) {
|
|
66
|
+
return (left.crc32 === right.crc32 &&
|
|
67
|
+
left.uncompressedSize === right.uncompressedSize);
|
|
68
|
+
}
|
|
55
69
|
const loadModule = (pkgName) => {
|
|
56
70
|
const nodePathDirs = (process.env.NODE_PATH || '')
|
|
57
71
|
.split(path_1.default.delimiter)
|
|
@@ -72,16 +86,48 @@ function basename(fn) {
|
|
|
72
86
|
function createOutputZip(output) {
|
|
73
87
|
fs.ensureDirSync(path_1.default.dirname(output));
|
|
74
88
|
const zipfile = new yazl_1.ZipFile();
|
|
89
|
+
const writeStream = fs.createWriteStream(output);
|
|
75
90
|
const writePromise = new Promise((resolve, reject) => {
|
|
76
91
|
zipfile.outputStream.on('error', reject);
|
|
77
|
-
const writeStream = fs.createWriteStream(output);
|
|
78
92
|
// without this, a full disk / read-only target left the promise pending
|
|
79
93
|
writeStream.on('error', reject);
|
|
80
94
|
zipfile.outputStream.pipe(writeStream).on('close', () => {
|
|
81
95
|
resolve(void 0);
|
|
82
96
|
});
|
|
83
97
|
});
|
|
84
|
-
|
|
98
|
+
// 失败时释放输出 fd 并删掉半成品,避免残留一个截断的 patch 包
|
|
99
|
+
const abort = async () => {
|
|
100
|
+
writePromise.catch(() => { });
|
|
101
|
+
zipfile.outputStream.unpipe(writeStream);
|
|
102
|
+
// yazl 的 outputStream 类型声明缺 destroy,运行时是 PassThrough
|
|
103
|
+
zipfile.outputStream.destroy();
|
|
104
|
+
if (!writeStream.closed) {
|
|
105
|
+
// 等 fd 真正关闭再删文件,避免 Windows 上删除被占用文件失败
|
|
106
|
+
await new Promise((resolve) => {
|
|
107
|
+
writeStream.once('close', () => resolve());
|
|
108
|
+
if (!writeStream.destroyed) {
|
|
109
|
+
writeStream.destroy();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
await fs.rm(output, { force: true });
|
|
114
|
+
};
|
|
115
|
+
return { zipfile, writePromise, abort };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 打开输出包,执行 build 填充条目并返回 manifest,最后写入 __diff.json
|
|
119
|
+
* 收尾。build 或收尾任何一步失败都会关闭输出流、删除半成品并重新抛出。
|
|
120
|
+
*/
|
|
121
|
+
async function writeDiffZip(output, build) {
|
|
122
|
+
const { zipfile, writePromise, abort } = createOutputZip(output);
|
|
123
|
+
try {
|
|
124
|
+
const manifest = await build(zipfile);
|
|
125
|
+
await finishDiffZip(zipfile, writePromise, manifest);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
await abort();
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
85
131
|
}
|
|
86
132
|
// baseline patch 小于该值时跳过变换尝试:节省一次 diff 的 CPU,
|
|
87
133
|
// 且此时变换收益上限(~25%)也抵不过元数据开销
|
|
@@ -125,10 +171,10 @@ async function filesEqual(leftPath, rightPath) {
|
|
|
125
171
|
return leftHash === rightHash;
|
|
126
172
|
}
|
|
127
173
|
/**
|
|
128
|
-
* 大 bundle
|
|
129
|
-
* 避免 old/new/restored 的整块 Buffer 副本。HBC
|
|
130
|
-
*
|
|
131
|
-
*
|
|
174
|
+
* 大 bundle 流式路径:bundle 直接从 ZIP entry 落盘后传入 native,
|
|
175
|
+
* 避免 old/new/restored 的整块 Buffer 副本。HBC 变换 T/T⁻¹ 也在文件上
|
|
176
|
+
* 按段定位改写(transformHbcFile),全程不持有整个 bundle。native 已
|
|
177
|
+
* 自校验的普通产物不再重复 patch;自定义/变换路径仍保留 round-trip 校验。
|
|
132
178
|
*/
|
|
133
179
|
async function buildStreamBundlePatch(originSource, newSource, options, workRoot) {
|
|
134
180
|
const diffStreamFn = options.diffStreamFn;
|
|
@@ -143,23 +189,12 @@ async function buildStreamBundlePatch(originSource, newSource, options, workRoot
|
|
|
143
189
|
let phaseStartedAt = performance.now();
|
|
144
190
|
const rawOldFile = await bundleSourceFile(originSource, path_1.default.join(tempRoot, 'old.bin'));
|
|
145
191
|
const rawNewFile = await bundleSourceFile(newSource, path_1.default.join(tempRoot, 'new.bin'));
|
|
146
|
-
|
|
147
|
-
? await bundleSourceBuffer(originSource)
|
|
148
|
-
: null;
|
|
149
|
-
const newBuffer = options.hbcTransform
|
|
150
|
-
? await bundleSourceBuffer(newSource)
|
|
151
|
-
: null;
|
|
152
|
-
const pair = originBuffer && newBuffer
|
|
153
|
-
? (0, hbcTransform_1.tryTransformPair)(originBuffer, newBuffer)
|
|
154
|
-
: null;
|
|
192
|
+
// 变换走文件版 T:只读头部选布局、按段定位改写,不把 bundle 读进内存
|
|
155
193
|
const transformedOldFile = path_1.default.join(tempRoot, 'old-transformed.bin');
|
|
156
194
|
const transformedNewFile = path_1.default.join(tempRoot, 'new-transformed.bin');
|
|
157
|
-
|
|
158
|
-
await
|
|
159
|
-
|
|
160
|
-
fs.writeFile(transformedNewFile, pair.tNew),
|
|
161
|
-
]);
|
|
162
|
-
}
|
|
195
|
+
const pair = options.hbcTransform
|
|
196
|
+
? await (0, hbcTransform_1.tryTransformPairFiles)(rawOldFile, rawNewFile, transformedOldFile, transformedNewFile)
|
|
197
|
+
: null;
|
|
163
198
|
reportDiffPhase(options, {
|
|
164
199
|
phase: 'materialize',
|
|
165
200
|
durationMs: extractionDurationMs + performance.now() - phaseStartedAt,
|
|
@@ -197,11 +232,10 @@ async function buildStreamBundlePatch(originSource, newSource, options, workRoot
|
|
|
197
232
|
const restoredFile = path_1.default.join(tempRoot, 'restored.bin');
|
|
198
233
|
await patchStreamFn(chosenPair ? transformedOldFile : rawOldFile, patchFile, restoredFile);
|
|
199
234
|
if (chosenPair) {
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
Buffer.compare(restored, newBuffer) !== 0) {
|
|
235
|
+
// T⁻¹ 同样在文件上按段改写,再以流式哈希比对,内存与 bundle 大小无关
|
|
236
|
+
const restoredRawFile = path_1.default.join(tempRoot, 'restored-raw.bin');
|
|
237
|
+
const inverted = await (0, hbcTransform_1.transformHbcFile)(restoredFile, restoredRawFile, chosenPair.layout, true);
|
|
238
|
+
if (!inverted || !(await filesEqual(restoredRawFile, rawNewFile))) {
|
|
205
239
|
throw new Error('stream diff round-trip verification failed');
|
|
206
240
|
}
|
|
207
241
|
}
|
|
@@ -265,9 +299,10 @@ async function buildBundlePatch(diffFn, originSource, newSource, options, workRo
|
|
|
265
299
|
if (candidate.length + metaOverhead >= baseline.length) {
|
|
266
300
|
return { patch: { kind: 'buffer', data: baseline } };
|
|
267
301
|
}
|
|
302
|
+
// patched 是 patchFn 新返回的 Buffer,原地做 T⁻¹ 省去一次整块拷贝
|
|
268
303
|
const patched = options.patchFn(pair.tOld, candidate);
|
|
269
|
-
|
|
270
|
-
|
|
304
|
+
if (!(0, hbcTransform_1.transformHbcWithLayoutInPlace)(patched, pair.layout, true) ||
|
|
305
|
+
Buffer.compare(patched, newBuffer) !== 0) {
|
|
271
306
|
console.warn((0, i18n_1.t)('hbcTransformRoundTripFailed'));
|
|
272
307
|
return { patch: { kind: 'buffer', data: baseline } };
|
|
273
308
|
}
|
|
@@ -360,7 +395,7 @@ async function diffFromPPK(origin, next, output, diffFn, bundleOptions, workRoot
|
|
|
360
395
|
originEntries[entry.fileName] = entry;
|
|
361
396
|
if (!/\/$/.test(entry.fileName)) {
|
|
362
397
|
// isFile
|
|
363
|
-
originMap[entry
|
|
398
|
+
originMap[zipEntryContentKey(entry)] = entry.fileName;
|
|
364
399
|
if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
|
|
365
400
|
// This is source.
|
|
366
401
|
originSource = await readOriginBundleSource(entry, zipFile, bundleOptions, workRoot);
|
|
@@ -371,74 +406,77 @@ async function diffFromPPK(origin, next, output, diffFn, bundleOptions, workRoot
|
|
|
371
406
|
throw new Error((0, i18n_1.t)('bundleFileNotFound'));
|
|
372
407
|
}
|
|
373
408
|
const copies = {};
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
addedEntry[fn] = true;
|
|
382
|
-
const base = basename(fn);
|
|
383
|
-
if (base) {
|
|
384
|
-
addEntry(base);
|
|
385
|
-
}
|
|
386
|
-
zipfile.addEmptyDirectory(fn);
|
|
387
|
-
}
|
|
388
|
-
const newEntries = {};
|
|
389
|
-
const hbcTransformMetas = {};
|
|
390
|
-
await (0, zip_entries_1.enumZipEntries)(next, async (entry, nextZipfile) => {
|
|
391
|
-
newEntries[entry.fileName] = entry;
|
|
392
|
-
if (/\/$/.test(entry.fileName)) {
|
|
393
|
-
// Directory
|
|
394
|
-
if (!originEntries[entry.fileName]) {
|
|
395
|
-
addEntry(entry.fileName);
|
|
409
|
+
const bundleSource = originSource;
|
|
410
|
+
await writeDiffZip(output, async (zipfile) => {
|
|
411
|
+
const addedEntry = {};
|
|
412
|
+
function addEntry(fn) {
|
|
413
|
+
//console.log(fn);
|
|
414
|
+
if (!fn || addedEntry[fn]) {
|
|
415
|
+
return;
|
|
396
416
|
}
|
|
417
|
+
addedEntry[fn] = true;
|
|
418
|
+
const base = basename(fn);
|
|
419
|
+
if (base) {
|
|
420
|
+
addEntry(base);
|
|
421
|
+
}
|
|
422
|
+
zipfile.addEmptyDirectory(fn);
|
|
397
423
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
424
|
+
const newEntries = {};
|
|
425
|
+
const hbcTransformMetas = {};
|
|
426
|
+
await (0, zip_entries_1.enumZipEntries)(next, async (entry, nextZipfile) => {
|
|
427
|
+
newEntries[entry.fileName] = entry;
|
|
428
|
+
if (/\/$/.test(entry.fileName)) {
|
|
429
|
+
// Directory
|
|
430
|
+
if (!originEntries[entry.fileName]) {
|
|
431
|
+
addEntry(entry.fileName);
|
|
432
|
+
}
|
|
407
433
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
434
|
+
else if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
|
|
435
|
+
await addBundlePatch(zipfile, entry, nextZipfile, diffFn, bundleSource, bundleOptions, hbcTransformMetas, workRoot);
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
// If same file.
|
|
439
|
+
const originEntry = originEntries[entry.fileName];
|
|
440
|
+
if (originEntry && zipEntriesHaveSameContent(originEntry, entry)) {
|
|
441
|
+
// ignore
|
|
442
|
+
return;
|
|
414
443
|
}
|
|
415
|
-
|
|
416
|
-
|
|
444
|
+
// If moved from other place
|
|
445
|
+
const movedFrom = originMap[zipEntryContentKey(entry)];
|
|
446
|
+
if (movedFrom) {
|
|
447
|
+
const base = basename(entry.fileName);
|
|
448
|
+
if (base && !originEntries[base]) {
|
|
449
|
+
addEntry(base);
|
|
450
|
+
}
|
|
451
|
+
copies[entry.fileName] = movedFrom;
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
// New file.
|
|
455
|
+
const basePath = basename(entry.fileName);
|
|
456
|
+
if (basePath) {
|
|
457
|
+
addEntry(basePath);
|
|
458
|
+
}
|
|
459
|
+
await addFileFromZipEntry(zipfile, entry, nextZipfile);
|
|
417
460
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
461
|
+
});
|
|
462
|
+
const deletes = {};
|
|
463
|
+
for (const k in originEntries) {
|
|
464
|
+
if (!newEntries[k]) {
|
|
465
|
+
console.log((0, i18n_1.t)('deleteFile', { file: k }));
|
|
466
|
+
deletes[k] = 1;
|
|
422
467
|
}
|
|
423
|
-
await addFileFromZipEntry(zipfile, entry, nextZipfile);
|
|
424
468
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
await finishDiffZip(zipfile, writePromise, {
|
|
434
|
-
copies,
|
|
435
|
-
deletes,
|
|
436
|
-
...(Object.keys(hbcTransformMetas).length
|
|
437
|
-
? { hbcTransform: hbcTransformMetas }
|
|
438
|
-
: {}),
|
|
469
|
+
return {
|
|
470
|
+
copies,
|
|
471
|
+
deletes,
|
|
472
|
+
...(Object.keys(hbcTransformMetas).length
|
|
473
|
+
? { hbcTransform: hbcTransformMetas }
|
|
474
|
+
: {}),
|
|
475
|
+
};
|
|
439
476
|
});
|
|
440
477
|
}
|
|
441
478
|
async function diffFromPackage(origin, next, output, diffFn, platform, bundleOptions, workRoot) {
|
|
479
|
+
// 路径 → 内容键(crc32 + 解压后长度)
|
|
442
480
|
const originEntries = {};
|
|
443
481
|
const originMap = {};
|
|
444
482
|
let originSource;
|
|
@@ -460,8 +498,9 @@ async function diffFromPackage(origin, next, output, diffFn, platform, bundleOpt
|
|
|
460
498
|
const fn = resolvedEntry.diffPath;
|
|
461
499
|
//console.log(fn);
|
|
462
500
|
// isFile
|
|
463
|
-
|
|
464
|
-
|
|
501
|
+
const contentKey = zipEntryContentKey(entry);
|
|
502
|
+
originEntries[fn] = contentKey;
|
|
503
|
+
originMap[contentKey] = fn;
|
|
465
504
|
if (resolvedEntry.kind === 'bundle') {
|
|
466
505
|
// This is source.
|
|
467
506
|
originSource = await readOriginBundleSource(entry, zipFile, bundleOptions, workRoot);
|
|
@@ -472,39 +511,42 @@ async function diffFromPackage(origin, next, output, diffFn, platform, bundleOpt
|
|
|
472
511
|
throw new Error((0, i18n_1.t)('bundleFileNotFound'));
|
|
473
512
|
}
|
|
474
513
|
const copies = {};
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
else if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
|
|
483
|
-
await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas, workRoot);
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
// If same file.
|
|
487
|
-
if (originEntries[entry.fileName] === entry.crc32) {
|
|
488
|
-
copies[entry.fileName] = '';
|
|
489
|
-
copiesCrc[entry.fileName] = entry.crc32;
|
|
490
|
-
return;
|
|
514
|
+
const bundleSource = originSource;
|
|
515
|
+
await writeDiffZip(output, async (zipfile) => {
|
|
516
|
+
const hbcTransformMetas = {};
|
|
517
|
+
await (0, zip_entries_1.enumZipEntries)(next, async (entry, nextZipfile) => {
|
|
518
|
+
if (/\/$/.test(entry.fileName)) {
|
|
519
|
+
// Directory
|
|
520
|
+
zipfile.addEmptyDirectory(entry.fileName);
|
|
491
521
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
if (movedFrom) {
|
|
495
|
-
copies[entry.fileName] = movedFrom;
|
|
496
|
-
copiesCrc[entry.fileName] = entry.crc32;
|
|
497
|
-
return;
|
|
522
|
+
else if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
|
|
523
|
+
await addBundlePatch(zipfile, entry, nextZipfile, diffFn, bundleSource, bundleOptions, hbcTransformMetas, workRoot);
|
|
498
524
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
525
|
+
else {
|
|
526
|
+
// If same file.
|
|
527
|
+
const contentKey = zipEntryContentKey(entry);
|
|
528
|
+
if (originEntries[entry.fileName] === contentKey) {
|
|
529
|
+
copies[entry.fileName] = '';
|
|
530
|
+
copiesCrc[entry.fileName] = entry.crc32;
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
// If moved from other place
|
|
534
|
+
const movedFrom = originMap[contentKey];
|
|
535
|
+
if (movedFrom) {
|
|
536
|
+
copies[entry.fileName] = movedFrom;
|
|
537
|
+
copiesCrc[entry.fileName] = entry.crc32;
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
await addFileFromZipEntry(zipfile, entry, nextZipfile);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
return {
|
|
544
|
+
copies,
|
|
545
|
+
copiesCrc,
|
|
546
|
+
...(Object.keys(hbcTransformMetas).length
|
|
547
|
+
? { hbcTransform: hbcTransformMetas }
|
|
548
|
+
: {}),
|
|
549
|
+
};
|
|
508
550
|
});
|
|
509
551
|
}
|
|
510
552
|
function resolveDiffImplementation(options) {
|
package/lib/locales/en.d.ts
CHANGED
|
@@ -164,6 +164,7 @@ declare const _default: {
|
|
|
164
164
|
hermesBaseRangeFallback: string;
|
|
165
165
|
hermesBaseCompileFailed: string;
|
|
166
166
|
hermesBaseCompileFailedLog: string;
|
|
167
|
+
hermesBasePlainCompileFailed: string;
|
|
167
168
|
hermesBaseVerified: string;
|
|
168
169
|
hermesBaseVerifyFailed: string;
|
|
169
170
|
cacheCleaned: string;
|
package/lib/locales/en.js
CHANGED
|
@@ -172,6 +172,7 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
172
172
|
hermesBaseRangeFallback: 'Hermes base: partial download unavailable ({{- reason}}); downloading the whole package',
|
|
173
173
|
hermesBaseCompileFailed: 'Hermes base compile failed ({{- reason}}); retrying without -base-bytecode',
|
|
174
174
|
hermesBaseCompileFailedLog: 'Hermes base: full compiler output written to {{- file}}',
|
|
175
|
+
hermesBasePlainCompileFailed: 'Hermes base: the plain compile used for verification failed ({{- reason}}); keeping the base compile unverified',
|
|
175
176
|
hermesBaseVerified: 'Hermes base: bytecode verified equivalent to a plain compile',
|
|
176
177
|
hermesBaseVerifyFailed: 'Hermes base: bytecode differs from a plain compile; dropping the base and recompiling',
|
|
177
178
|
cacheCleaned: 'Removed {{count}} cached bundle(s)',
|
package/lib/locales/zh.d.ts
CHANGED
|
@@ -163,6 +163,7 @@ declare const _default: {
|
|
|
163
163
|
hermesBaseRangeFallback: string;
|
|
164
164
|
hermesBaseCompileFailed: string;
|
|
165
165
|
hermesBaseCompileFailedLog: string;
|
|
166
|
+
hermesBasePlainCompileFailed: string;
|
|
166
167
|
hermesBaseVerified: string;
|
|
167
168
|
hermesBaseVerifyFailed: string;
|
|
168
169
|
cacheCleaned: string;
|
package/lib/locales/zh.js
CHANGED
|
@@ -171,6 +171,7 @@ exports.default = {
|
|
|
171
171
|
hermesBaseRangeFallback: 'Hermes base:无法按需下载({{- reason}}),改为下载整包',
|
|
172
172
|
hermesBaseCompileFailed: 'Hermes base 编译失败({{- reason}}),改为不带 -base-bytecode 重编',
|
|
173
173
|
hermesBaseCompileFailedLog: 'Hermes base:完整编译错误已写入 {{- file}}',
|
|
174
|
+
hermesBasePlainCompileFailed: 'Hermes base:用于校验的普通编译失败({{- reason}}),保留 base 编译结果但未校验',
|
|
174
175
|
hermesBaseVerified: 'Hermes base:字节码与普通编译等价,校验通过',
|
|
175
176
|
hermesBaseVerifyFailed: 'Hermes base:字节码与普通编译不等价,放弃 base 重新编译',
|
|
176
177
|
cacheCleaned: '已清理 {{count}} 个缓存 bundle',
|
package/lib/package.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Platform } from './types';
|
|
1
|
+
import type { Package, Platform } from './types';
|
|
2
2
|
type PackageCommandOptions = Record<string, unknown> & {
|
|
3
3
|
appId?: string;
|
|
4
4
|
appKey?: string;
|
|
@@ -12,8 +12,12 @@ type PackageCommandOptions = Record<string, unknown> & {
|
|
|
12
12
|
output?: string;
|
|
13
13
|
};
|
|
14
14
|
export declare function normalizeUploadBuildTime(value: unknown): string;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Print the app's native packages. Pass `packages` when the caller already
|
|
17
|
+
* fetched them (every page of the list), to skip fetching them again.
|
|
18
|
+
*/
|
|
19
|
+
export declare function listPackage(appId: string, packages?: Package[]): Promise<Package[]>;
|
|
20
|
+
export declare function choosePackage(appId: string, packages?: Package[]): Promise<Package>;
|
|
17
21
|
export declare const packageCommands: {
|
|
18
22
|
uploadIpa: ({ args, options, }: {
|
|
19
23
|
args: string[];
|
package/lib/package.js
CHANGED
|
@@ -43,17 +43,21 @@ exports.choosePackage = choosePackage;
|
|
|
43
43
|
const fs = __importStar(require("fs-extra"));
|
|
44
44
|
const os_1 = __importDefault(require("os"));
|
|
45
45
|
const path_1 = __importDefault(require("path"));
|
|
46
|
-
const tty_table_1 = __importDefault(require("tty-table"));
|
|
47
46
|
const api_1 = require("./api");
|
|
48
47
|
const app_1 = require("./app");
|
|
49
48
|
const native_package_1 = require("./native-package");
|
|
50
49
|
const utils_1 = require("./utils");
|
|
51
|
-
const aab_1 = require("./utils/app-info-parser/aab");
|
|
52
50
|
const dep_versions_1 = require("./utils/dep-versions");
|
|
53
51
|
const git_1 = require("./utils/git");
|
|
54
52
|
const hermes_base_1 = require("./utils/hermes-base");
|
|
55
53
|
const i18n_1 = require("./utils/i18n");
|
|
56
54
|
const options_1 = require("./utils/options");
|
|
55
|
+
const zip_range_1 = require("./utils/zip-range");
|
|
56
|
+
// the AAB parser drags in protobufjs; load it only for the aab commands
|
|
57
|
+
function createAabParser(source) {
|
|
58
|
+
const { AabParser } = require('./utils/app-info-parser/aab');
|
|
59
|
+
return new AabParser(source);
|
|
60
|
+
}
|
|
57
61
|
function normalizeUploadBuildTime(value) {
|
|
58
62
|
return String(value);
|
|
59
63
|
}
|
|
@@ -122,10 +126,18 @@ async function uploadNativePackage(filePath, options, config) {
|
|
|
122
126
|
try {
|
|
123
127
|
await (0, native_package_1.createSlimNativePackage)(filePath, slimPackagePath, config.platform);
|
|
124
128
|
const { hash } = await (0, api_1.uploadFile)(slimPackagePath, undefined, appId);
|
|
129
|
+
// where the bundle sits inside the uploaded (slim) archive, so a later
|
|
130
|
+
// `bundle` that falls back to this package as hermes base fetches only
|
|
131
|
+
// the bundle with one HTTP Range request. Harmony .app nests a second
|
|
132
|
+
// zip, so no location is reported for it.
|
|
133
|
+
const bundleLocation = config.extension === '.app'
|
|
134
|
+
? {}
|
|
135
|
+
: (0, zip_range_1.bundleLocationFields)(await (0, zip_range_1.locateZipEntry)(slimPackagePath, (0, hermes_base_1.bundleEntryMatcher)(config.extension.slice(1))).catch(() => null));
|
|
125
136
|
if (bundleFile) {
|
|
126
137
|
// keep the embedded bundle locally so a later `bundle` can use it as
|
|
127
|
-
// hermes base without downloading it back (see hermes-base.ts)
|
|
128
|
-
|
|
138
|
+
// hermes base without downloading it back (see hermes-base.ts); getInfo
|
|
139
|
+
// already hashed the bundle, so pass that hash instead of hashing twice
|
|
140
|
+
await (0, hermes_base_1.cachePut)(bundleFile, undefined, bundleHash).catch(() => { });
|
|
129
141
|
}
|
|
130
142
|
const normalizedBuildTime = config.normalizeBuildTime
|
|
131
143
|
? config.normalizeBuildTime(buildTime)
|
|
@@ -139,7 +151,8 @@ async function uploadNativePackage(filePath, options, config) {
|
|
|
139
151
|
// against the client-reported bundleHash to decide pdiff applicability.
|
|
140
152
|
// Old servers strip unknown fields, so this is forward-compatible.
|
|
141
153
|
...(bundleHash ? { bundleHash } : {}),
|
|
142
|
-
|
|
154
|
+
...bundleLocation,
|
|
155
|
+
deps: (0, dep_versions_1.getDepVersions)(),
|
|
143
156
|
commit: await (0, git_1.getCommitInfo)(),
|
|
144
157
|
});
|
|
145
158
|
console.log((0, i18n_1.t)(config.successKey, {
|
|
@@ -152,8 +165,12 @@ async function uploadNativePackage(filePath, options, config) {
|
|
|
152
165
|
await fs.remove(tempRoot);
|
|
153
166
|
}
|
|
154
167
|
}
|
|
155
|
-
|
|
156
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Print the app's native packages. Pass `packages` when the caller already
|
|
170
|
+
* fetched them (every page of the list), to skip fetching them again.
|
|
171
|
+
*/
|
|
172
|
+
async function listPackage(appId, packages) {
|
|
173
|
+
const allPkgs = packages ?? (await (0, api_1.getAllPackages)(appId)) ?? [];
|
|
157
174
|
const header = [
|
|
158
175
|
{ value: (0, i18n_1.t)('nativePackageId') },
|
|
159
176
|
{ value: (0, i18n_1.t)('nativeVersion') },
|
|
@@ -179,12 +196,14 @@ async function listPackage(appId) {
|
|
|
179
196
|
output += versionInfo;
|
|
180
197
|
rows.push([pkg.id, output]);
|
|
181
198
|
}
|
|
182
|
-
|
|
199
|
+
// tty-table is ~25 ms to load; only pay for it when a table is rendered
|
|
200
|
+
const Table = (0, utils_1.loadTtyTable)();
|
|
201
|
+
console.log(Table(header, rows).render());
|
|
183
202
|
console.log((0, i18n_1.t)('totalPackages', { count: allPkgs.length }));
|
|
184
203
|
return allPkgs;
|
|
185
204
|
}
|
|
186
|
-
async function choosePackage(appId) {
|
|
187
|
-
const list = await listPackage(appId);
|
|
205
|
+
async function choosePackage(appId, packages) {
|
|
206
|
+
const list = await listPackage(appId, packages);
|
|
188
207
|
const packageMap = new Map(list?.map((v) => [v.id.toString(), v]));
|
|
189
208
|
while (true) {
|
|
190
209
|
const id = await (0, utils_1.question)((0, i18n_1.t)('enterNativePackageId'));
|
|
@@ -225,7 +244,7 @@ exports.packageCommands = {
|
|
|
225
244
|
const output = path_1.default.join(tempRoot, 'universal.apk');
|
|
226
245
|
const includeAllSplits = parseBooleanOption(options.includeAllSplits);
|
|
227
246
|
const splits = parseCsvOption(options.splits);
|
|
228
|
-
const parser =
|
|
247
|
+
const parser = createAabParser(source);
|
|
229
248
|
try {
|
|
230
249
|
await parser.extractApk(output, {
|
|
231
250
|
includeAllSplits,
|
|
@@ -286,7 +305,7 @@ exports.packageCommands = {
|
|
|
286
305
|
path_1.default.join(path_1.default.dirname(source), `${path_1.default.basename(source, path_1.default.extname(source))}.apk`);
|
|
287
306
|
const includeAllSplits = parseBooleanOption(options.includeAllSplits);
|
|
288
307
|
const splits = parseCsvOption(options.splits);
|
|
289
|
-
const parser =
|
|
308
|
+
const parser = createAabParser(source);
|
|
290
309
|
await parser.extractApk(output, {
|
|
291
310
|
includeAllSplits,
|
|
292
311
|
splits,
|
package/lib/types.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export interface BundleOptions {
|
|
|
51
51
|
hermesBase?: string;
|
|
52
52
|
/** run the disassembly equivalence check after a base compile (default true) */
|
|
53
53
|
verifyHermesBase?: boolean;
|
|
54
|
+
/** pass --reset-cache to Metro (default true); false reuses its transform cache */
|
|
55
|
+
resetCache?: boolean;
|
|
54
56
|
sentryRelease?: string;
|
|
55
57
|
sentryDist?: string;
|
|
56
58
|
}
|
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/** Installed versions of the cwd project's dependencies, keys sorted. */
|
|
2
|
+
export declare function getDepVersions(): Record<string, string>;
|
|
3
|
+
/**
|
|
4
|
+
* Same data as `getDepVersions()` but as a lazily populated object, for the
|
|
5
|
+
* remaining property-access call sites (`depVersions['react-native']`).
|
|
6
|
+
* Nothing is resolved until the first property access.
|
|
7
|
+
*/
|
|
1
8
|
export declare const depVersions: Record<string, string>;
|