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