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/lib/api.js +4 -1
- package/lib/diff.js +219 -67
- package/lib/native-package.d.ts +17 -0
- package/lib/native-package.js +232 -0
- package/lib/package.js +26 -17
- package/lib/utils/zip-entries.d.ts +1 -0
- package/lib/utils/zip-entries.js +18 -0
- package/package.json +3 -2
- package/src/api.ts +4 -1
- package/src/diff.ts +325 -88
- package/src/native-package.ts +248 -0
- package/src/package.ts +29 -19
- package/src/utils/zip-entries.ts +22 -0
package/lib/api.js
CHANGED
|
@@ -230,7 +230,10 @@ async function uploadFile(fn, key, appId) {
|
|
|
230
230
|
method: 'PUT',
|
|
231
231
|
body: fileStream,
|
|
232
232
|
// 预签名 PUT 不接受 chunked 传输,必须显式声明长度
|
|
233
|
-
headers: {
|
|
233
|
+
headers: {
|
|
234
|
+
'content-length': String(fileSize),
|
|
235
|
+
...(resp.headers || {}),
|
|
236
|
+
},
|
|
234
237
|
});
|
|
235
238
|
}
|
|
236
239
|
catch (error) {
|
package/lib/diff.js
CHANGED
|
@@ -37,11 +37,13 @@ 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
|
+
const node_crypto_1 = require("node:crypto");
|
|
40
41
|
const fs = __importStar(require("fs-extra"));
|
|
41
42
|
const global_dirs_1 = require("global-dirs");
|
|
42
43
|
const os_1 = __importDefault(require("os"));
|
|
43
44
|
const path_1 = __importDefault(require("path"));
|
|
44
45
|
const yazl_1 = require("yazl");
|
|
46
|
+
const native_package_1 = require("./native-package");
|
|
45
47
|
const utils_1 = require("./utils");
|
|
46
48
|
const constants_1 = require("./utils/constants");
|
|
47
49
|
const hbcTransform_1 = require("./utils/hbcTransform");
|
|
@@ -81,98 +83,236 @@ function createOutputZip(output) {
|
|
|
81
83
|
// baseline patch 小于该值时跳过变换尝试:节省一次 diff 的 CPU,
|
|
82
84
|
// 且此时变换收益上限(~25%)也抵不过元数据开销
|
|
83
85
|
const HBC_TRANSFORM_MIN_BASELINE_BYTES = 64 * 1024;
|
|
86
|
+
function reportDiffPhase(options, metric) {
|
|
87
|
+
try {
|
|
88
|
+
options.onDiffPhase?.(metric);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Observability must never break patch generation.
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const bundleSourceSize = (source) => source.kind === 'buffer' ? source.data.length : source.size;
|
|
95
|
+
const bundleSourceBuffer = async (source) => source.kind === 'buffer' ? source.data : fs.readFile(source.path);
|
|
96
|
+
async function bundleSourceFile(source, outputPath) {
|
|
97
|
+
if (source.kind === 'file') {
|
|
98
|
+
return source.path;
|
|
99
|
+
}
|
|
100
|
+
await fs.writeFile(outputPath, source.data);
|
|
101
|
+
return outputPath;
|
|
102
|
+
}
|
|
103
|
+
async function hashFile(filePath) {
|
|
104
|
+
const hash = (0, node_crypto_1.createHash)('sha256');
|
|
105
|
+
for await (const chunk of fs.createReadStream(filePath)) {
|
|
106
|
+
hash.update(chunk);
|
|
107
|
+
}
|
|
108
|
+
return hash.digest('hex');
|
|
109
|
+
}
|
|
110
|
+
async function filesEqual(leftPath, rightPath) {
|
|
111
|
+
const [leftStat, rightStat] = await Promise.all([
|
|
112
|
+
fs.stat(leftPath),
|
|
113
|
+
fs.stat(rightPath),
|
|
114
|
+
]);
|
|
115
|
+
if (leftStat.size !== rightStat.size) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
const [leftHash, rightHash] = await Promise.all([
|
|
119
|
+
hashFile(leftPath),
|
|
120
|
+
hashFile(rightPath),
|
|
121
|
+
]);
|
|
122
|
+
return leftHash === rightHash;
|
|
123
|
+
}
|
|
84
124
|
/**
|
|
85
|
-
* 大 bundle
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
125
|
+
* 大 bundle 流式路径:普通 bundle 直接从 ZIP entry 落盘后传入 native,
|
|
126
|
+
* 避免 old/new/restored 的整块 Buffer 副本。HBC 变换仍需 Buffer,因为
|
|
127
|
+
* T/T⁻¹ 当前是内存算法。native 已自校验的普通产物不再重复 patch;
|
|
128
|
+
* 自定义/变换路径仍保留 round-trip 校验。
|
|
89
129
|
*/
|
|
90
|
-
async function buildStreamBundlePatch(originSource, newSource, options) {
|
|
130
|
+
async function buildStreamBundlePatch(originSource, newSource, options, workRoot) {
|
|
91
131
|
const diffStreamFn = options.diffStreamFn;
|
|
92
132
|
const patchStreamFn = options.patchStreamFn;
|
|
93
133
|
if (!diffStreamFn || !patchStreamFn) {
|
|
94
134
|
throw new Error('stream diff requires diffStream/patchStream from node-hdiffpatch');
|
|
95
135
|
}
|
|
96
|
-
const
|
|
97
|
-
|
|
136
|
+
const tempRoot = fs.mkdtempSync(path_1.default.join(workRoot, 'stream-'));
|
|
137
|
+
const inputBytes = bundleSourceSize(originSource) + bundleSourceSize(newSource);
|
|
138
|
+
const extractionDurationMs = (originSource.kind === 'file' ? originSource.materializeDurationMs : 0) +
|
|
139
|
+
(newSource.kind === 'file' ? newSource.materializeDurationMs : 0);
|
|
140
|
+
let phaseStartedAt = performance.now();
|
|
141
|
+
const rawOldFile = await bundleSourceFile(originSource, path_1.default.join(tempRoot, 'old.bin'));
|
|
142
|
+
const rawNewFile = await bundleSourceFile(newSource, path_1.default.join(tempRoot, 'new.bin'));
|
|
143
|
+
const originBuffer = options.hbcTransform
|
|
144
|
+
? await bundleSourceBuffer(originSource)
|
|
98
145
|
: null;
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
146
|
+
const newBuffer = options.hbcTransform
|
|
147
|
+
? await bundleSourceBuffer(newSource)
|
|
148
|
+
: null;
|
|
149
|
+
const pair = originBuffer && newBuffer
|
|
150
|
+
? (0, hbcTransform_1.tryTransformPair)(originBuffer, newBuffer)
|
|
151
|
+
: null;
|
|
152
|
+
const oldFile = pair
|
|
153
|
+
? path_1.default.join(tempRoot, 'old-transformed.bin')
|
|
154
|
+
: rawOldFile;
|
|
155
|
+
const newFile = pair
|
|
156
|
+
? path_1.default.join(tempRoot, 'new-transformed.bin')
|
|
157
|
+
: rawNewFile;
|
|
158
|
+
const patchFile = path_1.default.join(tempRoot, 'patch.bin');
|
|
159
|
+
if (pair) {
|
|
160
|
+
await Promise.all([
|
|
161
|
+
fs.writeFile(oldFile, pair.tOld),
|
|
162
|
+
fs.writeFile(newFile, pair.tNew),
|
|
163
|
+
]);
|
|
164
|
+
}
|
|
165
|
+
reportDiffPhase(options, {
|
|
166
|
+
phase: 'materialize',
|
|
167
|
+
durationMs: extractionDurationMs + performance.now() - phaseStartedAt,
|
|
168
|
+
inputBytes,
|
|
169
|
+
});
|
|
170
|
+
phaseStartedAt = performance.now();
|
|
171
|
+
await diffStreamFn(oldFile, newFile, patchFile);
|
|
172
|
+
const patchBytes = (await fs.stat(patchFile)).size;
|
|
173
|
+
reportDiffPhase(options, {
|
|
174
|
+
phase: 'diff',
|
|
175
|
+
durationMs: performance.now() - phaseStartedAt,
|
|
176
|
+
inputBytes,
|
|
177
|
+
outputBytes: patchBytes,
|
|
178
|
+
});
|
|
179
|
+
// 变换路径必须验证 T⁻¹ 和元数据;未声明自校验的自定义 diff 也保留
|
|
180
|
+
// round-trip。node-hdiffpatch native 普通路径已经在返回前完整验证。
|
|
181
|
+
if (pair || !options.streamOutputVerified) {
|
|
182
|
+
phaseStartedAt = performance.now();
|
|
104
183
|
const restoredFile = path_1.default.join(tempRoot, 'restored.bin');
|
|
105
|
-
fs.writeFileSync(oldFile, pair ? pair.tOld : originSource);
|
|
106
|
-
fs.writeFileSync(newFile, pair ? pair.tNew : newSource);
|
|
107
|
-
await diffStreamFn(oldFile, newFile, patchFile);
|
|
108
|
-
// round-trip 自检:patchStream 还原(变换域则再做 T⁻¹)必须与新 bundle 一致
|
|
109
184
|
await patchStreamFn(oldFile, patchFile, restoredFile);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
185
|
+
if (pair) {
|
|
186
|
+
const restoredRaw = await fs.readFile(restoredFile);
|
|
187
|
+
const restored = (0, hbcTransform_1.transformHbcWithLayout)(restoredRaw, pair.layout, true);
|
|
188
|
+
if (!restored ||
|
|
189
|
+
!newBuffer ||
|
|
190
|
+
Buffer.compare(restored, newBuffer) !== 0) {
|
|
191
|
+
throw new Error('stream diff round-trip verification failed');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else if (!(await filesEqual(restoredFile, rawNewFile))) {
|
|
115
195
|
throw new Error('stream diff round-trip verification failed');
|
|
116
196
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
197
|
+
reportDiffPhase(options, {
|
|
198
|
+
phase: 'verify',
|
|
199
|
+
durationMs: performance.now() - phaseStartedAt,
|
|
200
|
+
inputBytes,
|
|
201
|
+
outputBytes: patchBytes,
|
|
202
|
+
});
|
|
121
203
|
}
|
|
122
|
-
|
|
123
|
-
|
|
204
|
+
else {
|
|
205
|
+
reportDiffPhase(options, {
|
|
206
|
+
phase: 'verify',
|
|
207
|
+
durationMs: 0,
|
|
208
|
+
inputBytes,
|
|
209
|
+
outputBytes: patchBytes,
|
|
210
|
+
skipped: true,
|
|
211
|
+
});
|
|
124
212
|
}
|
|
213
|
+
return {
|
|
214
|
+
patch: { kind: 'file', path: patchFile },
|
|
215
|
+
...(pair ? { hbcTransform: pair.meta } : {}),
|
|
216
|
+
};
|
|
125
217
|
}
|
|
126
218
|
/**
|
|
127
219
|
* 生成 bundle patch:默认现状路径;开启 hbcTransform 时对 Hermes bundle
|
|
128
220
|
* 做双候选择优(baseline vs 变换域 + 元数据开销),且变换候选必须通过
|
|
129
221
|
* 本地 round-trip 还原自检才会被采用——收益永不为负,未知格式天然安全。
|
|
130
222
|
*/
|
|
131
|
-
async function buildBundlePatch(diffFn, originSource, newSource, options) {
|
|
223
|
+
async function buildBundlePatch(diffFn, originSource, newSource, options, workRoot) {
|
|
132
224
|
if (options.streamThresholdBytes &&
|
|
133
225
|
originSource &&
|
|
134
|
-
Math.max(originSource
|
|
226
|
+
Math.max(bundleSourceSize(originSource), bundleSourceSize(newSource)) >=
|
|
135
227
|
options.streamThresholdBytes) {
|
|
136
|
-
return buildStreamBundlePatch(originSource, newSource, options);
|
|
228
|
+
return buildStreamBundlePatch(originSource, newSource, options, workRoot);
|
|
137
229
|
}
|
|
138
|
-
const
|
|
230
|
+
const [originBuffer, newBuffer] = await Promise.all([
|
|
231
|
+
originSource
|
|
232
|
+
? bundleSourceBuffer(originSource)
|
|
233
|
+
: Promise.resolve(undefined),
|
|
234
|
+
bundleSourceBuffer(newSource),
|
|
235
|
+
]);
|
|
236
|
+
const baseline = await diffFn(originBuffer, newBuffer);
|
|
139
237
|
if (!options.hbcTransform ||
|
|
140
238
|
!options.patchFn ||
|
|
141
|
-
!
|
|
239
|
+
!originBuffer ||
|
|
142
240
|
baseline.length <
|
|
143
241
|
(options.minBaselineBytes ?? HBC_TRANSFORM_MIN_BASELINE_BYTES)) {
|
|
144
|
-
return {
|
|
242
|
+
return { patch: { kind: 'buffer', data: baseline } };
|
|
145
243
|
}
|
|
146
|
-
const pair = (0, hbcTransform_1.tryTransformPair)(
|
|
244
|
+
const pair = (0, hbcTransform_1.tryTransformPair)(originBuffer, newBuffer);
|
|
147
245
|
if (!pair) {
|
|
148
|
-
return {
|
|
246
|
+
return { patch: { kind: 'buffer', data: baseline } };
|
|
149
247
|
}
|
|
150
248
|
try {
|
|
151
249
|
const candidate = await diffFn(pair.tOld, pair.tNew);
|
|
152
250
|
const metaOverhead = Buffer.byteLength(JSON.stringify(pair.meta));
|
|
153
251
|
if (candidate.length + metaOverhead >= baseline.length) {
|
|
154
|
-
return {
|
|
252
|
+
return { patch: { kind: 'buffer', data: baseline } };
|
|
155
253
|
}
|
|
156
254
|
const patched = options.patchFn(pair.tOld, candidate);
|
|
157
255
|
const restored = (0, hbcTransform_1.transformHbcWithLayout)(patched, pair.layout, true);
|
|
158
|
-
if (!restored || Buffer.compare(restored,
|
|
256
|
+
if (!restored || Buffer.compare(restored, newBuffer) !== 0) {
|
|
159
257
|
console.warn((0, i18n_1.t)('hbcTransformRoundTripFailed'));
|
|
160
|
-
return {
|
|
258
|
+
return { patch: { kind: 'buffer', data: baseline } };
|
|
161
259
|
}
|
|
162
|
-
return {
|
|
260
|
+
return {
|
|
261
|
+
patch: { kind: 'buffer', data: candidate },
|
|
262
|
+
hbcTransform: pair.meta,
|
|
263
|
+
};
|
|
163
264
|
}
|
|
164
265
|
catch {
|
|
165
|
-
return {
|
|
266
|
+
return { patch: { kind: 'buffer', data: baseline } };
|
|
166
267
|
}
|
|
167
268
|
}
|
|
168
|
-
async function addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas) {
|
|
169
|
-
const
|
|
170
|
-
|
|
269
|
+
async function addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas, workRoot) {
|
|
270
|
+
const shouldStream = !!bundleOptions.streamThresholdBytes &&
|
|
271
|
+
!!originSource &&
|
|
272
|
+
Math.max(bundleSourceSize(originSource), entry.uncompressedSize) >=
|
|
273
|
+
bundleOptions.streamThresholdBytes;
|
|
274
|
+
let newSource;
|
|
275
|
+
if (shouldStream) {
|
|
276
|
+
const nextRoot = fs.mkdtempSync(path_1.default.join(workRoot, 'next-'));
|
|
277
|
+
const nextPath = path_1.default.join(nextRoot, 'bundle.bin');
|
|
278
|
+
const startedAt = performance.now();
|
|
279
|
+
await (0, zip_entries_1.writeEntry)(entry, nextZipfile, nextPath);
|
|
280
|
+
newSource = {
|
|
281
|
+
kind: 'file',
|
|
282
|
+
path: nextPath,
|
|
283
|
+
size: entry.uncompressedSize,
|
|
284
|
+
materializeDurationMs: performance.now() - startedAt,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
newSource = { kind: 'buffer', data: await (0, zip_entries_1.readEntry)(entry, nextZipfile) };
|
|
289
|
+
}
|
|
290
|
+
const { patch, hbcTransform } = await buildBundlePatch(diffFn, originSource, newSource, bundleOptions, workRoot);
|
|
171
291
|
const patchEntryName = `${entry.fileName}.patch`;
|
|
172
292
|
if (hbcTransform) {
|
|
173
293
|
hbcTransformMetas[patchEntryName] = hbcTransform;
|
|
174
294
|
}
|
|
175
|
-
|
|
295
|
+
if (patch.kind === 'file') {
|
|
296
|
+
zipfile.addFile(patch.path, patchEntryName, (0, zip_options_1.zipOptionsForPatchEntry)());
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
zipfile.addBuffer(patch.data, patchEntryName, (0, zip_options_1.zipOptionsForPatchEntry)());
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async function readOriginBundleSource(entry, zipFile, bundleOptions, workRoot) {
|
|
303
|
+
if (!bundleOptions.streamThresholdBytes) {
|
|
304
|
+
return { kind: 'buffer', data: await (0, zip_entries_1.readEntry)(entry, zipFile) };
|
|
305
|
+
}
|
|
306
|
+
const originRoot = fs.mkdtempSync(path_1.default.join(workRoot, 'origin-'));
|
|
307
|
+
const originPath = path_1.default.join(originRoot, 'bundle.bin');
|
|
308
|
+
const startedAt = performance.now();
|
|
309
|
+
await (0, zip_entries_1.writeEntry)(entry, zipFile, originPath);
|
|
310
|
+
return {
|
|
311
|
+
kind: 'file',
|
|
312
|
+
path: originPath,
|
|
313
|
+
size: entry.uncompressedSize,
|
|
314
|
+
materializeDurationMs: performance.now() - startedAt,
|
|
315
|
+
};
|
|
176
316
|
}
|
|
177
317
|
async function addFileFromZipEntry(zipfile, entry, nextZipfile) {
|
|
178
318
|
const entryPrefix = await (0, zip_entries_1.readEntryPrefix)(entry, nextZipfile, zip_options_1.ZIP_ENTRY_SNIFF_BYTES);
|
|
@@ -198,7 +338,7 @@ function finishDiffZip(zipfile, writePromise, manifest) {
|
|
|
198
338
|
zipfile.end();
|
|
199
339
|
return writePromise;
|
|
200
340
|
}
|
|
201
|
-
async function diffFromPPK(origin, next, output, diffFn, bundleOptions
|
|
341
|
+
async function diffFromPPK(origin, next, output, diffFn, bundleOptions, workRoot) {
|
|
202
342
|
const originEntries = {};
|
|
203
343
|
const originMap = {};
|
|
204
344
|
let originSource;
|
|
@@ -209,7 +349,7 @@ async function diffFromPPK(origin, next, output, diffFn, bundleOptions = {}) {
|
|
|
209
349
|
originMap[entry.crc32] = entry.fileName;
|
|
210
350
|
if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
|
|
211
351
|
// This is source.
|
|
212
|
-
originSource = await (
|
|
352
|
+
originSource = await readOriginBundleSource(entry, zipFile, bundleOptions, workRoot);
|
|
213
353
|
}
|
|
214
354
|
}
|
|
215
355
|
});
|
|
@@ -242,7 +382,7 @@ async function diffFromPPK(origin, next, output, diffFn, bundleOptions = {}) {
|
|
|
242
382
|
}
|
|
243
383
|
}
|
|
244
384
|
else if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
|
|
245
|
-
await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas);
|
|
385
|
+
await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas, workRoot);
|
|
246
386
|
}
|
|
247
387
|
else {
|
|
248
388
|
// If same file.
|
|
@@ -284,7 +424,7 @@ async function diffFromPPK(origin, next, output, diffFn, bundleOptions = {}) {
|
|
|
284
424
|
: {}),
|
|
285
425
|
});
|
|
286
426
|
}
|
|
287
|
-
async function diffFromPackage(origin, next, output, diffFn,
|
|
427
|
+
async function diffFromPackage(origin, next, output, diffFn, platform, bundleOptions, workRoot) {
|
|
288
428
|
const originEntries = {};
|
|
289
429
|
const originMap = {};
|
|
290
430
|
let originSource;
|
|
@@ -296,17 +436,18 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
|
|
|
296
436
|
const copiesCrc = {};
|
|
297
437
|
await (0, zip_entries_1.enumZipEntries)(origin, async (entry, zipFile) => {
|
|
298
438
|
if (!/\/$/.test(entry.fileName)) {
|
|
299
|
-
const
|
|
300
|
-
if (!
|
|
439
|
+
const resolvedEntry = (0, native_package_1.resolveNativePackageEntry)(platform, entry.fileName);
|
|
440
|
+
if (!resolvedEntry) {
|
|
301
441
|
return;
|
|
302
442
|
}
|
|
443
|
+
const fn = resolvedEntry.diffPath;
|
|
303
444
|
//console.log(fn);
|
|
304
445
|
// isFile
|
|
305
446
|
originEntries[fn] = entry.crc32;
|
|
306
447
|
originMap[entry.crc32] = fn;
|
|
307
|
-
if (
|
|
448
|
+
if (resolvedEntry.kind === 'bundle') {
|
|
308
449
|
// This is source.
|
|
309
|
-
originSource = await (
|
|
450
|
+
originSource = await readOriginBundleSource(entry, zipFile, bundleOptions, workRoot);
|
|
310
451
|
}
|
|
311
452
|
}
|
|
312
453
|
});
|
|
@@ -322,7 +463,7 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
|
|
|
322
463
|
zipfile.addEmptyDirectory(entry.fileName);
|
|
323
464
|
}
|
|
324
465
|
else if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
|
|
325
|
-
await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas);
|
|
466
|
+
await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas, workRoot);
|
|
326
467
|
}
|
|
327
468
|
else {
|
|
328
469
|
// If same file.
|
|
@@ -372,6 +513,9 @@ function resolvePatchImplementation(options) {
|
|
|
372
513
|
function resolveBundleDiffOptions(options) {
|
|
373
514
|
const hdiffModule = options.customHdiffModule ?? hdiff;
|
|
374
515
|
const streamOptions = {};
|
|
516
|
+
const observerOptions = typeof options.onDiffPhase === 'function'
|
|
517
|
+
? { onDiffPhase: options.onDiffPhase }
|
|
518
|
+
: {};
|
|
375
519
|
if (typeof options.bundleStreamThreshold === 'number' &&
|
|
376
520
|
options.bundleStreamThreshold > 0) {
|
|
377
521
|
const singleDiffStreamFn = options.customDiffSingleStream ?? hdiffModule?.diffSingleStream;
|
|
@@ -383,28 +527,35 @@ function resolveBundleDiffOptions(options) {
|
|
|
383
527
|
streamOptions.diffStreamFn = singleDiffStreamFn;
|
|
384
528
|
streamOptions.patchStreamFn = singlePatchStreamFn;
|
|
385
529
|
streamOptions.streamEmitsSingleFormat = true;
|
|
530
|
+
streamOptions.streamOutputVerified = options.customDiffSingleStream
|
|
531
|
+
? options.customDiffSingleStreamVerified === true
|
|
532
|
+
: hdiffModule?.capabilities?.diffSingleStreamVerifiesOutput === true;
|
|
386
533
|
}
|
|
387
534
|
else if (diffStreamFn && patchStreamFn) {
|
|
388
535
|
streamOptions.streamThresholdBytes = options.bundleStreamThreshold;
|
|
389
536
|
streamOptions.diffStreamFn = diffStreamFn;
|
|
390
537
|
streamOptions.patchStreamFn = patchStreamFn;
|
|
391
538
|
streamOptions.streamEmitsSingleFormat = false;
|
|
539
|
+
streamOptions.streamOutputVerified = options.customDiffStream
|
|
540
|
+
? options.customDiffStreamVerified === true
|
|
541
|
+
: hdiffModule?.capabilities?.diffStreamVerifiesOutput === true;
|
|
392
542
|
}
|
|
393
543
|
else {
|
|
394
544
|
console.warn((0, i18n_1.t)('bundleStreamNeedsHdiffpatch'));
|
|
395
545
|
}
|
|
396
546
|
}
|
|
397
547
|
if (!options.hbcTransform) {
|
|
398
|
-
return { ...streamOptions };
|
|
548
|
+
return { ...observerOptions, ...streamOptions };
|
|
399
549
|
}
|
|
400
550
|
const patchFn = resolvePatchImplementation(options);
|
|
401
551
|
if (!patchFn) {
|
|
402
552
|
console.warn((0, i18n_1.t)('hbcTransformNeedsPatch'));
|
|
403
|
-
return { ...streamOptions };
|
|
553
|
+
return { ...observerOptions, ...streamOptions };
|
|
404
554
|
}
|
|
405
555
|
return {
|
|
406
556
|
hbcTransform: true,
|
|
407
557
|
patchFn,
|
|
558
|
+
...observerOptions,
|
|
408
559
|
...streamOptions,
|
|
409
560
|
...(typeof options.hbcTransformMinBaseline === 'number'
|
|
410
561
|
? { minBaselineBytes: options.hbcTransformMinBaseline }
|
|
@@ -431,18 +582,20 @@ function diffArgsCheck(args, options, diffFnName) {
|
|
|
431
582
|
realOutput: output.replace(/\$\{time\}/g, `${Date.now()}`),
|
|
432
583
|
};
|
|
433
584
|
}
|
|
434
|
-
const transformIpaPackagePath = (v) => {
|
|
435
|
-
const match = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
|
436
|
-
return match?.[1];
|
|
437
|
-
};
|
|
438
585
|
const createDiffCommand = ({ diffFnName, target }) => async ({ args, options }) => {
|
|
439
586
|
const { origin, next, realOutput, diffFn } = diffArgsCheck(args, options, diffFnName);
|
|
440
587
|
const bundleOptions = resolveBundleDiffOptions(options);
|
|
441
|
-
|
|
442
|
-
|
|
588
|
+
const workRoot = fs.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'rnu-bundle-diff-'));
|
|
589
|
+
try {
|
|
590
|
+
if (target.kind === 'ppk') {
|
|
591
|
+
await diffFromPPK(origin, next, realOutput, diffFn, bundleOptions, workRoot);
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
await diffFromPackage(origin, next, realOutput, diffFn, target.platform, bundleOptions, workRoot);
|
|
595
|
+
}
|
|
443
596
|
}
|
|
444
|
-
|
|
445
|
-
|
|
597
|
+
finally {
|
|
598
|
+
fs.rmSync(workRoot, { recursive: true, force: true });
|
|
446
599
|
}
|
|
447
600
|
console.log((0, i18n_1.t)('diffPackageGenerated', { output: realOutput }));
|
|
448
601
|
};
|
|
@@ -455,22 +608,21 @@ exports.diffCommands = {
|
|
|
455
608
|
diffFnName: 'hdiffFromApk',
|
|
456
609
|
target: {
|
|
457
610
|
kind: 'package',
|
|
458
|
-
|
|
611
|
+
platform: 'android',
|
|
459
612
|
},
|
|
460
613
|
}),
|
|
461
614
|
hdiffFromApp: createDiffCommand({
|
|
462
615
|
diffFnName: 'hdiffFromApp',
|
|
463
616
|
target: {
|
|
464
617
|
kind: 'package',
|
|
465
|
-
|
|
618
|
+
platform: 'harmony',
|
|
466
619
|
},
|
|
467
620
|
}),
|
|
468
621
|
hdiffFromIpa: createDiffCommand({
|
|
469
622
|
diffFnName: 'hdiffFromIpa',
|
|
470
623
|
target: {
|
|
471
624
|
kind: 'package',
|
|
472
|
-
|
|
473
|
-
transformPackagePath: transformIpaPackagePath,
|
|
625
|
+
platform: 'ios',
|
|
474
626
|
},
|
|
475
627
|
}),
|
|
476
628
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Platform } from './types';
|
|
2
|
+
export type NativePackageEntry = {
|
|
3
|
+
diffPath: string;
|
|
4
|
+
kind: 'bundle' | 'resource';
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Resolve an archive entry that can be used as a native-package diff origin.
|
|
8
|
+
* Upload extraction and diff indexing deliberately share this function so a
|
|
9
|
+
* file cannot be removed from the uploaded baseline while still being
|
|
10
|
+
* considered by the local diff implementation (or vice versa).
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveNativePackageEntry(platform: Platform, entryName: string): NativePackageEntry | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Repack a native package with only the bundle and resources required by
|
|
15
|
+
* package-origin diffs. Entry names and nested Harmony HAP structure are kept.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSlimNativePackage(source: string, output: string, platform: Platform): Promise<void>;
|