react-native-update-cli 2.19.0 → 2.20.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/src/diff.ts CHANGED
@@ -1,10 +1,12 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import * as fs from 'fs-extra';
2
3
  import { npm, yarn } from 'global-dirs';
3
4
  import os from 'os';
4
5
  import path from 'path';
5
6
  import type { Entry, ZipFile as YauzlZipFile } from 'yauzl';
6
7
  import { ZipFile as YazlZipFile } from 'yazl';
7
- import type { CommandContext } from './types';
8
+ import { resolveNativePackageEntry } from './native-package';
9
+ import type { CommandContext, Platform } from './types';
8
10
  import { translateOptions } from './utils';
9
11
  import { isPPKBundleFileName, scriptName, tempDir } from './utils/constants';
10
12
  import {
@@ -17,6 +19,7 @@ import {
17
19
  enumZipEntries,
18
20
  readEntry,
19
21
  readEntryPrefix,
22
+ writeEntry,
20
23
  } from './utils/zip-entries';
21
24
  import {
22
25
  ZIP_ENTRY_SNIFF_BYTES,
@@ -47,17 +50,35 @@ type HdiffModule = {
47
50
  patchStream?: PatchStream;
48
51
  diffSingleStream?: DiffStream;
49
52
  patchSingleStream?: PatchStream;
53
+ capabilities?: {
54
+ diffStreamVerifiesOutput?: boolean;
55
+ diffSingleStreamVerifiesOutput?: boolean;
56
+ diffWindowVerifiesOutput?: boolean;
57
+ };
58
+ };
59
+ type BundleSource =
60
+ | { kind: 'buffer'; data: Buffer }
61
+ | {
62
+ kind: 'file';
63
+ path: string;
64
+ size: number;
65
+ materializeDurationMs: number;
66
+ };
67
+ type BundlePatch =
68
+ | { kind: 'buffer'; data: Buffer }
69
+ | { kind: 'file'; path: string };
70
+ type BundlePatchResult = {
71
+ patch: BundlePatch;
72
+ hbcTransform?: HbcTransformMeta;
50
73
  };
51
74
  type EntryMap = Record<string, { crc32: number; fileName: string }>;
52
75
  type CrcMap = Record<number, string>;
53
76
  type CopyMap = Record<string, string>;
54
- type PackagePathTransform = (v: string) => string | undefined;
55
77
  type DiffTarget =
56
78
  | { kind: 'ppk' }
57
79
  | {
58
80
  kind: 'package';
59
- originBundleName: string;
60
- transformPackagePath?: PackagePathTransform;
81
+ platform: Platform;
61
82
  };
62
83
  type DiffCommandConfig = {
63
84
  diffFnName: string;
@@ -120,19 +141,80 @@ type BundleDiffOptions = {
120
141
  patchStreamFn?: PatchStream;
121
142
  /** 流式产物是否为 single 格式(决定 baseline 轨道是否可用) */
122
143
  streamEmitsSingleFormat?: boolean;
144
+ /** diffStreamFn 内部已经完整 apply-and-compare,可跳过重复还原 */
145
+ streamOutputVerified?: boolean;
146
+ onDiffPhase?: (metric: {
147
+ phase: 'materialize' | 'diff' | 'verify';
148
+ durationMs: number;
149
+ inputBytes: number;
150
+ outputBytes?: number;
151
+ skipped?: boolean;
152
+ }) => void;
123
153
  };
124
154
 
155
+ function reportDiffPhase(
156
+ options: BundleDiffOptions,
157
+ metric: Parameters<NonNullable<BundleDiffOptions['onDiffPhase']>>[0],
158
+ ) {
159
+ try {
160
+ options.onDiffPhase?.(metric);
161
+ } catch {
162
+ // Observability must never break patch generation.
163
+ }
164
+ }
165
+
166
+ const bundleSourceSize = (source: BundleSource) =>
167
+ source.kind === 'buffer' ? source.data.length : source.size;
168
+
169
+ const bundleSourceBuffer = async (source: BundleSource) =>
170
+ source.kind === 'buffer' ? source.data : fs.readFile(source.path);
171
+
172
+ async function bundleSourceFile(
173
+ source: BundleSource,
174
+ outputPath: string,
175
+ ): Promise<string> {
176
+ if (source.kind === 'file') {
177
+ return source.path;
178
+ }
179
+ await fs.writeFile(outputPath, source.data);
180
+ return outputPath;
181
+ }
182
+
183
+ async function hashFile(filePath: string): Promise<string> {
184
+ const hash = createHash('sha256');
185
+ for await (const chunk of fs.createReadStream(filePath)) {
186
+ hash.update(chunk as Buffer);
187
+ }
188
+ return hash.digest('hex');
189
+ }
190
+
191
+ async function filesEqual(leftPath: string, rightPath: string) {
192
+ const [leftStat, rightStat] = await Promise.all([
193
+ fs.stat(leftPath),
194
+ fs.stat(rightPath),
195
+ ]);
196
+ if (leftStat.size !== rightStat.size) {
197
+ return false;
198
+ }
199
+ const [leftHash, rightHash] = await Promise.all([
200
+ hashFile(leftPath),
201
+ hashFile(rightPath),
202
+ ]);
203
+ return leftHash === rightHash;
204
+ }
205
+
125
206
  /**
126
- * 大 bundle 流式路径:可选 HBC 变换(在 buffer 上做,写临时文件)后
127
- * diffStream 生成 HDIFF13,并以 patchStream + T⁻¹ 做 round-trip 自检。
128
- * 自检失败直接抛错(此路径没有 baseline 可回退——内存 diff 正是要避免的),
129
- * 由上层按任务失败重试/告警处理。
207
+ * 大 bundle 流式路径:普通 bundle 直接从 ZIP entry 落盘后传入 native,
208
+ * 避免 old/new/restored 的整块 Buffer 副本。HBC 变换仍需 Buffer,因为
209
+ * T/T⁻¹ 当前是内存算法。native 已自校验的普通产物不再重复 patch;
210
+ * 自定义/变换路径仍保留 round-trip 校验。
130
211
  */
131
212
  async function buildStreamBundlePatch(
132
- originSource: Buffer,
133
- newSource: Buffer,
213
+ originSource: BundleSource,
214
+ newSource: BundleSource,
134
215
  options: BundleDiffOptions,
135
- ): Promise<{ patchData: Buffer; hbcTransform?: HbcTransformMeta }> {
216
+ workRoot: string,
217
+ ): Promise<BundlePatchResult> {
136
218
  const diffStreamFn = options.diffStreamFn;
137
219
  const patchStreamFn = options.patchStreamFn;
138
220
  if (!diffStreamFn || !patchStreamFn) {
@@ -141,37 +223,100 @@ async function buildStreamBundlePatch(
141
223
  );
142
224
  }
143
225
 
144
- const pair = options.hbcTransform
145
- ? tryTransformPair(originSource, newSource)
226
+ const tempRoot = fs.mkdtempSync(path.join(workRoot, 'stream-'));
227
+ const inputBytes =
228
+ bundleSourceSize(originSource) + bundleSourceSize(newSource);
229
+ const extractionDurationMs =
230
+ (originSource.kind === 'file' ? originSource.materializeDurationMs : 0) +
231
+ (newSource.kind === 'file' ? newSource.materializeDurationMs : 0);
232
+ let phaseStartedAt = performance.now();
233
+ const rawOldFile = await bundleSourceFile(
234
+ originSource,
235
+ path.join(tempRoot, 'old.bin'),
236
+ );
237
+ const rawNewFile = await bundleSourceFile(
238
+ newSource,
239
+ path.join(tempRoot, 'new.bin'),
240
+ );
241
+ const originBuffer = options.hbcTransform
242
+ ? await bundleSourceBuffer(originSource)
146
243
  : null;
147
- const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'rnu-stream-diff-'));
148
- try {
149
- const oldFile = path.join(tempRoot, 'old.bin');
150
- const newFile = path.join(tempRoot, 'new.bin');
151
- const patchFile = path.join(tempRoot, 'patch.bin');
152
- const restoredFile = path.join(tempRoot, 'restored.bin');
153
- fs.writeFileSync(oldFile, pair ? pair.tOld : originSource);
154
- fs.writeFileSync(newFile, pair ? pair.tNew : newSource);
244
+ const newBuffer = options.hbcTransform
245
+ ? await bundleSourceBuffer(newSource)
246
+ : null;
247
+ const pair =
248
+ originBuffer && newBuffer
249
+ ? tryTransformPair(originBuffer, newBuffer)
250
+ : null;
251
+ const oldFile = pair
252
+ ? path.join(tempRoot, 'old-transformed.bin')
253
+ : rawOldFile;
254
+ const newFile = pair
255
+ ? path.join(tempRoot, 'new-transformed.bin')
256
+ : rawNewFile;
257
+ const patchFile = path.join(tempRoot, 'patch.bin');
258
+
259
+ if (pair) {
260
+ await Promise.all([
261
+ fs.writeFile(oldFile, pair.tOld),
262
+ fs.writeFile(newFile, pair.tNew),
263
+ ]);
264
+ }
265
+ reportDiffPhase(options, {
266
+ phase: 'materialize',
267
+ durationMs: extractionDurationMs + performance.now() - phaseStartedAt,
268
+ inputBytes,
269
+ });
155
270
 
156
- await diffStreamFn(oldFile, newFile, patchFile);
271
+ phaseStartedAt = performance.now();
272
+ await diffStreamFn(oldFile, newFile, patchFile);
273
+ const patchBytes = (await fs.stat(patchFile)).size;
274
+ reportDiffPhase(options, {
275
+ phase: 'diff',
276
+ durationMs: performance.now() - phaseStartedAt,
277
+ inputBytes,
278
+ outputBytes: patchBytes,
279
+ });
157
280
 
158
- // round-trip 自检:patchStream 还原(变换域则再做 T⁻¹)必须与新 bundle 一致
281
+ // 变换路径必须验证 T⁻¹ 和元数据;未声明自校验的自定义 diff 也保留
282
+ // round-trip。node-hdiffpatch native 普通路径已经在返回前完整验证。
283
+ if (pair || !options.streamOutputVerified) {
284
+ phaseStartedAt = performance.now();
285
+ const restoredFile = path.join(tempRoot, 'restored.bin');
159
286
  await patchStreamFn(oldFile, patchFile, restoredFile);
160
- const restoredRaw: Buffer = fs.readFileSync(restoredFile);
161
- const restored = pair
162
- ? transformHbcWithLayout(restoredRaw, pair.layout, true)
163
- : restoredRaw;
164
- if (!restored || Buffer.compare(restored, newSource) !== 0) {
287
+ if (pair) {
288
+ const restoredRaw = await fs.readFile(restoredFile);
289
+ const restored = transformHbcWithLayout(restoredRaw, pair.layout, true);
290
+ if (
291
+ !restored ||
292
+ !newBuffer ||
293
+ Buffer.compare(restored, newBuffer) !== 0
294
+ ) {
295
+ throw new Error('stream diff round-trip verification failed');
296
+ }
297
+ } else if (!(await filesEqual(restoredFile, rawNewFile))) {
165
298
  throw new Error('stream diff round-trip verification failed');
166
299
  }
167
-
168
- return {
169
- patchData: fs.readFileSync(patchFile),
170
- ...(pair ? { hbcTransform: pair.meta } : {}),
171
- };
172
- } finally {
173
- fs.rmSync(tempRoot, { recursive: true, force: true });
300
+ reportDiffPhase(options, {
301
+ phase: 'verify',
302
+ durationMs: performance.now() - phaseStartedAt,
303
+ inputBytes,
304
+ outputBytes: patchBytes,
305
+ });
306
+ } else {
307
+ reportDiffPhase(options, {
308
+ phase: 'verify',
309
+ durationMs: 0,
310
+ inputBytes,
311
+ outputBytes: patchBytes,
312
+ skipped: true,
313
+ });
174
314
  }
315
+
316
+ return {
317
+ patch: { kind: 'file', path: patchFile },
318
+ ...(pair ? { hbcTransform: pair.meta } : {}),
319
+ };
175
320
  }
176
321
 
177
322
  /**
@@ -181,51 +326,61 @@ async function buildStreamBundlePatch(
181
326
  */
182
327
  async function buildBundlePatch(
183
328
  diffFn: Diff,
184
- originSource: Buffer | undefined,
185
- newSource: Buffer,
329
+ originSource: BundleSource | undefined,
330
+ newSource: BundleSource,
186
331
  options: BundleDiffOptions,
187
- ): Promise<{ patchData: Buffer; hbcTransform?: HbcTransformMeta }> {
332
+ workRoot: string,
333
+ ): Promise<BundlePatchResult> {
188
334
  if (
189
335
  options.streamThresholdBytes &&
190
336
  originSource &&
191
- Math.max(originSource.length, newSource.length) >=
337
+ Math.max(bundleSourceSize(originSource), bundleSourceSize(newSource)) >=
192
338
  options.streamThresholdBytes
193
339
  ) {
194
- return buildStreamBundlePatch(originSource, newSource, options);
340
+ return buildStreamBundlePatch(originSource, newSource, options, workRoot);
195
341
  }
196
342
 
197
- const baseline = await diffFn(originSource, newSource);
343
+ const [originBuffer, newBuffer] = await Promise.all([
344
+ originSource
345
+ ? bundleSourceBuffer(originSource)
346
+ : Promise.resolve(undefined),
347
+ bundleSourceBuffer(newSource),
348
+ ]);
349
+ const baseline = await diffFn(originBuffer, newBuffer);
198
350
  if (
199
351
  !options.hbcTransform ||
200
352
  !options.patchFn ||
201
- !originSource ||
353
+ !originBuffer ||
202
354
  baseline.length <
203
355
  (options.minBaselineBytes ?? HBC_TRANSFORM_MIN_BASELINE_BYTES)
204
356
  ) {
205
- return { patchData: baseline };
357
+ return { patch: { kind: 'buffer', data: baseline } };
206
358
  }
207
359
 
208
- const pair = tryTransformPair(originSource, newSource);
360
+ const pair = tryTransformPair(originBuffer, newBuffer);
209
361
  if (!pair) {
210
- return { patchData: baseline };
362
+ return { patch: { kind: 'buffer', data: baseline } };
211
363
  }
212
364
 
213
365
  try {
214
366
  const candidate = await diffFn(pair.tOld, pair.tNew);
215
367
  const metaOverhead = Buffer.byteLength(JSON.stringify(pair.meta));
216
368
  if (candidate.length + metaOverhead >= baseline.length) {
217
- return { patchData: baseline };
369
+ return { patch: { kind: 'buffer', data: baseline } };
218
370
  }
219
371
 
220
372
  const patched = options.patchFn(pair.tOld, candidate);
221
373
  const restored = transformHbcWithLayout(patched, pair.layout, true);
222
- if (!restored || Buffer.compare(restored, newSource) !== 0) {
374
+ if (!restored || Buffer.compare(restored, newBuffer) !== 0) {
223
375
  console.warn(t('hbcTransformRoundTripFailed'));
224
- return { patchData: baseline };
376
+ return { patch: { kind: 'buffer', data: baseline } };
225
377
  }
226
- return { patchData: candidate, hbcTransform: pair.meta };
378
+ return {
379
+ patch: { kind: 'buffer', data: candidate },
380
+ hbcTransform: pair.meta,
381
+ };
227
382
  } catch {
228
- return { patchData: baseline };
383
+ return { patch: { kind: 'buffer', data: baseline } };
229
384
  }
230
385
  }
231
386
 
@@ -234,22 +389,69 @@ async function addBundlePatch(
234
389
  entry: Entry,
235
390
  nextZipfile: YauzlZipFile,
236
391
  diffFn: Diff,
237
- originSource: Buffer | undefined,
392
+ originSource: BundleSource | undefined,
238
393
  bundleOptions: BundleDiffOptions,
239
394
  hbcTransformMetas: Record<string, HbcTransformMeta>,
395
+ workRoot: string,
240
396
  ) {
241
- const newSource = await readEntry(entry, nextZipfile);
242
- const { patchData, hbcTransform } = await buildBundlePatch(
397
+ const shouldStream =
398
+ !!bundleOptions.streamThresholdBytes &&
399
+ !!originSource &&
400
+ Math.max(bundleSourceSize(originSource), entry.uncompressedSize) >=
401
+ bundleOptions.streamThresholdBytes;
402
+ let newSource: BundleSource;
403
+ if (shouldStream) {
404
+ const nextRoot = fs.mkdtempSync(path.join(workRoot, 'next-'));
405
+ const nextPath = path.join(nextRoot, 'bundle.bin');
406
+ const startedAt = performance.now();
407
+ await writeEntry(entry, nextZipfile, nextPath);
408
+ newSource = {
409
+ kind: 'file',
410
+ path: nextPath,
411
+ size: entry.uncompressedSize,
412
+ materializeDurationMs: performance.now() - startedAt,
413
+ };
414
+ } else {
415
+ newSource = { kind: 'buffer', data: await readEntry(entry, nextZipfile) };
416
+ }
417
+
418
+ const { patch, hbcTransform } = await buildBundlePatch(
243
419
  diffFn,
244
420
  originSource,
245
421
  newSource,
246
422
  bundleOptions,
423
+ workRoot,
247
424
  );
248
425
  const patchEntryName = `${entry.fileName}.patch`;
249
426
  if (hbcTransform) {
250
427
  hbcTransformMetas[patchEntryName] = hbcTransform;
251
428
  }
252
- zipfile.addBuffer(patchData, patchEntryName, zipOptionsForPatchEntry());
429
+ if (patch.kind === 'file') {
430
+ zipfile.addFile(patch.path, patchEntryName, zipOptionsForPatchEntry());
431
+ } else {
432
+ zipfile.addBuffer(patch.data, patchEntryName, zipOptionsForPatchEntry());
433
+ }
434
+ }
435
+
436
+ async function readOriginBundleSource(
437
+ entry: Entry,
438
+ zipFile: YauzlZipFile,
439
+ bundleOptions: BundleDiffOptions,
440
+ workRoot: string,
441
+ ): Promise<BundleSource> {
442
+ if (!bundleOptions.streamThresholdBytes) {
443
+ return { kind: 'buffer', data: await readEntry(entry, zipFile) };
444
+ }
445
+ const originRoot = fs.mkdtempSync(path.join(workRoot, 'origin-'));
446
+ const originPath = path.join(originRoot, 'bundle.bin');
447
+ const startedAt = performance.now();
448
+ await writeEntry(entry, zipFile, originPath);
449
+ return {
450
+ kind: 'file',
451
+ path: originPath,
452
+ size: entry.uncompressedSize,
453
+ materializeDurationMs: performance.now() - startedAt,
454
+ };
253
455
  }
254
456
 
255
457
  async function addFileFromZipEntry(
@@ -303,12 +505,13 @@ async function diffFromPPK(
303
505
  next: string,
304
506
  output: string,
305
507
  diffFn: Diff,
306
- bundleOptions: BundleDiffOptions = {},
508
+ bundleOptions: BundleDiffOptions,
509
+ workRoot: string,
307
510
  ) {
308
511
  const originEntries: EntryMap = {};
309
512
  const originMap: CrcMap = {};
310
513
 
311
- let originSource: Buffer | undefined;
514
+ let originSource: BundleSource | undefined;
312
515
 
313
516
  await enumZipEntries(origin, async (entry, zipFile) => {
314
517
  originEntries[entry.fileName] = entry;
@@ -318,7 +521,12 @@ async function diffFromPPK(
318
521
 
319
522
  if (isPPKBundleFileName(entry.fileName)) {
320
523
  // This is source.
321
- originSource = await readEntry(entry, zipFile);
524
+ originSource = await readOriginBundleSource(
525
+ entry,
526
+ zipFile,
527
+ bundleOptions,
528
+ workRoot,
529
+ );
322
530
  }
323
531
  }
324
532
  });
@@ -366,6 +574,7 @@ async function diffFromPPK(
366
574
  originSource,
367
575
  bundleOptions,
368
576
  hbcTransformMetas,
577
+ workRoot,
369
578
  );
370
579
  } else {
371
580
  // If same file.
@@ -419,14 +628,14 @@ async function diffFromPackage(
419
628
  next: string,
420
629
  output: string,
421
630
  diffFn: Diff,
422
- originBundleName: string,
423
- transformPackagePath: (v: string) => string | undefined = (v: string) => v,
424
- bundleOptions: BundleDiffOptions = {},
631
+ platform: Platform,
632
+ bundleOptions: BundleDiffOptions,
633
+ workRoot: string,
425
634
  ) {
426
635
  const originEntries: Record<string, number> = {};
427
636
  const originMap: CrcMap = {};
428
637
 
429
- let originSource: Buffer | undefined;
638
+ let originSource: BundleSource | undefined;
430
639
 
431
640
  // Content checksum (CRC32) for entries that are copied from a *different*
432
641
  // path in the origin package ("moved" entries). On Android these are the
@@ -437,19 +646,25 @@ async function diffFromPackage(
437
646
 
438
647
  await enumZipEntries(origin, async (entry, zipFile) => {
439
648
  if (!/\/$/.test(entry.fileName)) {
440
- const fn = transformPackagePath(entry.fileName);
441
- if (!fn) {
649
+ const resolvedEntry = resolveNativePackageEntry(platform, entry.fileName);
650
+ if (!resolvedEntry) {
442
651
  return;
443
652
  }
653
+ const fn = resolvedEntry.diffPath;
444
654
 
445
655
  //console.log(fn);
446
656
  // isFile
447
657
  originEntries[fn] = entry.crc32;
448
658
  originMap[entry.crc32] = fn;
449
659
 
450
- if (fn === originBundleName) {
660
+ if (resolvedEntry.kind === 'bundle') {
451
661
  // This is source.
452
- originSource = await readEntry(entry, zipFile);
662
+ originSource = await readOriginBundleSource(
663
+ entry,
664
+ zipFile,
665
+ bundleOptions,
666
+ workRoot,
667
+ );
453
668
  }
454
669
  }
455
670
  });
@@ -476,6 +691,7 @@ async function diffFromPackage(
476
691
  originSource,
477
692
  bundleOptions,
478
693
  hbcTransformMetas,
694
+ workRoot,
479
695
  );
480
696
  } else {
481
697
  // If same file.
@@ -512,9 +728,12 @@ type DiffCommandOptions = {
512
728
  customPatch?: Patch;
513
729
  customDiffStream?: DiffStream;
514
730
  customPatchStream?: PatchStream;
731
+ customDiffStreamVerified?: boolean;
515
732
  customDiffSingleStream?: DiffStream;
516
733
  customPatchSingleStream?: PatchStream;
734
+ customDiffSingleStreamVerified?: boolean;
517
735
  customHdiffModule?: HdiffModule;
736
+ onDiffPhase?: BundleDiffOptions['onDiffPhase'];
518
737
  hbcTransform?: boolean;
519
738
  bundleStreamThreshold?: number;
520
739
  [key: string]: any;
@@ -553,7 +772,12 @@ function resolveBundleDiffOptions(
553
772
  | 'diffStreamFn'
554
773
  | 'patchStreamFn'
555
774
  | 'streamEmitsSingleFormat'
775
+ | 'streamOutputVerified'
556
776
  > = {};
777
+ const observerOptions =
778
+ typeof options.onDiffPhase === 'function'
779
+ ? { onDiffPhase: options.onDiffPhase }
780
+ : {};
557
781
  if (
558
782
  typeof options.bundleStreamThreshold === 'number' &&
559
783
  options.bundleStreamThreshold > 0
@@ -569,27 +793,34 @@ function resolveBundleDiffOptions(
569
793
  streamOptions.diffStreamFn = singleDiffStreamFn;
570
794
  streamOptions.patchStreamFn = singlePatchStreamFn;
571
795
  streamOptions.streamEmitsSingleFormat = true;
796
+ streamOptions.streamOutputVerified = options.customDiffSingleStream
797
+ ? options.customDiffSingleStreamVerified === true
798
+ : hdiffModule?.capabilities?.diffSingleStreamVerifiesOutput === true;
572
799
  } else if (diffStreamFn && patchStreamFn) {
573
800
  streamOptions.streamThresholdBytes = options.bundleStreamThreshold;
574
801
  streamOptions.diffStreamFn = diffStreamFn;
575
802
  streamOptions.patchStreamFn = patchStreamFn;
576
803
  streamOptions.streamEmitsSingleFormat = false;
804
+ streamOptions.streamOutputVerified = options.customDiffStream
805
+ ? options.customDiffStreamVerified === true
806
+ : hdiffModule?.capabilities?.diffStreamVerifiesOutput === true;
577
807
  } else {
578
808
  console.warn(t('bundleStreamNeedsHdiffpatch'));
579
809
  }
580
810
  }
581
811
 
582
812
  if (!options.hbcTransform) {
583
- return { ...streamOptions };
813
+ return { ...observerOptions, ...streamOptions };
584
814
  }
585
815
  const patchFn = resolvePatchImplementation(options);
586
816
  if (!patchFn) {
587
817
  console.warn(t('hbcTransformNeedsPatch'));
588
- return { ...streamOptions };
818
+ return { ...observerOptions, ...streamOptions };
589
819
  }
590
820
  return {
591
821
  hbcTransform: true,
592
822
  patchFn,
823
+ ...observerOptions,
593
824
  ...streamOptions,
594
825
  ...(typeof options.hbcTransformMinBaseline === 'number'
595
826
  ? { minBaselineBytes: options.hbcTransformMinBaseline }
@@ -625,11 +856,6 @@ function diffArgsCheck(
625
856
  };
626
857
  }
627
858
 
628
- const transformIpaPackagePath: PackagePathTransform = (v) => {
629
- const match = /^Payload\/[^/]+\/(.+)$/.exec(v);
630
- return match?.[1];
631
- };
632
-
633
859
  const createDiffCommand =
634
860
  ({ diffFnName, target }: DiffCommandConfig) =>
635
861
  async ({ args, options }: CommandContext) => {
@@ -642,18 +868,30 @@ const createDiffCommand =
642
868
  options as DiffCommandOptions,
643
869
  );
644
870
 
645
- if (target.kind === 'ppk') {
646
- await diffFromPPK(origin, next, realOutput, diffFn, bundleOptions);
647
- } else {
648
- await diffFromPackage(
649
- origin,
650
- next,
651
- realOutput,
652
- diffFn,
653
- target.originBundleName,
654
- target.transformPackagePath,
655
- bundleOptions,
656
- );
871
+ const workRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'rnu-bundle-diff-'));
872
+ try {
873
+ if (target.kind === 'ppk') {
874
+ await diffFromPPK(
875
+ origin,
876
+ next,
877
+ realOutput,
878
+ diffFn,
879
+ bundleOptions,
880
+ workRoot,
881
+ );
882
+ } else {
883
+ await diffFromPackage(
884
+ origin,
885
+ next,
886
+ realOutput,
887
+ diffFn,
888
+ target.platform,
889
+ bundleOptions,
890
+ workRoot,
891
+ );
892
+ }
893
+ } finally {
894
+ fs.rmSync(workRoot, { recursive: true, force: true });
657
895
  }
658
896
 
659
897
  console.log(t('diffPackageGenerated', { output: realOutput }));
@@ -668,22 +906,21 @@ export const diffCommands = {
668
906
  diffFnName: 'hdiffFromApk',
669
907
  target: {
670
908
  kind: 'package',
671
- originBundleName: 'assets/index.android.bundle',
909
+ platform: 'android',
672
910
  },
673
911
  }),
674
912
  hdiffFromApp: createDiffCommand({
675
913
  diffFnName: 'hdiffFromApp',
676
914
  target: {
677
915
  kind: 'package',
678
- originBundleName: 'resources/rawfile/bundle.harmony.js',
916
+ platform: 'harmony',
679
917
  },
680
918
  }),
681
919
  hdiffFromIpa: createDiffCommand({
682
920
  diffFnName: 'hdiffFromIpa',
683
921
  target: {
684
922
  kind: 'package',
685
- originBundleName: 'main.jsbundle',
686
- transformPackagePath: transformIpaPackagePath,
923
+ platform: 'ios',
687
924
  },
688
925
  }),
689
926
  };