react-native-update-cli 2.17.0 → 2.19.0

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 (57) hide show
  1. package/lib/api.d.ts +1 -1
  2. package/lib/api.js +140 -134
  3. package/lib/app.d.ts +2 -2
  4. package/lib/app.js +60 -107
  5. package/lib/bin.js +38 -35
  6. package/lib/bundle-pack.js +57 -77
  7. package/lib/bundle-runner.js +249 -312
  8. package/lib/bundle.js +71 -89
  9. package/lib/diff.js +224 -198
  10. package/lib/exports.js +14 -37
  11. package/lib/index.js +16 -17
  12. package/lib/install.js +24 -37
  13. package/lib/locales/en.d.ts +1 -0
  14. package/lib/locales/en.js +4 -11
  15. package/lib/locales/zh.d.ts +1 -0
  16. package/lib/locales/zh.js +4 -11
  17. package/lib/package.js +164 -218
  18. package/lib/provider.js +85 -107
  19. package/lib/types.js +1 -3
  20. package/lib/user.d.ts +1 -1
  21. package/lib/user.js +26 -39
  22. package/lib/utils/add-gitignore.js +16 -29
  23. package/lib/utils/app-info-parser/aab.js +133 -157
  24. package/lib/utils/app-info-parser/apk.js +42 -39
  25. package/lib/utils/app-info-parser/app.js +5 -11
  26. package/lib/utils/app-info-parser/index.js +21 -31
  27. package/lib/utils/app-info-parser/ipa.js +35 -35
  28. package/lib/utils/app-info-parser/resource-finder.js +84 -71
  29. package/lib/utils/app-info-parser/utils.js +52 -77
  30. package/lib/utils/app-info-parser/xml-parser/binary.js +82 -90
  31. package/lib/utils/app-info-parser/xml-parser/manifest.js +88 -98
  32. package/lib/utils/app-info-parser/zip.js +43 -51
  33. package/lib/utils/check-lockfile.js +28 -37
  34. package/lib/utils/check-plugin.js +16 -32
  35. package/lib/utils/command-result.js +7 -20
  36. package/lib/utils/constants.js +23 -63
  37. package/lib/utils/dep-versions.js +21 -27
  38. package/lib/utils/git.js +20 -64
  39. package/lib/utils/hbcTransform.js +133 -246
  40. package/lib/utils/http-helper.js +33 -44
  41. package/lib/utils/i18n.js +17 -26
  42. package/lib/utils/index.js +137 -179
  43. package/lib/utils/latest-version/index.js +128 -137
  44. package/lib/utils/options.js +13 -34
  45. package/lib/utils/plugin-config.js +43 -56
  46. package/lib/utils/runtime.js +50 -108
  47. package/lib/utils/zip-entries.js +70 -97
  48. package/lib/utils/zip-options.js +80 -181
  49. package/lib/versions.js +231 -265
  50. package/package.json +19 -20
  51. package/src/api.ts +44 -3
  52. package/src/diff.ts +129 -2
  53. package/src/locales/en.ts +2 -0
  54. package/src/locales/zh.ts +2 -0
  55. package/src/package.ts +1 -1
  56. package/src/user.ts +1 -1
  57. package/src/versions.ts +1 -1
package/lib/diff.js CHANGED
@@ -1,184 +1,192 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get diffCommands () {
13
- return diffCommands;
14
- },
15
- get enumZipEntries () {
16
- return _zipentries.enumZipEntries;
17
- },
18
- get readEntry () {
19
- return _zipentries.readEntry;
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
7
  }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
21
17
  });
