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