react-native-update-cli 2.22.7 → 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 +11 -4
- package/lib/bundle-runner.js +176 -90
- 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 +22 -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 +21 -4
- package/lib/utils/hermes-base.js +146 -37
- 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 +47 -15
- package/lib/utils/zip-range.js +192 -83
- package/lib/versions.js +19 -9
- 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 +225 -113
- 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 +26 -13
- 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 +156 -45
- 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 +244 -88
- package/src/versions.ts +17 -7
package/src/diff.ts
CHANGED
|
@@ -11,8 +11,10 @@ import { translateOptions } from './utils';
|
|
|
11
11
|
import { isPPKBundleFileName, scriptName, tempDir } from './utils/constants';
|
|
12
12
|
import {
|
|
13
13
|
type HbcTransformMeta,
|
|
14
|
-
|
|
14
|
+
transformHbcFile,
|
|
15
|
+
transformHbcWithLayoutInPlace,
|
|
15
16
|
tryTransformPair,
|
|
17
|
+
tryTransformPairFiles,
|
|
16
18
|
} from './utils/hbcTransform';
|
|
17
19
|
import { t } from './utils/i18n';
|
|
18
20
|
import {
|
|
@@ -71,8 +73,10 @@ type BundlePatchResult = {
|
|
|
71
73
|
patch: BundlePatch;
|
|
72
74
|
hbcTransform?: HbcTransformMeta;
|
|
73
75
|
};
|
|
74
|
-
type EntryMap = Record<string,
|
|
75
|
-
|
|
76
|
+
type EntryMap = Record<string, ZipEntryContent & { fileName: string }>;
|
|
77
|
+
/** 内容键(见 zipEntryContentKey)→ 原包路径 */
|
|
78
|
+
type ContentMap = Record<string, string>;
|
|
79
|
+
type ZipEntryContent = Pick<Entry, 'crc32' | 'uncompressedSize'>;
|
|
76
80
|
type CopyMap = Record<string, string>;
|
|
77
81
|
type DiffTarget =
|
|
78
82
|
| { kind: 'ppk' }
|
|
@@ -87,6 +91,25 @@ type DiffCommandConfig = {
|
|
|
87
91
|
|
|
88
92
|
export { enumZipEntries, readEntry };
|
|
89
93
|
|
|
94
|
+
/**
|
|
95
|
+
* 判定两个 zip entry 内容相同的键:crc32 单独并不足以证明内容一致(32 位
|
|
96
|
+
* 校验和碰撞并不罕见,尤其是长度不同的文件),必须同时要求解压后长度相等。
|
|
97
|
+
* 仅用于生成端匹配,manifest 里的 copies / copiesCrc 格式不变。
|
|
98
|
+
*/
|
|
99
|
+
export function zipEntryContentKey(entry: ZipEntryContent): string {
|
|
100
|
+
return `${entry.crc32}:${entry.uncompressedSize}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function zipEntriesHaveSameContent(
|
|
104
|
+
left: ZipEntryContent,
|
|
105
|
+
right: ZipEntryContent,
|
|
106
|
+
): boolean {
|
|
107
|
+
return (
|
|
108
|
+
left.crc32 === right.crc32 &&
|
|
109
|
+
left.uncompressedSize === right.uncompressedSize
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
90
113
|
const loadModule = <T>(pkgName: string): T | undefined => {
|
|
91
114
|
const nodePathDirs = (process.env.NODE_PATH || '')
|
|
92
115
|
.split(path.delimiter)
|
|
@@ -111,16 +134,51 @@ function basename(fn: string): string | undefined {
|
|
|
111
134
|
function createOutputZip(output: string) {
|
|
112
135
|
fs.ensureDirSync(path.dirname(output));
|
|
113
136
|
const zipfile = new YazlZipFile();
|
|
137
|
+
const writeStream = fs.createWriteStream(output);
|
|
114
138
|
const writePromise = new Promise<void>((resolve, reject) => {
|
|
115
139
|
zipfile.outputStream.on('error', reject);
|
|
116
|
-
const writeStream = fs.createWriteStream(output);
|
|
117
140
|
// without this, a full disk / read-only target left the promise pending
|
|
118
141
|
writeStream.on('error', reject);
|
|
119
142
|
zipfile.outputStream.pipe(writeStream).on('close', () => {
|
|
120
143
|
resolve(void 0);
|
|
121
144
|
});
|
|
122
145
|
});
|
|
123
|
-
|
|
146
|
+
// 失败时释放输出 fd 并删掉半成品,避免残留一个截断的 patch 包
|
|
147
|
+
const abort = async () => {
|
|
148
|
+
writePromise.catch(() => {});
|
|
149
|
+
zipfile.outputStream.unpipe(writeStream);
|
|
150
|
+
// yazl 的 outputStream 类型声明缺 destroy,运行时是 PassThrough
|
|
151
|
+
(zipfile.outputStream as unknown as { destroy(): void }).destroy();
|
|
152
|
+
if (!writeStream.closed) {
|
|
153
|
+
// 等 fd 真正关闭再删文件,避免 Windows 上删除被占用文件失败
|
|
154
|
+
await new Promise<void>((resolve) => {
|
|
155
|
+
writeStream.once('close', () => resolve());
|
|
156
|
+
if (!writeStream.destroyed) {
|
|
157
|
+
writeStream.destroy();
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
await fs.rm(output, { force: true });
|
|
162
|
+
};
|
|
163
|
+
return { zipfile, writePromise, abort };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 打开输出包,执行 build 填充条目并返回 manifest,最后写入 __diff.json
|
|
168
|
+
* 收尾。build 或收尾任何一步失败都会关闭输出流、删除半成品并重新抛出。
|
|
169
|
+
*/
|
|
170
|
+
async function writeDiffZip(
|
|
171
|
+
output: string,
|
|
172
|
+
build: (zipfile: YazlZipFile) => Promise<Record<string, unknown>>,
|
|
173
|
+
) {
|
|
174
|
+
const { zipfile, writePromise, abort } = createOutputZip(output);
|
|
175
|
+
try {
|
|
176
|
+
const manifest = await build(zipfile);
|
|
177
|
+
await finishDiffZip(zipfile, writePromise, manifest);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
await abort();
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
124
182
|
}
|
|
125
183
|
|
|
126
184
|
// baseline patch 小于该值时跳过变换尝试:节省一次 diff 的 CPU,
|
|
@@ -207,10 +265,10 @@ async function filesEqual(leftPath: string, rightPath: string) {
|
|
|
207
265
|
}
|
|
208
266
|
|
|
209
267
|
/**
|
|
210
|
-
* 大 bundle
|
|
211
|
-
* 避免 old/new/restored 的整块 Buffer 副本。HBC
|
|
212
|
-
*
|
|
213
|
-
*
|
|
268
|
+
* 大 bundle 流式路径:bundle 直接从 ZIP entry 落盘后传入 native,
|
|
269
|
+
* 避免 old/new/restored 的整块 Buffer 副本。HBC 变换 T/T⁻¹ 也在文件上
|
|
270
|
+
* 按段定位改写(transformHbcFile),全程不持有整个 bundle。native 已
|
|
271
|
+
* 自校验的普通产物不再重复 patch;自定义/变换路径仍保留 round-trip 校验。
|
|
214
272
|
*/
|
|
215
273
|
async function buildStreamBundlePatch(
|
|
216
274
|
originSource: BundleSource,
|
|
@@ -241,25 +299,17 @@ async function buildStreamBundlePatch(
|
|
|
241
299
|
newSource,
|
|
242
300
|
path.join(tempRoot, 'new.bin'),
|
|
243
301
|
);
|
|
244
|
-
|
|
245
|
-
? await bundleSourceBuffer(originSource)
|
|
246
|
-
: null;
|
|
247
|
-
const newBuffer = options.hbcTransform
|
|
248
|
-
? await bundleSourceBuffer(newSource)
|
|
249
|
-
: null;
|
|
250
|
-
const pair =
|
|
251
|
-
originBuffer && newBuffer
|
|
252
|
-
? tryTransformPair(originBuffer, newBuffer)
|
|
253
|
-
: null;
|
|
302
|
+
// 变换走文件版 T:只读头部选布局、按段定位改写,不把 bundle 读进内存
|
|
254
303
|
const transformedOldFile = path.join(tempRoot, 'old-transformed.bin');
|
|
255
304
|
const transformedNewFile = path.join(tempRoot, 'new-transformed.bin');
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
305
|
+
const pair = options.hbcTransform
|
|
306
|
+
? await tryTransformPairFiles(
|
|
307
|
+
rawOldFile,
|
|
308
|
+
rawNewFile,
|
|
309
|
+
transformedOldFile,
|
|
310
|
+
transformedNewFile,
|
|
311
|
+
)
|
|
312
|
+
: null;
|
|
263
313
|
reportDiffPhase(options, {
|
|
264
314
|
phase: 'materialize',
|
|
265
315
|
durationMs: extractionDurationMs + performance.now() - phaseStartedAt,
|
|
@@ -307,17 +357,15 @@ async function buildStreamBundlePatch(
|
|
|
307
357
|
restoredFile,
|
|
308
358
|
);
|
|
309
359
|
if (chosenPair) {
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
|
|
360
|
+
// T⁻¹ 同样在文件上按段改写,再以流式哈希比对,内存与 bundle 大小无关
|
|
361
|
+
const restoredRawFile = path.join(tempRoot, 'restored-raw.bin');
|
|
362
|
+
const inverted = await transformHbcFile(
|
|
363
|
+
restoredFile,
|
|
364
|
+
restoredRawFile,
|
|
313
365
|
chosenPair.layout,
|
|
314
366
|
true,
|
|
315
367
|
);
|
|
316
|
-
if (
|
|
317
|
-
!restored ||
|
|
318
|
-
!newBuffer ||
|
|
319
|
-
Buffer.compare(restored, newBuffer) !== 0
|
|
320
|
-
) {
|
|
368
|
+
if (!inverted || !(await filesEqual(restoredRawFile, rawNewFile))) {
|
|
321
369
|
throw new Error('stream diff round-trip verification failed');
|
|
322
370
|
}
|
|
323
371
|
} else if (!(await filesEqual(restoredFile, rawNewFile))) {
|
|
@@ -395,9 +443,12 @@ async function buildBundlePatch(
|
|
|
395
443
|
return { patch: { kind: 'buffer', data: baseline } };
|
|
396
444
|
}
|
|
397
445
|
|
|
446
|
+
// patched 是 patchFn 新返回的 Buffer,原地做 T⁻¹ 省去一次整块拷贝
|
|
398
447
|
const patched = options.patchFn(pair.tOld, candidate);
|
|
399
|
-
|
|
400
|
-
|
|
448
|
+
if (
|
|
449
|
+
!transformHbcWithLayoutInPlace(patched, pair.layout, true) ||
|
|
450
|
+
Buffer.compare(patched, newBuffer) !== 0
|
|
451
|
+
) {
|
|
401
452
|
console.warn(t('hbcTransformRoundTripFailed'));
|
|
402
453
|
return { patch: { kind: 'buffer', data: baseline } };
|
|
403
454
|
}
|
|
@@ -535,7 +586,7 @@ async function diffFromPPK(
|
|
|
535
586
|
workRoot: string,
|
|
536
587
|
) {
|
|
537
588
|
const originEntries: EntryMap = {};
|
|
538
|
-
const originMap:
|
|
589
|
+
const originMap: ContentMap = {};
|
|
539
590
|
|
|
540
591
|
let originSource: BundleSource | undefined;
|
|
541
592
|
|
|
@@ -543,7 +594,7 @@ async function diffFromPPK(
|
|
|
543
594
|
originEntries[entry.fileName] = entry;
|
|
544
595
|
if (!/\/$/.test(entry.fileName)) {
|
|
545
596
|
// isFile
|
|
546
|
-
originMap[entry
|
|
597
|
+
originMap[zipEntryContentKey(entry)] = entry.fileName;
|
|
547
598
|
|
|
548
599
|
if (isPPKBundleFileName(entry.fileName)) {
|
|
549
600
|
// This is source.
|
|
@@ -562,90 +613,91 @@ async function diffFromPPK(
|
|
|
562
613
|
}
|
|
563
614
|
|
|
564
615
|
const copies: CopyMap = {};
|
|
616
|
+
const bundleSource = originSource;
|
|
565
617
|
|
|
566
|
-
|
|
618
|
+
await writeDiffZip(output, async (zipfile) => {
|
|
619
|
+
const addedEntry: Record<string, true> = {};
|
|
567
620
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
621
|
+
function addEntry(fn: string) {
|
|
622
|
+
//console.log(fn);
|
|
623
|
+
if (!fn || addedEntry[fn]) {
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
addedEntry[fn] = true;
|
|
627
|
+
const base = basename(fn);
|
|
628
|
+
if (base) {
|
|
629
|
+
addEntry(base);
|
|
630
|
+
}
|
|
631
|
+
zipfile.addEmptyDirectory(fn);
|
|
579
632
|
}
|
|
580
|
-
zipfile.addEmptyDirectory(fn);
|
|
581
|
-
}
|
|
582
633
|
|
|
583
|
-
|
|
584
|
-
|
|
634
|
+
const newEntries: EntryMap = {};
|
|
635
|
+
const hbcTransformMetas: Record<string, HbcTransformMeta> = {};
|
|
585
636
|
|
|
586
|
-
|
|
587
|
-
|
|
637
|
+
await enumZipEntries(next, async (entry, nextZipfile) => {
|
|
638
|
+
newEntries[entry.fileName] = entry;
|
|
588
639
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
640
|
+
if (/\/$/.test(entry.fileName)) {
|
|
641
|
+
// Directory
|
|
642
|
+
if (!originEntries[entry.fileName]) {
|
|
643
|
+
addEntry(entry.fileName);
|
|
644
|
+
}
|
|
645
|
+
} else if (isPPKBundleFileName(entry.fileName)) {
|
|
646
|
+
await addBundlePatch(
|
|
647
|
+
zipfile,
|
|
648
|
+
entry,
|
|
649
|
+
nextZipfile,
|
|
650
|
+
diffFn,
|
|
651
|
+
bundleSource,
|
|
652
|
+
bundleOptions,
|
|
653
|
+
hbcTransformMetas,
|
|
654
|
+
workRoot,
|
|
655
|
+
);
|
|
656
|
+
} else {
|
|
657
|
+
// If same file.
|
|
658
|
+
const originEntry = originEntries[entry.fileName];
|
|
659
|
+
if (originEntry && zipEntriesHaveSameContent(originEntry, entry)) {
|
|
660
|
+
// ignore
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
612
663
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
664
|
+
// If moved from other place
|
|
665
|
+
const movedFrom = originMap[zipEntryContentKey(entry)];
|
|
666
|
+
if (movedFrom) {
|
|
667
|
+
const base = basename(entry.fileName);
|
|
668
|
+
if (base && !originEntries[base]) {
|
|
669
|
+
addEntry(base);
|
|
670
|
+
}
|
|
671
|
+
copies[entry.fileName] = movedFrom;
|
|
672
|
+
return;
|
|
619
673
|
}
|
|
620
|
-
copies[entry.fileName] = movedFrom;
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
674
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
675
|
+
// New file.
|
|
676
|
+
const basePath = basename(entry.fileName);
|
|
677
|
+
if (basePath) {
|
|
678
|
+
addEntry(basePath);
|
|
679
|
+
}
|
|
629
680
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
681
|
+
await addFileFromZipEntry(zipfile, entry, nextZipfile);
|
|
682
|
+
}
|
|
683
|
+
});
|
|
633
684
|
|
|
634
|
-
|
|
685
|
+
const deletes: Record<string, 1> = {};
|
|
635
686
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
687
|
+
for (const k in originEntries) {
|
|
688
|
+
if (!newEntries[k]) {
|
|
689
|
+
console.log(t('deleteFile', { file: k }));
|
|
690
|
+
deletes[k] = 1;
|
|
691
|
+
}
|
|
640
692
|
}
|
|
641
|
-
}
|
|
642
693
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
694
|
+
return {
|
|
695
|
+
copies,
|
|
696
|
+
deletes,
|
|
697
|
+
...(Object.keys(hbcTransformMetas).length
|
|
698
|
+
? { hbcTransform: hbcTransformMetas }
|
|
699
|
+
: {}),
|
|
700
|
+
};
|
|
649
701
|
});
|
|
650
702
|
}
|
|
651
703
|
|
|
@@ -658,8 +710,9 @@ async function diffFromPackage(
|
|
|
658
710
|
bundleOptions: BundleDiffOptions,
|
|
659
711
|
workRoot: string,
|
|
660
712
|
) {
|
|
661
|
-
|
|
662
|
-
const
|
|
713
|
+
// 路径 → 内容键(crc32 + 解压后长度)
|
|
714
|
+
const originEntries: Record<string, string> = {};
|
|
715
|
+
const originMap: ContentMap = {};
|
|
663
716
|
|
|
664
717
|
let originSource: BundleSource | undefined;
|
|
665
718
|
|
|
@@ -683,8 +736,9 @@ async function diffFromPackage(
|
|
|
683
736
|
|
|
684
737
|
//console.log(fn);
|
|
685
738
|
// isFile
|
|
686
|
-
|
|
687
|
-
|
|
739
|
+
const contentKey = zipEntryContentKey(entry);
|
|
740
|
+
originEntries[fn] = contentKey;
|
|
741
|
+
originMap[contentKey] = fn;
|
|
688
742
|
|
|
689
743
|
if (resolvedEntry.kind === 'bundle') {
|
|
690
744
|
// This is source.
|
|
@@ -703,50 +757,53 @@ async function diffFromPackage(
|
|
|
703
757
|
}
|
|
704
758
|
|
|
705
759
|
const copies: CopyMap = {};
|
|
760
|
+
const bundleSource = originSource;
|
|
761
|
+
|
|
762
|
+
await writeDiffZip(output, async (zipfile) => {
|
|
763
|
+
const hbcTransformMetas: Record<string, HbcTransformMeta> = {};
|
|
764
|
+
|
|
765
|
+
await enumZipEntries(next, async (entry, nextZipfile) => {
|
|
766
|
+
if (/\/$/.test(entry.fileName)) {
|
|
767
|
+
// Directory
|
|
768
|
+
zipfile.addEmptyDirectory(entry.fileName);
|
|
769
|
+
} else if (isPPKBundleFileName(entry.fileName)) {
|
|
770
|
+
await addBundlePatch(
|
|
771
|
+
zipfile,
|
|
772
|
+
entry,
|
|
773
|
+
nextZipfile,
|
|
774
|
+
diffFn,
|
|
775
|
+
bundleSource,
|
|
776
|
+
bundleOptions,
|
|
777
|
+
hbcTransformMetas,
|
|
778
|
+
workRoot,
|
|
779
|
+
);
|
|
780
|
+
} else {
|
|
781
|
+
// If same file.
|
|
782
|
+
const contentKey = zipEntryContentKey(entry);
|
|
783
|
+
if (originEntries[entry.fileName] === contentKey) {
|
|
784
|
+
copies[entry.fileName] = '';
|
|
785
|
+
copiesCrc[entry.fileName] = entry.crc32;
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
// If moved from other place
|
|
789
|
+
const movedFrom = originMap[contentKey];
|
|
790
|
+
if (movedFrom) {
|
|
791
|
+
copies[entry.fileName] = movedFrom;
|
|
792
|
+
copiesCrc[entry.fileName] = entry.crc32;
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
706
795
|
|
|
707
|
-
|
|
708
|
-
const hbcTransformMetas: Record<string, HbcTransformMeta> = {};
|
|
709
|
-
|
|
710
|
-
await enumZipEntries(next, async (entry, nextZipfile) => {
|
|
711
|
-
if (/\/$/.test(entry.fileName)) {
|
|
712
|
-
// Directory
|
|
713
|
-
zipfile.addEmptyDirectory(entry.fileName);
|
|
714
|
-
} else if (isPPKBundleFileName(entry.fileName)) {
|
|
715
|
-
await addBundlePatch(
|
|
716
|
-
zipfile,
|
|
717
|
-
entry,
|
|
718
|
-
nextZipfile,
|
|
719
|
-
diffFn,
|
|
720
|
-
originSource,
|
|
721
|
-
bundleOptions,
|
|
722
|
-
hbcTransformMetas,
|
|
723
|
-
workRoot,
|
|
724
|
-
);
|
|
725
|
-
} else {
|
|
726
|
-
// If same file.
|
|
727
|
-
if (originEntries[entry.fileName] === entry.crc32) {
|
|
728
|
-
copies[entry.fileName] = '';
|
|
729
|
-
copiesCrc[entry.fileName] = entry.crc32;
|
|
730
|
-
return;
|
|
796
|
+
await addFileFromZipEntry(zipfile, entry, nextZipfile);
|
|
731
797
|
}
|
|
732
|
-
|
|
733
|
-
const movedFrom = originMap[entry.crc32];
|
|
734
|
-
if (movedFrom) {
|
|
735
|
-
copies[entry.fileName] = movedFrom;
|
|
736
|
-
copiesCrc[entry.fileName] = entry.crc32;
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
await addFileFromZipEntry(zipfile, entry, nextZipfile);
|
|
741
|
-
}
|
|
742
|
-
});
|
|
798
|
+
});
|
|
743
799
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
800
|
+
return {
|
|
801
|
+
copies,
|
|
802
|
+
copiesCrc,
|
|
803
|
+
...(Object.keys(hbcTransformMetas).length
|
|
804
|
+
? { hbcTransform: hbcTransformMetas }
|
|
805
|
+
: {}),
|
|
806
|
+
};
|
|
750
807
|
});
|
|
751
808
|
}
|
|
752
809
|
|
package/src/locales/en.ts
CHANGED
|
@@ -226,6 +226,8 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|
|
226
226
|
'Hermes base compile failed ({{- reason}}); retrying without -base-bytecode',
|
|
227
227
|
hermesBaseCompileFailedLog:
|
|
228
228
|
'Hermes base: full compiler output written to {{- file}}',
|
|
229
|
+
hermesBasePlainCompileFailed:
|
|
230
|
+
'Hermes base: the plain compile used for verification failed ({{- reason}}); keeping the base compile unverified',
|
|
229
231
|
hermesBaseVerified:
|
|
230
232
|
'Hermes base: bytecode verified equivalent to a plain compile',
|
|
231
233
|
hermesBaseVerifyFailed:
|
package/src/locales/zh.ts
CHANGED
|
@@ -208,6 +208,8 @@ export default {
|
|
|
208
208
|
hermesBaseCompileFailed:
|
|
209
209
|
'Hermes base 编译失败({{- reason}}),改为不带 -base-bytecode 重编',
|
|
210
210
|
hermesBaseCompileFailedLog: 'Hermes base:完整编译错误已写入 {{- file}}',
|
|
211
|
+
hermesBasePlainCompileFailed:
|
|
212
|
+
'Hermes base:用于校验的普通编译失败({{- reason}}),保留 base 编译结果但未校验',
|
|
211
213
|
hermesBaseVerified: 'Hermes base:字节码与普通编译等价,校验通过',
|
|
212
214
|
hermesBaseVerifyFailed:
|
|
213
215
|
'Hermes base:字节码与普通编译不等价,放弃 base 重新编译',
|
package/src/package.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import * as fs from 'fs-extra';
|
|
2
2
|
import os from 'os';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import Table from 'tty-table';
|
|
5
4
|
import { doDelete, getAllPackages, post, uploadFile } from './api';
|
|
6
5
|
import { getPlatform, getSelectedApp } from './app';
|
|
7
6
|
import { createSlimNativePackage } from './native-package';
|
|
8
|
-
import type { Platform } from './types';
|
|
7
|
+
import type { Package, Platform } from './types';
|
|
9
8
|
import {
|
|
10
9
|
getAabInfo,
|
|
11
10
|
getApkInfo,
|
|
12
11
|
getAppInfo,
|
|
13
12
|
getIpaInfo,
|
|
13
|
+
loadTtyTable,
|
|
14
14
|
question,
|
|
15
15
|
} from './utils';
|
|
16
|
-
import {
|
|
17
|
-
import { depVersions } from './utils/dep-versions';
|
|
16
|
+
import { getDepVersions } from './utils/dep-versions';
|
|
18
17
|
import { getCommitInfo } from './utils/git';
|
|
19
18
|
import { bundleEntryMatcher, cachePut } from './utils/hermes-base';
|
|
20
19
|
import { t } from './utils/i18n';
|
|
@@ -61,6 +60,13 @@ type NativeUploadConfig = {
|
|
|
61
60
|
) => string | number | undefined;
|
|
62
61
|
};
|
|
63
62
|
|
|
63
|
+
// the AAB parser drags in protobufjs; load it only for the aab commands
|
|
64
|
+
function createAabParser(source: string) {
|
|
65
|
+
const { AabParser } =
|
|
66
|
+
require('./utils/app-info-parser/aab') as typeof import('./utils/app-info-parser/aab');
|
|
67
|
+
return new AabParser(source);
|
|
68
|
+
}
|
|
69
|
+
|
|
64
70
|
export function normalizeUploadBuildTime(value: unknown): string {
|
|
65
71
|
return String(value);
|
|
66
72
|
}
|
|
@@ -169,8 +175,9 @@ async function uploadNativePackage(
|
|
|
169
175
|
);
|
|
170
176
|
if (bundleFile) {
|
|
171
177
|
// keep the embedded bundle locally so a later `bundle` can use it as
|
|
172
|
-
// hermes base without downloading it back (see hermes-base.ts)
|
|
173
|
-
|
|
178
|
+
// hermes base without downloading it back (see hermes-base.ts); getInfo
|
|
179
|
+
// already hashed the bundle, so pass that hash instead of hashing twice
|
|
180
|
+
await cachePut(bundleFile, undefined, bundleHash).catch(() => {});
|
|
174
181
|
}
|
|
175
182
|
const normalizedBuildTime = config.normalizeBuildTime
|
|
176
183
|
? config.normalizeBuildTime(buildTime)
|
|
@@ -186,7 +193,7 @@ async function uploadNativePackage(
|
|
|
186
193
|
// Old servers strip unknown fields, so this is forward-compatible.
|
|
187
194
|
...(bundleHash ? { bundleHash } : {}),
|
|
188
195
|
...bundleLocation,
|
|
189
|
-
deps:
|
|
196
|
+
deps: getDepVersions(),
|
|
190
197
|
commit: await getCommitInfo(),
|
|
191
198
|
});
|
|
192
199
|
console.log(
|
|
@@ -201,8 +208,12 @@ async function uploadNativePackage(
|
|
|
201
208
|
}
|
|
202
209
|
}
|
|
203
210
|
|
|
204
|
-
|
|
205
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Print the app's native packages. Pass `packages` when the caller already
|
|
213
|
+
* fetched them (every page of the list), to skip fetching them again.
|
|
214
|
+
*/
|
|
215
|
+
export async function listPackage(appId: string, packages?: Package[]) {
|
|
216
|
+
const allPkgs = packages ?? (await getAllPackages(appId)) ?? [];
|
|
206
217
|
|
|
207
218
|
const header = [
|
|
208
219
|
{ value: t('nativePackageId') },
|
|
@@ -230,13 +241,15 @@ export async function listPackage(appId: string) {
|
|
|
230
241
|
rows.push([pkg.id, output]);
|
|
231
242
|
}
|
|
232
243
|
|
|
244
|
+
// tty-table is ~25 ms to load; only pay for it when a table is rendered
|
|
245
|
+
const Table = loadTtyTable();
|
|
233
246
|
console.log(Table(header, rows).render());
|
|
234
247
|
console.log(t('totalPackages', { count: allPkgs.length }));
|
|
235
248
|
return allPkgs;
|
|
236
249
|
}
|
|
237
250
|
|
|
238
|
-
export async function choosePackage(appId: string) {
|
|
239
|
-
const list = await listPackage(appId);
|
|
251
|
+
export async function choosePackage(appId: string, packages?: Package[]) {
|
|
252
|
+
const list = await listPackage(appId, packages);
|
|
240
253
|
const packageMap = new Map(list?.map((v) => [v.id.toString(), v]));
|
|
241
254
|
|
|
242
255
|
while (true) {
|
|
@@ -302,7 +315,7 @@ export const packageCommands = {
|
|
|
302
315
|
const includeAllSplits = parseBooleanOption(options.includeAllSplits);
|
|
303
316
|
const splits = parseCsvOption(options.splits);
|
|
304
317
|
|
|
305
|
-
const parser =
|
|
318
|
+
const parser = createAabParser(source);
|
|
306
319
|
try {
|
|
307
320
|
await parser.extractApk(output, {
|
|
308
321
|
includeAllSplits,
|
|
@@ -381,7 +394,7 @@ export const packageCommands = {
|
|
|
381
394
|
const includeAllSplits = parseBooleanOption(options.includeAllSplits);
|
|
382
395
|
const splits = parseCsvOption(options.splits);
|
|
383
396
|
|
|
384
|
-
const parser =
|
|
397
|
+
const parser = createAabParser(source);
|
|
385
398
|
await parser.extractApk(output, {
|
|
386
399
|
includeAllSplits,
|
|
387
400
|
splits,
|
package/src/types.ts
CHANGED
|
@@ -61,6 +61,8 @@ export interface BundleOptions {
|
|
|
61
61
|
hermesBase?: string;
|
|
62
62
|
/** run the disassembly equivalence check after a base compile (default true) */
|
|
63
63
|
verifyHermesBase?: boolean;
|
|
64
|
+
/** pass --reset-cache to Metro (default true); false reuses its transform cache */
|
|
65
|
+
resetCache?: boolean;
|
|
64
66
|
sentryRelease?: string;
|
|
65
67
|
sentryDist?: string;
|
|
66
68
|
}
|