22
- const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
23
- const _globaldirs = require("global-dirs");
24
- const _path = /*#__PURE__*/ _interop_require_default(require("path"));
25
- const _yazl = require("yazl");
26
- const _utils = require("./utils");
27
- const _constants = require("./utils/constants");
28
- const _hbcTransform = require("./utils/hbcTransform");
29
- const _i18n = require("./utils/i18n");
30
- const _zipentries = require("./utils/zip-entries");
31
- const _zipoptions = require("./utils/zip-options");
32
- function _interop_require_default(obj) {
33
- return obj && obj.__esModule ? obj : {
34
- default: obj
35
- };
36
- }
37
- function _getRequireWildcardCache(nodeInterop) {
38
- if (typeof WeakMap !== "function") return null;
39
- var cacheBabelInterop = new WeakMap();
40
- var cacheNodeInterop = new WeakMap();
41
- return (_getRequireWildcardCache = function(nodeInterop) {
42
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
43
- })(nodeInterop);
44
- }
45
- function _interop_require_wildcard(obj, nodeInterop) {
46
- if (!nodeInterop && obj && obj.__esModule) {
47
- return obj;
48
- }
49
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
50
- return {
51
- default: obj
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
52
24
  };
53
- }
54
- var cache = _getRequireWildcardCache(nodeInterop);
55
- if (cache && cache.has(obj)) {
56
- return cache.get(obj);
57
- }
58
- var newObj = {
59
- __proto__: null
25
+ return ownKeys(o);
60
26
  };
61
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
62
- for(var key in obj){
63
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
64
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
65
- if (desc && (desc.get || desc.set)) {
66
- Object.defineProperty(newObj, key, desc);
67
- } else {
68
- newObj[key] = obj[key];
69
- }
70
- }
71
- }
72
- newObj.default = obj;
73
- if (cache) {
74
- cache.set(obj, newObj);
75
- }
76
- return newObj;
77
- }
78
- const loadModule = (pkgName)=>{
79
- const nodePathDirs = (process.env.NODE_PATH || '').split(_path.default.delimiter).filter(Boolean);
80
- const resolvePaths = [
81
- '.',
82
- ...nodePathDirs,
83
- _globaldirs.npm.packages,
84
- _globaldirs.yarn.packages
85
- ];
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.diffCommands = exports.readEntry = exports.enumZipEntries = void 0;
40
+ const fs = __importStar(require("fs-extra"));
41
+ const global_dirs_1 = require("global-dirs");
42
+ const os_1 = __importDefault(require("os"));
43
+ const path_1 = __importDefault(require("path"));
44
+ const yazl_1 = require("yazl");
45
+ const utils_1 = require("./utils");
46
+ const constants_1 = require("./utils/constants");
47
+ const hbcTransform_1 = require("./utils/hbcTransform");
48
+ const i18n_1 = require("./utils/i18n");
49
+ const zip_entries_1 = require("./utils/zip-entries");
50
+ Object.defineProperty(exports, "enumZipEntries", { enumerable: true, get: function () { return zip_entries_1.enumZipEntries; } });
51
+ Object.defineProperty(exports, "readEntry", { enumerable: true, get: function () { return zip_entries_1.readEntry; } });
52
+ const zip_options_1 = require("./utils/zip-options");
53
+ const loadModule = (pkgName) => {
54
+ const nodePathDirs = (process.env.NODE_PATH || '')
55
+ .split(path_1.default.delimiter)
56
+ .filter(Boolean);
57
+ const resolvePaths = ['.', ...nodePathDirs, global_dirs_1.npm.packages, global_dirs_1.yarn.packages];
86
58
  try {
87
- const resolved = require.resolve(pkgName, {
88
- paths: resolvePaths
89
- });
59
+ const resolved = require.resolve(pkgName, { paths: resolvePaths });
90
60
  return require(resolved);
91
- } catch (unused) {}
61
+ }
62
+ catch { }
92
63
  return undefined;
93
64
  };
94
65
  const hdiff = loadModule('node-hdiffpatch');
95
66
  function basename(fn) {
96
67
  const m = /^(.+\/)[^/]+\/?$/.exec(fn);
97
- return m == null ? void 0 : m[1];
68
+ return m?.[1];
98
69
  }
