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.
Files changed (59) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/cli.json +5 -0
  4. package/lib/api.d.ts +7 -0
  5. package/lib/api.js +106 -38
  6. package/lib/app.js +3 -2
  7. package/lib/bin.js +16 -2
  8. package/lib/bundle-runner.d.ts +35 -2
  9. package/lib/bundle-runner.js +313 -128
  10. package/lib/bundle.d.ts +1 -0
  11. package/lib/bundle.js +2 -0
  12. package/lib/diff.d.ts +9 -0
  13. package/lib/diff.js +162 -120
  14. package/lib/locales/en.d.ts +1 -0
  15. package/lib/locales/en.js +1 -0
  16. package/lib/locales/zh.d.ts +1 -0
  17. package/lib/locales/zh.js +1 -0
  18. package/lib/package.d.ts +7 -3
  19. package/lib/package.js +31 -12
  20. package/lib/types.d.ts +2 -0
  21. package/lib/utils/dep-versions.d.ts +7 -0
  22. package/lib/utils/dep-versions.js +66 -31
  23. package/lib/utils/hbcTransform.d.ts +21 -0
  24. package/lib/utils/hbcTransform.js +146 -5
  25. package/lib/utils/hermes-base.d.ts +31 -7
  26. package/lib/utils/hermes-base.js +284 -76
  27. package/lib/utils/http-helper.d.ts +6 -1
  28. package/lib/utils/http-helper.js +23 -11
  29. package/lib/utils/index.d.ts +30 -1
  30. package/lib/utils/index.js +98 -24
  31. package/lib/utils/latest-version/index.d.ts +11 -8
  32. package/lib/utils/latest-version/index.js +63 -18
  33. package/lib/utils/zip-entries.js +20 -15
  34. package/lib/utils/zip-options.d.ts +2 -0
  35. package/lib/utils/zip-options.js +9 -4
  36. package/lib/utils/zip-range.d.ts +84 -13
  37. package/lib/utils/zip-range.js +363 -63
  38. package/lib/versions.js +30 -23
  39. package/package.json +11 -11
  40. package/src/api.ts +126 -46
  41. package/src/app.ts +3 -2
  42. package/src/bin.ts +17 -2
  43. package/src/bundle-runner.ts +419 -171
  44. package/src/bundle.ts +3 -0
  45. package/src/diff.ts +210 -153
  46. package/src/locales/en.ts +2 -0
  47. package/src/locales/zh.ts +2 -0
  48. package/src/package.ts +42 -14
  49. package/src/types.ts +2 -0
  50. package/src/utils/dep-versions.ts +76 -33
  51. package/src/utils/hbcTransform.ts +194 -5
  52. package/src/utils/hermes-base.ts +311 -81
  53. package/src/utils/http-helper.ts +24 -13
  54. package/src/utils/index.ts +136 -26
  55. package/src/utils/latest-version/index.ts +82 -29
  56. package/src/utils/zip-entries.ts +18 -16
  57. package/src/utils/zip-options.ts +8 -3
  58. package/src/utils/zip-range.ts +436 -67
  59. package/src/versions.ts +34 -26
