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.
- package/lib/api.d.ts +1 -1
- package/lib/api.js +140 -134
- package/lib/app.d.ts +2 -2
- package/lib/app.js +60 -107
- package/lib/bin.js +38 -35
- package/lib/bundle-pack.js +57 -77
- package/lib/bundle-runner.js +249 -312
- package/lib/bundle.js +71 -89
- package/lib/diff.js +188 -235
- package/lib/exports.js +14 -37
- package/lib/index.js +16 -17
- package/lib/install.js +24 -37
- package/lib/locales/en.js +3 -11
- package/lib/locales/zh.js +3 -11
- package/lib/package.js +164 -218
- package/lib/provider.js +85 -107
- package/lib/types.js +1 -3
- package/lib/user.d.ts +1 -1
- package/lib/user.js +26 -39
- package/lib/utils/add-gitignore.js +16 -29
- package/lib/utils/app-info-parser/aab.js +133 -157
- package/lib/utils/app-info-parser/apk.js +42 -39
- package/lib/utils/app-info-parser/app.js +5 -11
- package/lib/utils/app-info-parser/index.js +21 -31
- package/lib/utils/app-info-parser/ipa.js +35 -35
- package/lib/utils/app-info-parser/resource-finder.js +84 -71
- package/lib/utils/app-info-parser/utils.js +52 -77
- package/lib/utils/app-info-parser/xml-parser/binary.js +82 -90
- package/lib/utils/app-info-parser/xml-parser/manifest.js +88 -98
- package/lib/utils/app-info-parser/zip.js +43 -51
- package/lib/utils/check-lockfile.js +28 -37
- package/lib/utils/check-plugin.js +16 -32
- package/lib/utils/command-result.js +7 -20
- package/lib/utils/constants.js +23 -63
- package/lib/utils/dep-versions.js +21 -27
- package/lib/utils/git.js +20 -64
- package/lib/utils/hbcTransform.js +133 -246
- package/lib/utils/http-helper.js +33 -44
- package/lib/utils/i18n.js +17 -26
- package/lib/utils/index.js +137 -179
- package/lib/utils/latest-version/index.js +128 -137
- package/lib/utils/options.js +13 -34
- package/lib/utils/plugin-config.js +43 -56
- package/lib/utils/runtime.js +50 -108
- package/lib/utils/zip-entries.js +70 -97
- package/lib/utils/zip-options.js +80 -181
- package/lib/versions.js +231 -265
- package/package.json +19 -21
- package/src/api.ts +44 -3
- package/src/package.ts +1 -1
- package/src/user.ts +1 -1
- package/src/versions.ts +1 -1
package/lib/diff.js
CHANGED
|
@@ -1,115 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
}
|
|
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
|
|
68
|
+
return m?.[1];
|
|
99
69
|
}
|
|
100
70
|
function createOutputZip(output) {
|
|
101
|
-
|
|
102
|
-
const zipfile = new
|
|
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(
|
|
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
|
-
*/
|
|
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
|
|
129
|
-
|
|
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 =
|
|
132
|
-
const newFile =
|
|
133
|
-
const patchFile =
|
|
134
|
-
const restoredFile =
|
|
135
|
-
|
|
136
|
-
|
|
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 =
|
|
141
|
-
const restored = pair
|
|
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:
|
|
147
|
-
...pair ? {
|
|
148
|
-
hbcTransform: pair.meta
|
|
149
|
-
} : {}
|
|
118
|
+
patchData: fs.readFileSync(patchFile),
|
|
119
|
+
...(pair ? { hbcTransform: pair.meta } : {}),
|
|
150
120
|
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
*/
|
|
163
|
-
|
|
164
|
-
if (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 ||
|
|
169
|
-
|
|
170
|
-
|
|
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,
|
|
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,
|
|
157
|
+
const restored = (0, hbcTransform_1.transformHbcWithLayout)(patched, pair.layout, true);
|
|
189
158
|
if (!restored || Buffer.compare(restored, newSource) !== 0) {
|
|
190
|
-
console.warn((0,
|
|
191
|
-
return {
|
|
192
|
-
patchData: baseline
|
|
193
|
-
};
|
|
159
|
+
console.warn((0, i18n_1.t)('hbcTransformRoundTripFailed'));
|
|
160
|
+
return { patchData: baseline };
|
|
194
161
|
}
|
|
195
|
-
return {
|
|
196
|
-
|
|
197
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
210
|
+
if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
|
|
248
211
|
// This is source.
|
|
249
|
-
originSource = await (0,
|
|
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,
|
|
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,
|
|
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
|
-
}
|
|
243
|
+
}
|
|
244
|
+
else if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
|
|
281
245
|
await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas);
|
|
282
|
-
}
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
}
|
|
323
|
+
}
|
|
324
|
+
else if ((0, constants_1.isPPKBundleFileName)(entry.fileName)) {
|
|
361
325
|
await addBundlePatch(zipfile, entry, nextZipfile, diffFn, originSource, bundleOptions, hbcTransformMetas);
|
|
362
|
-
}
|
|
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 =
|
|
395
|
-
if (!
|
|
396
|
-
throw new Error((0,
|
|
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 =
|
|
409
|
-
return hdiffModule
|
|
369
|
+
const hdiffModule = options.customHdiffModule ?? hdiff;
|
|
370
|
+
return hdiffModule?.patch;
|
|
410
371
|
}
|
|
411
372
|
function resolveBundleDiffOptions(options) {
|
|
412
|
-
|
|
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' &&
|
|
416
|
-
|
|
417
|
-
const singleDiffStreamFn =
|
|
418
|
-
const singlePatchStreamFn =
|
|
419
|
-
const diffStreamFn =
|
|
420
|
-
const patchStreamFn =
|
|
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
|
-
}
|
|
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
|
-
}
|
|
432
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
420
|
+
const { output } = (0, utils_1.translateOptions)({
|
|
465
421
|
...options,
|
|
466
|
-
tempDir:
|
|
422
|
+
tempDir: constants_1.tempDir,
|
|
467
423
|
});
|
|
468
424
|
if (typeof output !== 'string') {
|
|
469
|
-
throw new Error((0,
|
|
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
|
|
436
|
+
return match?.[1];
|
|
481
437
|
};
|
|
482
|
-
const createDiffCommand = ({ diffFnName, target })=>async ({ args, options })=>{
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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
|
};
|