99
70
  function createOutputZip(output) {
100
- _fsextra.ensureDirSync(_path.default.dirname(output));
101
- const zipfile = new _yazl.ZipFile();
102
- const writePromise = new Promise((resolve, reject)=>{
71
+ fs.ensureDirSync(path_1.default.dirname(output));
72
+ const zipfile = new yazl_1.ZipFile();
73
+ const writePromise = new Promise((resolve, reject) => {
103
74
  zipfile.outputStream.on('error', reject);
104
- zipfile.outputStream.pipe(_fsextra.createWriteStream(output)).on('close', ()=>{
75
+ zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
105
76
  resolve(void 0);
106
77
  });
107
78
  });
108
- return {
109
- zipfile,
110
- writePromise
111
- };
79
+ return { zipfile, writePromise };
112
80
  }
113
81
  // baseline patch 小于该值时跳过变换尝试:节省一次 diff 的 CPU,
114
82
  // 且此时变换收益上限(~25%)也抵不过元数据开销
115
83
  const HBC_TRANSFORM_MIN_BASELINE_BYTES = 64 * 1024;
84
+ /**
85
+ * 大 bundle 流式路径:可选 HBC 变换(在 buffer 上做,写临时文件)后
86
+ * diffStream 生成 HDIFF13,并以 patchStream + T⁻¹ 做 round-trip 自检。
87
+ * 自检失败直接抛错(此路径没有 baseline 可回退——内存 diff 正是要避免的),
88
+ * 由上层按任务失败重试/告警处理。
89
+ */
90
+ async function buildStreamBundlePatch(originSource, newSource, options) {
91
+ const diffStreamFn = options.diffStreamFn;
92
+ const patchStreamFn = options.patchStreamFn;
93
+ if (!diffStreamFn || !patchStreamFn) {
94
+ throw new Error('stream diff requires diffStream/patchStream from node-hdiffpatch');
95
+ }
96
+ const pair = options.hbcTransform
97
+ ? (0, hbcTransform_1.tryTransformPair)(originSource, newSource)
98
+ : null;
99
+ const tempRoot = fs.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'rnu-stream-diff-'));
100
+ try {
101
+ const oldFile = path_1.default.join(tempRoot, 'old.bin');
102
+ const newFile = path_1.default.join(tempRoot, 'new.bin');
103
+ const patchFile = path_1.default.join(tempRoot, 'patch.bin');
104
+ 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
+ await patchStreamFn(oldFile, patchFile, restoredFile);
110
+ const restoredRaw = fs.readFileSync(restoredFile);
111
+ const restored = pair
112
+ ? (0, hbcTransform_1.transformHbcWithLayout)(restoredRaw, pair.layout, true)
113
+ : restoredRaw;
114
+ if (!restored || Buffer.compare(restored, newSource) !== 0) {
115
+ throw new Error('stream diff round-trip verification failed');
116
+ }
117
+ return {
118
+ patchData: fs.readFileSync(patchFile),
119
+ ...(pair ? { hbcTransform: pair.meta } : {}),
120
+ };
121
+ }
122
+ finally {
123
+ fs.rmSync(tempRoot, { recursive: true, force: true });
124
+ }
125
+ }
116
126
  /**
117
127
  * 生成 bundle patch:默认现状路径;开启 hbcTransform 时对 Hermes bundle
118
128
  * 做双候选择优(baseline vs 变换域 + 元数据开销),且变换候选必须通过
119
129
  * 本地 round-trip 还原自检才会被采用——收益永不为负,未知格式天然安全。
120
- */ async function buildBundlePatch(diffFn, originSource, newSource, options) {
121
- var _options_minBaselineBytes;
130
+ */
131
+ async function buildBundlePatch(diffFn, originSource, newSource, options) {
132
+ if (options.streamThresholdBytes &&
133
+ originSource &&
134
+ Math.max(originSource.length, newSource.length) >=
135
+ options.streamThresholdBytes) {
136
+ return buildStreamBundlePatch(originSource, newSource, options);
137
+ }
122
138
  const baseline = await diffFn(originSource, newSource);
123
- if (!options.hbcTransform || !options.patchFn || !originSource || baseline.length < ((_options_minBaselineBytes = options.minBaselineBytes) != null ? _options_minBaselineBytes : HBC_TRANSFORM_MIN_BASELINE_BYTES)) {
124
- return {
125
- patchData: baseline
126
- };
139
+ if (!options.hbcTransform ||
140
+ !options.patchFn ||
141
+ !originSource ||
142
+ baseline.length <
143
+ (options.minBaselineBytes ?? HBC_TRANSFORM_MIN_BASELINE_BYTES)) {
144
+ return { patchData: baseline };
127
145
  }
128
- const pair = (0, _hbcTransform.tryTransformPair)(originSource, newSource);
146
+ const pair = (0, hbcTransform_1.tryTransformPair)(originSource, newSource);
129
147
  if (!pair) {
130
- return {
131
- patchData: baseline
132
- };
148
+ return { patchData: baseline };
133
149
  }
134
150
  try {
135
151
  const candidate = await diffFn(pair.tOld, pair.tNew);
136
152
  const metaOverhead = Buffer.byteLength(JSON.stringify(pair.meta));
137
153
  if (candidate.length + metaOverhead >= baseline.length) {
138
- return {
139
- patchData: baseline
140
- };
154
+ return { patchData: baseline };
141
155
  }
142
156
  const patched = options.patchFn(pair.tOld, candidate);
143
- const restored = (0, _hbcTransform.transformHbcWithLayout)(patched, pair.layout, true);
157
+ const restored = (0, hbcTransform_1.transformHbcWithLayout)(patched, pair.layout, true);
144
158
  if (!restored || Buffer.compare(restored, newSource) !== 0) {
145
- console.warn((0, _i18n.t)('hbcTransformRoundTripFailed'));
146
- return {
147
- patchData: baseline
148
- };
159
+ console.warn((0, i18n_1.t)('hbcTransformRoundTripFailed'));
160
+ return { patchData: baseline };
149
161
  }
150
- return {
151
- patchData: candidate,
152
- hbcTransform: pair.meta
153
- };
154
- } catch (unused) {
155
- return {
156
- patchData: baseline
157
- };
162
+ return { patchData: candidate, hbcTransform: pair.meta };
163
+ }
164
+ catch {
165
+ return { patchData: baseline };
158
166
  }
159
167
  }
160
168
  async function addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas) {
161
- const newSource = await (0, _zipentries.readEntry)(entry, nextZipfile);
169
+ const newSource = await (0, zip_entries_1.readEntry)(entry, nextZipfile);
162
170
  const { patchData, hbcTransform } = await buildBundlePatch(diffFn, originSource, newSource, bundleOptions);
163
171
  const patchEntryName = `${entry.fileName}.patch`;
164
172
  if (hbcTransform) {
165
173
  hbcTransformMetas[patchEntryName] = hbcTransform;
166
174
  }
167
- zipfile.addBuffer(patchData, patchEntryName, (0, _zipoptions.zipOptionsForPatchEntry)());
175
+ zipfile.addBuffer(patchData, patchEntryName, (0, zip_options_1.zipOptionsForPatchEntry)());
168
176
  }
169
177
  async function addFileFromZipEntry(zipfile, entry, nextZipfile) {
170
- const entryPrefix = await (0, _zipentries.readEntryPrefix)(entry, nextZipfile, _zipoptions.ZIP_ENTRY_SNIFF_BYTES);
171
- await new Promise((resolve, reject)=>{
172
- nextZipfile.openReadStream(entry, (err, readStream)=>{
178
+ const entryPrefix = await (0, zip_entries_1.readEntryPrefix)(entry, nextZipfile, zip_options_1.ZIP_ENTRY_SNIFF_BYTES);
179
+ await new Promise((resolve, reject) => {
180
+ nextZipfile.openReadStream(entry, (err, readStream) => {
173
181
  if (err) {
174
182
  return reject(err);
175
183
  }
176
184
  if (!readStream) {
177
185
  return reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
178
186
  }
179
- zipfile.addReadStream(readStream, entry.fileName, (0, _zipoptions.zipOptionsForPayloadEntry)(entry.fileName, entryPrefix));
187
+ zipfile.addReadStream(readStream, entry.fileName, (0, zip_options_1.zipOptionsForPayloadEntry)(entry.fileName, entryPrefix));
180
188
  readStream.on('error', reject);
181
- readStream.on('end', ()=>{
189
+ readStream.on('end', () => {
182
190
  resolve(void 0);
183
191
  });
184
192
  });
@@ -186,7 +194,7 @@ async function addFileFromZipEntry(zipfile, entry, nextZipfile) {
186
194
  }
187
195
  function finishDiffZip(zipfile, writePromise, manifest) {
188
196
  const diffManifest = Buffer.from(JSON.stringify(manifest));
189
- zipfile.addBuffer(diffManifest, '__diff.json', (0, _zipoptions.zipOptionsForManifestEntry)(diffManifest.length));
197
+ zipfile.addBuffer(diffManifest, '__diff.json', (0, zip_options_1.zipOptionsForManifestEntry)(diffManifest.length));
190
198
  zipfile.end();
191
199
  return writePromise;
192
200
  }
@@ -194,19 +202,19 @@ async function diffFromPPK(origin, next, output, diffFn, bundleOptions = {}) {
194
202
  const originEntries = {};
195
203
  const originMap = {};
196
204
  let originSource;
197
- await (0, _zipentries.enumZipEntries)(origin, async (entry, zipFile)=>{
205
+ await (0, zip_entries_1.enumZipEntries)(origin, async (entry, zipFile) => {
198
206
  originEntries[entry.fileName] = entry;
199
207
  if (!/\/$/.test(entry.fileName)) {
200
208
  // isFile
201
209
  originMap[entry.crc32] = entry.fileName;
202
- if ((0, _constants.isPPKBundleFileName)(entry.fileName)) {
210
+ if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
203
211
  // This is source.
204
- originSource = await (0, _zipentries.readEntry)(entry, zipFile);
212
+ originSource = await (0, zip_entries_1.readEntry)(entry, zipFile);
205
213
  }
206
214
  }
207
215
  });
208
216
  if (!originSource) {
209
- throw new Error((0, _i18n.t)('bundleFileNotFound'));
217
+ throw new Error((0, i18n_1.t)('bundleFileNotFound'));
210
218
  }
211
219
  const copies = {};
212
220
  const { zipfile, writePromise } = createOutputZip(output);
@@ -225,16 +233,18 @@ async function diffFromPPK(origin, next, output, diffFn, bundleOptions = {}) {
225
233
  }
226
234
  const newEntries = {};
227
235
  const hbcTransformMetas = {};
228
- await (0, _zipentries.enumZipEntries)(next, async (entry, nextZipfile)=>{
236
+ await (0, zip_entries_1.enumZipEntries)(next, async (entry, nextZipfile) => {
229
237
  newEntries[entry.fileName] = entry;
230
238
  if (/\/$/.test(entry.fileName)) {
231
239
  // Directory
232
240
  if (!originEntries[entry.fileName]) {
233
241
  addEntry(entry.fileName);
234
242
  }
235
- } else if ((0, _constants.isPPKBundleFileName)(entry.fileName)) {
243
+ }
244
+ else if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
236
245
  await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas);
237
- } else {
246
+ }
247
+ else {
238
248
  // If same file.
239
249
  const originEntry = originEntries[entry.fileName];
240
250
  if (originEntry && originEntry.crc32 === entry.crc32) {
@@ -260,23 +270,21 @@ async function diffFromPPK(origin, next, output, diffFn, bundleOptions = {}) {
260
270
  }
261
271
  });
262
272
  const deletes = {};
263
- for(const k in originEntries){
273
+ for (const k in originEntries) {
264
274
  if (!newEntries[k]) {
265
- console.log((0, _i18n.t)('deleteFile', {
266
- file: k
267
- }));
275
+ console.log((0, i18n_1.t)('deleteFile', { file: k }));
268
276
  deletes[k] = 1;
269
277
  }
270
278
  }
271
279
  await finishDiffZip(zipfile, writePromise, {
272
280
  copies,
273
281
  deletes,
274
- ...Object.keys(hbcTransformMetas).length ? {
275
- hbcTransform: hbcTransformMetas
276
- } : {}
282
+ ...(Object.keys(hbcTransformMetas).length
283
+ ? { hbcTransform: hbcTransformMetas }
284
+ : {}),
277
285
  });
278
286
  }
279
- async function diffFromPackage(origin, next, output, diffFn, originBundleName, transformPackagePath = (v)=>v, bundleOptions = {}) {
287
+ async function diffFromPackage(origin, next, output, diffFn, originBundleName, transformPackagePath = (v) => v, bundleOptions = {}) {
280
288
  const originEntries = {};
281
289
  const originMap = {};
282
290
  let originSource;
@@ -286,7 +294,7 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
286
294
  // baseline and an AAB(split-apk) install due to resource path shortening,
287
295
  // so the client cannot locate them by path and must fall back to content.
288
296
  const copiesCrc = {};
289
- await (0, _zipentries.enumZipEntries)(origin, async (entry, zipFile)=>{
297
+ await (0, zip_entries_1.enumZipEntries)(origin, async (entry, zipFile) => {
290
298
  if (!/\/$/.test(entry.fileName)) {
291
299
  const fn = transformPackagePath(entry.fileName);
292
300
  if (!fn) {
@@ -298,23 +306,25 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
298
306
  originMap[entry.crc32] = fn;
299
307
  if (fn === originBundleName) {
300
308
  // This is source.
301
- originSource = await (0, _zipentries.readEntry)(entry, zipFile);
309
+ originSource = await (0, zip_entries_1.readEntry)(entry, zipFile);
302
310
  }
303
311
  }
304
312
  });
305
313
  if (!originSource) {
306
- throw new Error((0, _i18n.t)('bundleFileNotFound'));
314
+ throw new Error((0, i18n_1.t)('bundleFileNotFound'));
307
315
  }
308
316
  const copies = {};
309
317
  const { zipfile, writePromise } = createOutputZip(output);
310
318
  const hbcTransformMetas = {};
311
- await (0, _zipentries.enumZipEntries)(next, async (entry, nextZipfile)=>{
319
+ await (0, zip_entries_1.enumZipEntries)(next, async (entry, nextZipfile) => {
312
320
  if (/\/$/.test(entry.fileName)) {
313
321
  // Directory
314
322
  zipfile.addEmptyDirectory(entry.fileName);
315
- } else if ((0, _constants.isPPKBundleFileName)(entry.fileName)) {
323
+ }
324
+ else if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
316
325
  await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas);
317
- } else {
326
+ }
327
+ else {
318
328
  // If same file.
319
329
  if (originEntries[entry.fileName] === entry.crc32) {
320
330
  copies[entry.fileName] = '';
@@ -336,115 +346,131 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
336
346
  await finishDiffZip(zipfile, writePromise, {
337
347
  copies,
338
348
  copiesCrc,
339
- ...Object.keys(hbcTransformMetas).length ? {
340
- hbcTransform: hbcTransformMetas
341
- } : {}
349
+ ...(Object.keys(hbcTransformMetas).length
350
+ ? { hbcTransform: hbcTransformMetas }
351
+ : {}),
342
352
  });
343
353
  }
344
354
  function resolveDiffImplementation(options) {
345
- var _options_customHdiffModule;
346
355
  if (options.customDiff) {
347
356
  return options.customDiff;
348
357
  }
349
- const hdiffModule = (_options_customHdiffModule = options.customHdiffModule) != null ? _options_customHdiffModule : hdiff;
350
- if (!(hdiffModule == null ? void 0 : hdiffModule.diff)) {
351
- throw new Error((0, _i18n.t)('nodeHdiffpatchRequired', {
352
- scriptName: _constants.scriptName
353
- }));
358
+ const hdiffModule = options.customHdiffModule ?? hdiff;
359
+ if (!hdiffModule?.diff) {
360
+ throw new Error((0, i18n_1.t)('nodeHdiffpatchRequired', { scriptName: constants_1.scriptName }));
354
361
  }
355
362
  return hdiffModule.diff;
356
363
  }
357
364
  // round-trip 自检需要 patch 能力;拿不到时禁用变换(安全优先),不报错
358
365
  function resolvePatchImplementation(options) {
359
- var _options_customHdiffModule;
360
366
  if (options.customPatch) {
361
367
  return options.customPatch;
362
368
  }
363
- const hdiffModule = (_options_customHdiffModule = options.customHdiffModule) != null ? _options_customHdiffModule : hdiff;
364
- return hdiffModule == null ? void 0 : hdiffModule.patch;
369
+ const hdiffModule = options.customHdiffModule ?? hdiff;
370
+ return hdiffModule?.patch;
365
371
  }
366
372
  function resolveBundleDiffOptions(options) {
373
+ const hdiffModule = options.customHdiffModule ?? hdiff;
374
+ const streamOptions = {};
375
+ if (typeof options.bundleStreamThreshold === 'number' &&
376
+ options.bundleStreamThreshold > 0) {
377
+ const singleDiffStreamFn = options.customDiffSingleStream ?? hdiffModule?.diffSingleStream;
378
+ const singlePatchStreamFn = options.customPatchSingleStream ?? hdiffModule?.patchSingleStream;
379
+ const diffStreamFn = options.customDiffStream ?? hdiffModule?.diffStream;
380
+ const patchStreamFn = options.customPatchStream ?? hdiffModule?.patchStream;
381
+ if (singleDiffStreamFn && singlePatchStreamFn) {
382
+ streamOptions.streamThresholdBytes = options.bundleStreamThreshold;
383
+ streamOptions.diffStreamFn = singleDiffStreamFn;
384
+ streamOptions.patchStreamFn = singlePatchStreamFn;
385
+ streamOptions.streamEmitsSingleFormat = true;
386
+ }
387
+ else if (diffStreamFn && patchStreamFn) {
388
+ streamOptions.streamThresholdBytes = options.bundleStreamThreshold;
389
+ streamOptions.diffStreamFn = diffStreamFn;
390
+ streamOptions.patchStreamFn = patchStreamFn;
391
+ streamOptions.streamEmitsSingleFormat = false;
392
+ }
393
+ else {
394
+ console.warn((0, i18n_1.t)('bundleStreamNeedsHdiffpatch'));
395
+ }
396
+ }
367
397
  if (!options.hbcTransform) {
368
- return {};
398
+ return { ...streamOptions };
369
399
  }
370
400
  const patchFn = resolvePatchImplementation(options);
371
401
  if (!patchFn) {
372
- console.warn((0, _i18n.t)('hbcTransformNeedsPatch'));
373
- return {};
402
+ console.warn((0, i18n_1.t)('hbcTransformNeedsPatch'));
403
+ return { ...streamOptions };
374
404
  }
375
405
  return {
376
406
  hbcTransform: true,
377
407
  patchFn,
378
- ...typeof options.hbcTransformMinBaseline === 'number' ? {
379
- minBaselineBytes: options.hbcTransformMinBaseline
380
- } : {}
408
+ ...streamOptions,
409
+ ...(typeof options.hbcTransformMinBaseline === 'number'
410
+ ? { minBaselineBytes: options.hbcTransformMinBaseline }
411
+ : {}),
381
412
  };
382
413
  }
383
414
  function diffArgsCheck(args, options, diffFnName) {
384
415
  const [origin, next] = args;
385
416
  if (!origin || !next) {
386
- throw new Error((0, _i18n.t)('usageDiff', {
387
- command: diffFnName
388
- }));
417
+ throw new Error((0, i18n_1.t)('usageDiff', { command: diffFnName }));
389
418
  }
390
419
  const diffFn = resolveDiffImplementation(options);
391
- const { output } = (0, _utils.translateOptions)({
420
+ const { output } = (0, utils_1.translateOptions)({
392
421
  ...options,
393
- tempDir: _constants.tempDir
422
+ tempDir: constants_1.tempDir,
394
423
  });
395
424
  if (typeof output !== 'string') {
396
- throw new Error((0, _i18n.t)('outputPathRequired'));
425
+ throw new Error((0, i18n_1.t)('outputPathRequired'));
397
426
  }
398
427
  return {
399
428
  origin,
400
429
  next,
401
430
  diffFn,
402
- realOutput: output.replace(/\$\{time\}/g, `${Date.now()}`)
431
+ realOutput: output.replace(/\$\{time\}/g, `${Date.now()}`),
403
432
  };
404
433
  }
405
- const transformIpaPackagePath = (v)=>{
434
+ const transformIpaPackagePath = (v) => {
406
435
  const match = /^Payload\/[^/]+\/(.+)$/.exec(v);
407
- return match == null ? void 0 : match[1];
436
+ return match?.[1];
408
437
  };
409
- const createDiffCommand = ({ diffFnName, target })=>async ({ args, options })=>{
410
- const { origin, next, realOutput, diffFn } = diffArgsCheck(args, options, diffFnName);
411
- const bundleOptions = resolveBundleDiffOptions(options);
412
- if (target.kind === 'ppk') {
413
- await diffFromPPK(origin, next, realOutput, diffFn, bundleOptions);
414
- } else {
415
- await diffFromPackage(origin, next, realOutput, diffFn, target.originBundleName, target.transformPackagePath, bundleOptions);
416
- }
417
- console.log((0, _i18n.t)('diffPackageGenerated', {
418
- output: realOutput
419
- }));
420
- };
421
- const diffCommands = {
438
+ const createDiffCommand = ({ diffFnName, target }) => async ({ args, options }) => {
439
+ const { origin, next, realOutput, diffFn } = diffArgsCheck(args, options, diffFnName);
440
+ const bundleOptions = resolveBundleDiffOptions(options);
441
+ if (target.kind === 'ppk') {
442
+ await diffFromPPK(origin, next, realOutput, diffFn, bundleOptions);
443
+ }
444
+ else {
445
+ await diffFromPackage(origin, next, realOutput, diffFn, target.originBundleName, target.transformPackagePath, bundleOptions);
446
+ }
447
+ console.log((0, i18n_1.t)('diffPackageGenerated', { output: realOutput }));
448
+ };
449
+ exports.diffCommands = {
422
450
  hdiff: createDiffCommand({
423
451
  diffFnName: 'hdiff',
424
- target: {
425
- kind: 'ppk'
426
- }
452
+ target: { kind: 'ppk' },
427
453
  }),
428
454
  hdiffFromApk: createDiffCommand({
429
455
  diffFnName: 'hdiffFromApk',
430
456
  target: {
431
457
  kind: 'package',
432
- originBundleName: 'assets/index.android.bundle'
433
- }
458
+ originBundleName: 'assets/index.android.bundle',
459
+ },
434
460
  }),
435
461
  hdiffFromApp: createDiffCommand({
436
462
  diffFnName: 'hdiffFromApp',
437
463
  target: {
438
464
  kind: 'package',
439
- originBundleName: 'resources/rawfile/bundle.harmony.js'
440
- }
465
+ originBundleName: 'resources/rawfile/bundle.harmony.js',
466
+ },
441
467
  }),
442
468
  hdiffFromIpa: createDiffCommand({
443
469
  diffFnName: 'hdiffFromIpa',
444
470
  target: {
445
471
  kind: 'package',
446
472
  originBundleName: 'main.jsbundle',
447
- transformPackagePath: transformIpaPackagePath
448
- }
449
- })
473
+ transformPackagePath: transformIpaPackagePath,
474
+ },
475
+ }),
450
476
  };