package/src/bundle.ts CHANGED
@@ -39,6 +39,7 @@ type NormalizedBundleOptions = {
39
39
  hermes: boolean;
40
40
  hermesBase: string;
41
41
  verifyHermesBase: boolean;
42
+ resetCache: boolean;
42
43
  cacheMaxMb?: number;
43
44
  name?: string;
44
45
  description?: string;
@@ -118,6 +119,7 @@ export function normalizeBundleOptions(
118
119
  'verifyHermesBase',
119
120
  true,
120
121
  ),
122
+ resetCache: getBooleanOption(translatedOptions, 'resetCache', true),
121
123
  cacheMaxMb: parseCacheMaxMb(translatedOptions.cacheMaxMb),
122
124
  name: getOptionalStringOption(translatedOptions, 'name'),
123
125
  description: getOptionalStringOption(translatedOptions, 'description'),
@@ -262,6 +264,7 @@ export const bundleCommands = {
262
264
  verify: normalized.verifyHermesBase,
263
265
  cacheMaxMb: normalized.cacheMaxMb,
264
266
  },
267
+ resetCache: normalized.resetCache,
265
268
  cli: {
266
269
  taro: normalized.taro,
267
270
  expo: normalized.expo,
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
- transformHbcWithLayout,
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, { crc32: number; fileName: string }>;
75
- type CrcMap = Record<number, string>;
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
- return { zipfile, writePromise };
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 流式路径:普通 bundle 直接从 ZIP entry 落盘后传入 native,
211
- * 避免 old/new/restored 的整块 Buffer 副本。HBC 变换仍需 Buffer,因为
212
- * T/T⁻¹ 当前是内存算法。native 已自校验的普通产物不再重复 patch;
213
- * 自定义/变换路径仍保留 round-trip 校验。
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
- const originBuffer = options.hbcTransform
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
- if (pair) {
258
- await Promise.all([
259
- fs.writeFile(transformedOldFile, pair.tOld),
260
- fs.writeFile(transformedNewFile, pair.tNew),
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
- const restoredRaw = await fs.readFile(restoredFile);
311
- const restored = transformHbcWithLayout(
312
- restoredRaw,
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
- const restored = transformHbcWithLayout(patched, pair.layout, true);
400
- if (!restored || Buffer.compare(restored, newBuffer) !== 0) {
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: CrcMap = {};
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.crc32] = entry.fileName;
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
- const { zipfile, writePromise } = createOutputZip(output);
618
+ await writeDiffZip(output, async (zipfile) => {
619
+ const addedEntry: Record<string, true> = {};
567
620
 
568
- const addedEntry: Record<string, true> = {};
569
-
570
- function addEntry(fn: string) {
571
- //console.log(fn);
572
- if (!fn || addedEntry[fn]) {
573
- return;
574
- }
575
- addedEntry[fn] = true;
576
- const base = basename(fn);
577
- if (base) {
578
- addEntry(base);
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
- const newEntries: EntryMap = {};
584
- const hbcTransformMetas: Record<string, HbcTransformMeta> = {};
634
+ const newEntries: EntryMap = {};
635
+ const hbcTransformMetas: Record<string, HbcTransformMeta> = {};
585
636
 
586
- await enumZipEntries(next, async (entry, nextZipfile) => {
587
- newEntries[entry.fileName] = entry;
637
+ await enumZipEntries(next, async (entry, nextZipfile) => {
638
+ newEntries[entry.fileName] = entry;
588
639
 
589
- if (/\/$/.test(entry.fileName)) {
590
- // Directory
591
- if (!originEntries[entry.fileName]) {
592
- addEntry(entry.fileName);
593
- }
594
- } else if (isPPKBundleFileName(entry.fileName)) {
595
- await addBundlePatch(
596
- zipfile,
597
- entry,
598
- nextZipfile,
599
- diffFn,
600
- originSource,
601
- bundleOptions,
602
- hbcTransformMetas,
603
- workRoot,
604
- );
605
- } else {
606
- // If same file.
607
- const originEntry = originEntries[entry.fileName];
608
- if (originEntry && originEntry.crc32 === entry.crc32) {
609
- // ignore
610
- return;
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
- // If moved from other place
614
- const movedFrom = originMap[entry.crc32];
615
- if (movedFrom) {
616
- const base = basename(entry.fileName);
617
- if (base && !originEntries[base]) {
618
- addEntry(base);
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
- // New file.
625
- const basePath = basename(entry.fileName);
626
- if (basePath) {
627
- addEntry(basePath);
628
- }
675
+ // New file.
676
+ const basePath = basename(entry.fileName);
677
+ if (basePath) {
678
+ addEntry(basePath);
679
+ }
629
680
 
630
- await addFileFromZipEntry(zipfile, entry, nextZipfile);
631
- }
632
- });
681
+ await addFileFromZipEntry(zipfile, entry, nextZipfile);
682
+ }
683
+ });
633
684
 
634
- const deletes: Record<string, 1> = {};
685
+ const deletes: Record<string, 1> = {};
635
686
 
636
- for (const k in originEntries) {
637
- if (!newEntries[k]) {
638
- console.log(t('deleteFile', { file: k }));
639
- deletes[k] = 1;
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
- await finishDiffZip(zipfile, writePromise, {
644
- copies,
645
- deletes,
646
- ...(Object.keys(hbcTransformMetas).length
647
- ? { hbcTransform: hbcTransformMetas }
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
- const originEntries: Record<string, number> = {};
662
- const originMap: CrcMap = {};
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
- originEntries[fn] = entry.crc32;
687
- originMap[entry.crc32] = fn;
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
- const { zipfile, writePromise } = createOutputZip(output);
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
- // If moved from other place
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
- await finishDiffZip(zipfile, writePromise, {
745
- copies,
746
- copiesCrc,
747
- ...(Object.keys(hbcTransformMetas).length
748
- ? { hbcTransform: hbcTransformMetas }
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,24 +1,24 @@
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 { AabParser } from './utils/app-info-parser/aab';
17
- import { depVersions } from './utils/dep-versions';
16
+ import { getDepVersions } from './utils/dep-versions';
18
17
  import { getCommitInfo } from './utils/git';
19
- import { cachePut } from './utils/hermes-base';
18
+ import { bundleEntryMatcher, cachePut } from './utils/hermes-base';
20
19
  import { t } from './utils/i18n';
21
20
  import { getStringListOption } from './utils/options';
21
+ import { bundleLocationFields, locateZipEntry } from './utils/zip-range';
22
22
 
23
23
  type PackageCommandOptions = Record<string, unknown> & {
24
24
  appId?: string;
@@ -60,6 +60,13 @@ type NativeUploadConfig = {
60
60
  ) => string | number | undefined;
61
61
  };
62
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
+
63
70
  export function normalizeUploadBuildTime(value: unknown): string {
64
71
  return String(value);
65
72
  }
@@ -153,10 +160,24 @@ async function uploadNativePackage(
153
160
  try {
154
161
  await createSlimNativePackage(filePath, slimPackagePath, config.platform);
155
162
  const { hash } = await uploadFile(slimPackagePath, undefined, appId);
163
+ // where the bundle sits inside the uploaded (slim) archive, so a later
164
+ // `bundle` that falls back to this package as hermes base fetches only
165
+ // the bundle with one HTTP Range request. Harmony .app nests a second
166
+ // zip, so no location is reported for it.
167
+ const bundleLocation =
168
+ config.extension === '.app'
169
+ ? {}
170
+ : bundleLocationFields(
171
+ await locateZipEntry(
172
+ slimPackagePath,
173
+ bundleEntryMatcher(config.extension.slice(1) as 'apk' | 'ipa'),
174
+ ).catch(() => null),
175
+ );
156
176
  if (bundleFile) {
157
177
  // keep the embedded bundle locally so a later `bundle` can use it as
158
- // hermes base without downloading it back (see hermes-base.ts)
159
- await cachePut(bundleFile).catch(() => {});
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(() => {});
160
181
  }
161
182
  const normalizedBuildTime = config.normalizeBuildTime
162
183
  ? config.normalizeBuildTime(buildTime)
@@ -171,7 +192,8 @@ async function uploadNativePackage(
171
192
  // against the client-reported bundleHash to decide pdiff applicability.
172
193
  // Old servers strip unknown fields, so this is forward-compatible.
173
194
  ...(bundleHash ? { bundleHash } : {}),
174
- deps: depVersions,
195
+ ...bundleLocation,
196
+ deps: getDepVersions(),
175
197
  commit: await getCommitInfo(),
176
198
  });
177
199
  console.log(
@@ -186,8 +208,12 @@ async function uploadNativePackage(
186
208
  }
187
209
  }
188
210
 
189
- export async function listPackage(appId: string) {
190
- const allPkgs = (await getAllPackages(appId)) || [];
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)) ?? [];
191
217
 
192
218
  const header = [
193
219
  { value: t('nativePackageId') },
@@ -215,13 +241,15 @@ export async function listPackage(appId: string) {
215
241
  rows.push([pkg.id, output]);
216
242
  }
217
243
 
244
+ // tty-table is ~25 ms to load; only pay for it when a table is rendered
245
+ const Table = loadTtyTable();
218
246
  console.log(Table(header, rows).render());
219
247
  console.log(t('totalPackages', { count: allPkgs.length }));
220
248
  return allPkgs;
221
249
  }
222
250
 
223
- export async function choosePackage(appId: string) {
224
- const list = await listPackage(appId);
251
+ export async function choosePackage(appId: string, packages?: Package[]) {
252
+ const list = await listPackage(appId, packages);
225
253
  const packageMap = new Map(list?.map((v) => [v.id.toString(), v]));
226
254
 
227
255
  while (true) {
@@ -287,7 +315,7 @@ export const packageCommands = {
287
315
  const includeAllSplits = parseBooleanOption(options.includeAllSplits);
288
316
  const splits = parseCsvOption(options.splits);
289
317
 
290
- const parser = new AabParser(source);
318
+ const parser = createAabParser(source);
291
319
  try {
292
320
  await parser.extractApk(output, {
293
321
  includeAllSplits,
@@ -366,7 +394,7 @@ export const packageCommands = {
366
394
  const includeAllSplits = parseBooleanOption(options.includeAllSplits);
367
395
  const splits = parseCsvOption(options.splits);
368
396
 
369
- const parser = new AabParser(source);
397
+ const parser = createAabParser(source);
370
398
  await parser.extractApk(output, {
371
399
  includeAllSplits,
372
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
  }