react-native-update-cli 2.9.3 → 2.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api.js +23 -9
- package/lib/app.d.ts +5 -1
- package/lib/app.js +23 -13
- package/lib/bundle-pack.js +2 -1
- package/lib/diff.js +98 -17
- package/lib/module-manager.js +0 -3
- package/lib/package.js +7 -3
- package/lib/utils/http-helper.js +1 -1
- package/lib/utils/zip-entries.d.ts +1 -0
- package/lib/utils/zip-entries.js +61 -0
- package/lib/utils/zip-options.d.ts +9 -0
- package/lib/utils/zip-options.js +272 -0
- package/lib/versions.js +12 -12
- package/package.json +1 -1
- package/src/api.ts +32 -9
- package/src/app.ts +24 -11
- package/src/bundle-pack.ts +6 -1
- package/src/diff.ts +209 -15
- package/src/module-manager.ts +0 -4
- package/src/package.ts +5 -4
- package/src/utils/http-helper.ts +1 -1
- package/src/utils/zip-entries.ts +69 -0
- package/src/utils/zip-options.ts +173 -0
- package/src/versions.ts +12 -12
package/lib/api.js
CHANGED
|
@@ -114,21 +114,30 @@ const closeSession = ()=>{
|
|
|
114
114
|
}
|
|
115
115
|
session = undefined;
|
|
116
116
|
};
|
|
117
|
+
function createRequestError(error, requestUrl) {
|
|
118
|
+
const message = typeof error === 'string' ? error : error instanceof Error ? error.message : String(error);
|
|
119
|
+
return new Error(`${message}\nURL: ${requestUrl}`);
|
|
120
|
+
}
|
|
117
121
|
async function query(url, options) {
|
|
118
122
|
const baseUrl = await _httphelper.getBaseUrl;
|
|
119
123
|
const fullUrl = `${baseUrl}${url}`;
|
|
120
|
-
|
|
124
|
+
let resp;
|
|
125
|
+
try {
|
|
126
|
+
resp = await (0, _nodefetch.default)(fullUrl, options);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
throw createRequestError(error, fullUrl);
|
|
129
|
+
}
|
|
121
130
|
const text = await resp.text();
|
|
122
131
|
let json;
|
|
123
132
|
try {
|
|
124
133
|
json = JSON.parse(text);
|
|
125
134
|
} catch (e) {}
|
|
126
135
|
if (resp.status !== 200) {
|
|
127
|
-
const message = (json == null ? void 0 : json.message) || resp.statusText
|
|
136
|
+
const message = (json == null ? void 0 : json.message) || resp.statusText || `HTTP ${resp.status}`;
|
|
128
137
|
if (resp.status === 401) {
|
|
129
|
-
throw
|
|
138
|
+
throw createRequestError((0, _i18n.t)('loginExpired'), fullUrl);
|
|
130
139
|
}
|
|
131
|
-
throw
|
|
140
|
+
throw createRequestError(message, fullUrl);
|
|
132
141
|
}
|
|
133
142
|
return json;
|
|
134
143
|
}
|
|
@@ -221,12 +230,17 @@ async function uploadFile(fn, key) {
|
|
|
221
230
|
// form.append('file', fileStream, {
|
|
222
231
|
// contentType: 'application/octet-stream',
|
|
223
232
|
// });
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
233
|
+
let res;
|
|
234
|
+
try {
|
|
235
|
+
res = await (0, _nodefetch.default)(realUrl, {
|
|
236
|
+
method: 'POST',
|
|
237
|
+
body: form
|
|
238
|
+
});
|
|
239
|
+
} catch (error) {
|
|
240
|
+
throw createRequestError(error, realUrl);
|
|
241
|
+
}
|
|
228
242
|
if (res.status > 299) {
|
|
229
|
-
throw
|
|
243
|
+
throw createRequestError(`${res.status}: ${res.statusText || 'Upload failed'}`, realUrl);
|
|
230
244
|
}
|
|
231
245
|
// const body = await response.json();
|
|
232
246
|
return {
|
package/lib/app.d.ts
CHANGED
|
@@ -6,7 +6,11 @@ interface AppSummary {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function getPlatform(platform?: string): Promise<Platform>;
|
|
8
8
|
export declare function assertPlatform(platform: string): Platform;
|
|
9
|
-
export declare function getSelectedApp(platform: Platform):
|
|
9
|
+
export declare function getSelectedApp(platform: Platform): Promise<{
|
|
10
|
+
appId: string;
|
|
11
|
+
appKey: string;
|
|
12
|
+
platform: Platform;
|
|
13
|
+
}>;
|
|
10
14
|
export declare function listApp(platform?: Platform | ''): Promise<AppSummary[]>;
|
|
11
15
|
export declare function chooseApp(platform: Platform): Promise<AppSummary>;
|
|
12
16
|
export declare const appCommands: {
|
package/lib/app.js
CHANGED
|
@@ -54,20 +54,30 @@ function assertPlatform(platform) {
|
|
|
54
54
|
}
|
|
55
55
|
return platform;
|
|
56
56
|
}
|
|
57
|
-
function getSelectedApp(platform) {
|
|
57
|
+
async function getSelectedApp(platform) {
|
|
58
58
|
assertPlatform(platform);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
let updateInfo = {};
|
|
60
|
+
try {
|
|
61
|
+
updateInfo = JSON.parse(await _fs.default.promises.readFile('update.json', 'utf8'));
|
|
62
|
+
} catch (e) {
|
|
63
|
+
if (e.code === 'ENOENT') {
|
|
64
|
+
throw new Error((0, _i18n.t)('appNotSelected', {
|
|
65
|
+
platform
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
throw e;
|
|
63
69
|
}
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
70
|
+
const info = updateInfo[platform];
|
|
71
|
+
if (!info) {
|
|
66
72
|
throw new Error((0, _i18n.t)('appNotSelected', {
|
|
67
73
|
platform
|
|
68
74
|
}));
|
|
69
75
|
}
|
|
70
|
-
return
|
|
76
|
+
return {
|
|
77
|
+
appId: String(info.appId),
|
|
78
|
+
appKey: info.appKey,
|
|
79
|
+
platform
|
|
80
|
+
};
|
|
71
81
|
}
|
|
72
82
|
async function listApp(platform = '') {
|
|
73
83
|
const { data } = await (0, _api.get)('/app/list');
|
|
@@ -148,10 +158,10 @@ const appCommands = {
|
|
|
148
158
|
const platform = await getPlatform(options.platform);
|
|
149
159
|
const id = args[0] ? Number.parseInt(args[0]) : (await chooseApp(platform)).id;
|
|
150
160
|
let updateInfo = {};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
161
|
+
try {
|
|
162
|
+
updateInfo = JSON.parse(await _fs.default.promises.readFile('update.json', 'utf8'));
|
|
163
|
+
} catch (e) {
|
|
164
|
+
if (e.code !== 'ENOENT') {
|
|
155
165
|
console.error((0, _i18n.t)('failedToParseUpdateJson'));
|
|
156
166
|
throw e;
|
|
157
167
|
}
|
|
@@ -161,6 +171,6 @@ const appCommands = {
|
|
|
161
171
|
appId: id,
|
|
162
172
|
appKey
|
|
163
173
|
};
|
|
164
|
-
_fs.default.
|
|
174
|
+
await _fs.default.promises.writeFile('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
|
|
165
175
|
}
|
|
166
176
|
};
|
package/lib/bundle-pack.js
CHANGED
|
@@ -12,6 +12,7 @@ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
|
12
12
|
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
13
13
|
const _yazl = require("yazl");
|
|
14
14
|
const _i18n = require("./utils/i18n");
|
|
15
|
+
const _zipoptions = require("./utils/zip-options");
|
|
15
16
|
function _interop_require_default(obj) {
|
|
16
17
|
return obj && obj.__esModule ? obj : {
|
|
17
18
|
default: obj
|
|
@@ -85,7 +86,7 @@ async function packBundle(dir, output) {
|
|
|
85
86
|
const fullPath = _path.default.join(root, name);
|
|
86
87
|
const stat = _fsextra.statSync(fullPath);
|
|
87
88
|
if (stat.isFile()) {
|
|
88
|
-
zipfile.addFile(fullPath, rel + name);
|
|
89
|
+
zipfile.addFile(fullPath, rel + name, (0, _zipoptions.zipOptionsForPayloadFile)(fullPath, rel + name));
|
|
89
90
|
} else if (stat.isDirectory()) {
|
|
90
91
|
addDirectory(fullPath, `${rel}${name}/`);
|
|
91
92
|
}
|
package/lib/diff.js
CHANGED
|
@@ -27,6 +27,7 @@ const _utils = require("./utils");
|
|
|
27
27
|
const _constants = require("./utils/constants");
|
|
28
28
|
const _i18n = require("./utils/i18n");
|
|
29
29
|
const _zipentries = require("./utils/zip-entries");
|
|
30
|
+
const _zipoptions = require("./utils/zip-options");
|
|
30
31
|
function _interop_require_default(obj) {
|
|
31
32
|
return obj && obj.__esModule ? obj : {
|
|
32
33
|
default: obj
|
|
@@ -73,7 +74,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
73
74
|
}
|
|
74
75
|
return newObj;
|
|
75
76
|
}
|
|
76
|
-
const
|
|
77
|
+
const loadModule = (pkgName)=>{
|
|
77
78
|
const resolvePaths = [
|
|
78
79
|
'.',
|
|
79
80
|
_globaldirs.npm.packages,
|
|
@@ -83,15 +84,90 @@ const loadDiffModule = (pkgName)=>{
|
|
|
83
84
|
const resolved = require.resolve(pkgName, {
|
|
84
85
|
paths: resolvePaths
|
|
85
86
|
});
|
|
86
|
-
|
|
87
|
-
if (mod == null ? void 0 : mod.diff) {
|
|
88
|
-
return mod.diff;
|
|
89
|
-
}
|
|
87
|
+
return require(resolved);
|
|
90
88
|
} catch (e) {}
|
|
91
89
|
return undefined;
|
|
92
90
|
};
|
|
93
|
-
const hdiff =
|
|
94
|
-
const bsdiff =
|
|
91
|
+
const hdiff = loadModule('node-hdiffpatch');
|
|
92
|
+
const bsdiff = loadModule('node-bsdiff');
|
|
93
|
+
const chiff = loadModule('@chiff/node');
|
|
94
|
+
// Structured covers are experimental and can be expensive on real Hermes input.
|
|
95
|
+
// Keep native hdiff as the default unless the server explicitly opts in.
|
|
96
|
+
function resolveChiffHpatchPolicy(policy) {
|
|
97
|
+
var _ref;
|
|
98
|
+
const value = String((_ref = policy != null ? policy : process.env.RNU_CHIFF_HPATCH_POLICY) != null ? _ref : 'off').toLowerCase();
|
|
99
|
+
if (value === 'costed' || value === 'on' || value === 'true' || value === '1') {
|
|
100
|
+
return 'costed';
|
|
101
|
+
}
|
|
102
|
+
return 'off';
|
|
103
|
+
}
|
|
104
|
+
function resolveChiffHpatchMinNativeBytes(value) {
|
|
105
|
+
var _ref;
|
|
106
|
+
const raw = (_ref = value != null ? value : process.env.RNU_CHIFF_HPATCH_MIN_NATIVE_BYTES) != null ? _ref : 4096;
|
|
107
|
+
const parsed = Number(raw);
|
|
108
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
109
|
+
return 4096;
|
|
110
|
+
}
|
|
111
|
+
return Math.floor(parsed);
|
|
112
|
+
}
|
|
113
|
+
function resolveChiffHpatchExactPolicy(policy) {
|
|
114
|
+
var _ref;
|
|
115
|
+
const value = String((_ref = policy != null ? policy : process.env.RNU_CHIFF_HPATCH_EXACT_COVERS) != null ? _ref : 'off').toLowerCase();
|
|
116
|
+
if (value === 'on' || value === 'true' || value === '1') {
|
|
117
|
+
return 'on';
|
|
118
|
+
}
|
|
119
|
+
return 'off';
|
|
120
|
+
}
|
|
121
|
+
function createChiffAwareHdiff(hdiffModule, chiffModule, policy, minNativeBytes, exactPolicy) {
|
|
122
|
+
const baseDiff = hdiffModule.diff;
|
|
123
|
+
if (!baseDiff) {
|
|
124
|
+
throw new Error((0, _i18n.t)('nodeHdiffpatchRequired', {
|
|
125
|
+
scriptName: _constants.scriptName
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
if (policy === 'off') {
|
|
129
|
+
return baseDiff;
|
|
130
|
+
}
|
|
131
|
+
return (oldSource, newSource)=>{
|
|
132
|
+
const nativeDiff = baseDiff(oldSource, newSource);
|
|
133
|
+
if (!oldSource || !newSource || !hdiffModule.diffWithCovers) {
|
|
134
|
+
return nativeDiff;
|
|
135
|
+
}
|
|
136
|
+
let bestDiff = nativeDiff;
|
|
137
|
+
const tryDiffWithCovers = (covers, mode)=>{
|
|
138
|
+
try {
|
|
139
|
+
const result = hdiffModule.diffWithCovers == null ? void 0 : hdiffModule.diffWithCovers.call(hdiffModule, oldSource, newSource, covers, {
|
|
140
|
+
mode
|
|
141
|
+
});
|
|
142
|
+
if (Buffer.isBuffer(result == null ? void 0 : result.diff) && result.diff.length < bestDiff.length) {
|
|
143
|
+
bestDiff = result.diff;
|
|
144
|
+
}
|
|
145
|
+
} catch (e) {}
|
|
146
|
+
};
|
|
147
|
+
tryDiffWithCovers([], 'native-coalesce');
|
|
148
|
+
if (nativeDiff.length < minNativeBytes) {
|
|
149
|
+
return bestDiff;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
var _chiffModule_hpatchApproximatePlanResult;
|
|
153
|
+
const approximatePlan = chiffModule == null ? void 0 : (_chiffModule_hpatchApproximatePlanResult = chiffModule.hpatchApproximatePlanResult) == null ? void 0 : _chiffModule_hpatchApproximatePlanResult.call(chiffModule, oldSource, newSource);
|
|
154
|
+
if (Array.isArray(approximatePlan == null ? void 0 : approximatePlan.covers)) {
|
|
155
|
+
tryDiffWithCovers(approximatePlan.covers, 'merge');
|
|
156
|
+
}
|
|
157
|
+
} catch (e) {}
|
|
158
|
+
if (exactPolicy === 'off' || !(chiffModule == null ? void 0 : chiffModule.hpatchCompatiblePlanResult)) {
|
|
159
|
+
return bestDiff;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
const plan = chiffModule.hpatchCompatiblePlanResult(oldSource, newSource);
|
|
163
|
+
if (Array.isArray(plan.covers)) {
|
|
164
|
+
tryDiffWithCovers(plan.covers, 'replace');
|
|
165
|
+
tryDiffWithCovers(plan.covers, 'merge');
|
|
166
|
+
}
|
|
167
|
+
} catch (e) {}
|
|
168
|
+
return bestDiff;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
95
171
|
function basename(fn) {
|
|
96
172
|
const m = /^(.+\/)[^\/]+\/?$/.exec(fn);
|
|
97
173
|
return m == null ? void 0 : m[1];
|
|
@@ -148,7 +224,7 @@ async function diffFromPPK(origin, next, output, diffFn) {
|
|
|
148
224
|
//console.log('Found bundle');
|
|
149
225
|
const newSource = await (0, _zipentries.readEntry)(entry, nextZipfile);
|
|
150
226
|
//console.log('Begin diff');
|
|
151
|
-
zipfile.addBuffer(diffFn(originSource, newSource), `${entry.fileName}.patch
|
|
227
|
+
zipfile.addBuffer(diffFn(originSource, newSource), `${entry.fileName}.patch`, (0, _zipoptions.zipOptionsForPatchEntry)());
|
|
152
228
|
//console.log('End diff');
|
|
153
229
|
} else {
|
|
154
230
|
// If same file.
|
|
@@ -172,6 +248,7 @@ async function diffFromPPK(origin, next, output, diffFn) {
|
|
|
172
248
|
if (basePath) {
|
|
173
249
|
addEntry(basePath);
|
|
174
250
|
}
|
|
251
|
+
const entryPrefix = await (0, _zipentries.readEntryPrefix)(entry, nextZipfile, _zipoptions.ZIP_ENTRY_SNIFF_BYTES);
|
|
175
252
|
await new Promise((resolve, reject)=>{
|
|
176
253
|
nextZipfile.openReadStream(entry, (err, readStream)=>{
|
|
177
254
|
if (err) {
|
|
@@ -180,7 +257,7 @@ async function diffFromPPK(origin, next, output, diffFn) {
|
|
|
180
257
|
if (!readStream) {
|
|
181
258
|
return reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
|
|
182
259
|
}
|
|
183
|
-
zipfile.addReadStream(readStream, entry.fileName);
|
|
260
|
+
zipfile.addReadStream(readStream, entry.fileName, (0, _zipoptions.zipOptionsForPayloadEntry)(entry.fileName, entryPrefix));
|
|
184
261
|
readStream.on('end', ()=>{
|
|
185
262
|
//console.log('add finished');
|
|
186
263
|
resolve(void 0);
|
|
@@ -202,7 +279,7 @@ async function diffFromPPK(origin, next, output, diffFn) {
|
|
|
202
279
|
zipfile.addBuffer(Buffer.from(JSON.stringify({
|
|
203
280
|
copies,
|
|
204
281
|
deletes
|
|
205
|
-
})), '__diff.json');
|
|
282
|
+
})), '__diff.json', (0, _zipoptions.zipOptionsForManifestEntry)());
|
|
206
283
|
zipfile.end();
|
|
207
284
|
await writePromise;
|
|
208
285
|
}
|
|
@@ -246,7 +323,7 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
|
|
|
246
323
|
//console.log('Found bundle');
|
|
247
324
|
const newSource = await (0, _zipentries.readEntry)(entry, nextZipfile);
|
|
248
325
|
//console.log('Begin diff');
|
|
249
|
-
zipfile.addBuffer(diffFn(originSource, newSource), `${entry.fileName}.patch
|
|
326
|
+
zipfile.addBuffer(diffFn(originSource, newSource), `${entry.fileName}.patch`, (0, _zipoptions.zipOptionsForPatchEntry)());
|
|
250
327
|
//console.log('End diff');
|
|
251
328
|
} else {
|
|
252
329
|
// If same file.
|
|
@@ -260,6 +337,7 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
|
|
|
260
337
|
copies[entry.fileName] = movedFrom;
|
|
261
338
|
return;
|
|
262
339
|
}
|
|
340
|
+
const entryPrefix = await (0, _zipentries.readEntryPrefix)(entry, nextZipfile, _zipoptions.ZIP_ENTRY_SNIFF_BYTES);
|
|
263
341
|
await new Promise((resolve, reject)=>{
|
|
264
342
|
nextZipfile.openReadStream(entry, (err, readStream)=>{
|
|
265
343
|
if (err) {
|
|
@@ -268,7 +346,7 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
|
|
|
268
346
|
if (!readStream) {
|
|
269
347
|
return reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
|
|
270
348
|
}
|
|
271
|
-
zipfile.addReadStream(readStream, entry.fileName);
|
|
349
|
+
zipfile.addReadStream(readStream, entry.fileName, (0, _zipoptions.zipOptionsForPayloadEntry)(entry.fileName, entryPrefix));
|
|
272
350
|
readStream.on('end', ()=>{
|
|
273
351
|
//console.log('add finished');
|
|
274
352
|
resolve(void 0);
|
|
@@ -279,7 +357,7 @@ async function diffFromPackage(origin, next, output, diffFn, originBundleName, t
|
|
|
279
357
|
});
|
|
280
358
|
zipfile.addBuffer(Buffer.from(JSON.stringify({
|
|
281
359
|
copies
|
|
282
|
-
})), '__diff.json');
|
|
360
|
+
})), '__diff.json', (0, _zipoptions.zipOptionsForManifestEntry)());
|
|
283
361
|
zipfile.end();
|
|
284
362
|
await writePromise;
|
|
285
363
|
}
|
|
@@ -288,19 +366,22 @@ function resolveDiffImplementation(useHdiff, options) {
|
|
|
288
366
|
return options.customDiff;
|
|
289
367
|
}
|
|
290
368
|
if (useHdiff) {
|
|
291
|
-
|
|
369
|
+
var _options_customHdiffModule;
|
|
370
|
+
const hdiffModule = (_options_customHdiffModule = options.customHdiffModule) != null ? _options_customHdiffModule : hdiff;
|
|
371
|
+
if (!(hdiffModule == null ? void 0 : hdiffModule.diff)) {
|
|
292
372
|
throw new Error((0, _i18n.t)('nodeHdiffpatchRequired', {
|
|
293
373
|
scriptName: _constants.scriptName
|
|
294
374
|
}));
|
|
295
375
|
}
|
|
296
|
-
|
|
376
|
+
var _options_customChiffModule;
|
|
377
|
+
return createChiffAwareHdiff(hdiffModule, (_options_customChiffModule = options.customChiffModule) != null ? _options_customChiffModule : chiff, resolveChiffHpatchPolicy(options.chiffHpatchPolicy), resolveChiffHpatchMinNativeBytes(options.chiffHpatchMinNativeBytes), resolveChiffHpatchExactPolicy(options.chiffHpatchExactCovers));
|
|
297
378
|
}
|
|
298
|
-
if (!bsdiff) {
|
|
379
|
+
if (!(bsdiff == null ? void 0 : bsdiff.diff)) {
|
|
299
380
|
throw new Error((0, _i18n.t)('nodeBsdiffRequired', {
|
|
300
381
|
scriptName: _constants.scriptName
|
|
301
382
|
}));
|
|
302
383
|
}
|
|
303
|
-
return bsdiff;
|
|
384
|
+
return bsdiff.diff;
|
|
304
385
|
}
|
|
305
386
|
function diffArgsCheck(args, options, diffFnName, useHdiff) {
|
|
306
387
|
const [origin, next] = args;
|
package/lib/module-manager.js
CHANGED
|
@@ -36,9 +36,6 @@ class ModuleManager {
|
|
|
36
36
|
if (module.init) {
|
|
37
37
|
module.init(this.provider);
|
|
38
38
|
}
|
|
39
|
-
// console.log(
|
|
40
|
-
// `Module '${module.name}' (v${module.version}) registered successfully`,
|
|
41
|
-
// );
|
|
42
39
|
}
|
|
43
40
|
unregisterModule(moduleName) {
|
|
44
41
|
const module = this.modules.get(moduleName);
|
package/lib/package.js
CHANGED
|
@@ -72,7 +72,7 @@ async function uploadNativePackage(filePath, options, config) {
|
|
|
72
72
|
const { versionName: extractedVersionName, buildTime } = info;
|
|
73
73
|
const { appId: appIdInPkg, appKey: appKeyInPkg } = info;
|
|
74
74
|
const { appId, appKey } = await (0, _app.getSelectedApp)(config.platform);
|
|
75
|
-
if (appIdInPkg && appIdInPkg
|
|
75
|
+
if (appIdInPkg && String(appIdInPkg) !== appId) {
|
|
76
76
|
throw new Error((0, _i18n.t)(config.appIdMismatchKey, {
|
|
77
77
|
appIdInPkg,
|
|
78
78
|
appId
|
|
@@ -151,9 +151,13 @@ async function listPackage(appId) {
|
|
|
151
151
|
}
|
|
152
152
|
async function choosePackage(appId) {
|
|
153
153
|
const list = await listPackage(appId);
|
|
154
|
+
const packageMap = new Map(list == null ? void 0 : list.map((v)=>[
|
|
155
|
+
v.id.toString(),
|
|
156
|
+
v
|
|
157
|
+
]));
|
|
154
158
|
while(true){
|
|
155
159
|
const id = await (0, _utils.question)((0, _i18n.t)('enterNativePackageId'));
|
|
156
|
-
const app =
|
|
160
|
+
const app = packageMap.get(id);
|
|
157
161
|
if (app) {
|
|
158
162
|
return app;
|
|
159
163
|
}
|
|
@@ -262,7 +266,7 @@ const packageCommands = {
|
|
|
262
266
|
packages: async ({ options })=>{
|
|
263
267
|
const platform = await (0, _app.getPlatform)(options.platform);
|
|
264
268
|
const { appId } = await (0, _app.getSelectedApp)(platform);
|
|
265
|
-
await listPackage(appId);
|
|
269
|
+
await listPackage(String(appId));
|
|
266
270
|
},
|
|
267
271
|
deletePackage: async ({ args, options })=>{
|
|
268
272
|
let { appId, packageId, packageVersion } = options;
|
package/lib/utils/http-helper.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type Entry, type ZipFile as YauzlZipFile } from 'yauzl';
|
|
2
2
|
export declare function readEntry(entry: Entry, zipFile: YauzlZipFile): Promise<Buffer>;
|
|
3
|
+
export declare function readEntryPrefix(entry: Entry, zipFile: YauzlZipFile, maxBytes: number): Promise<Buffer>;
|
|
3
4
|
export declare function enumZipEntries(zipFn: string, callback: (entry: Entry, zipFile: YauzlZipFile, nestedPath?: string) => Promise<any> | undefined, nestedPath?: string): Promise<unknown>;
|
package/lib/utils/zip-entries.js
CHANGED
|
@@ -14,6 +14,9 @@ _export(exports, {
|
|
|
14
14
|
},
|
|
15
15
|
readEntry: function() {
|
|
16
16
|
return readEntry;
|
|
17
|
+
},
|
|
18
|
+
readEntryPrefix: function() {
|
|
19
|
+
return readEntryPrefix;
|
|
17
20
|
}
|
|
18
21
|
});
|
|
19
22
|
const _os = /*#__PURE__*/ _interop_require_default(require("os"));
|
|
@@ -83,6 +86,64 @@ function readEntry(entry, zipFile) {
|
|
|
83
86
|
});
|
|
84
87
|
});
|
|
85
88
|
}
|
|
89
|
+
function readEntryPrefix(entry, zipFile, maxBytes) {
|
|
90
|
+
if (maxBytes <= 0) {
|
|
91
|
+
return Promise.resolve(Buffer.alloc(0));
|
|
92
|
+
}
|
|
93
|
+
const buffers = [];
|
|
94
|
+
let length = 0;
|
|
95
|
+
return new Promise((resolve, reject)=>{
|
|
96
|
+
zipFile.openReadStream(entry, (err, stream)=>{
|
|
97
|
+
if (err) {
|
|
98
|
+
return reject(err);
|
|
99
|
+
}
|
|
100
|
+
if (!stream) {
|
|
101
|
+
return reject(new Error(`Unable to read zip entry: ${entry.fileName}`));
|
|
102
|
+
}
|
|
103
|
+
let settled = false;
|
|
104
|
+
const cleanup = ()=>{
|
|
105
|
+
stream.off('data', onData);
|
|
106
|
+
stream.off('end', onEnd);
|
|
107
|
+
stream.off('error', onError);
|
|
108
|
+
};
|
|
109
|
+
const finish = ()=>{
|
|
110
|
+
if (settled) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
settled = true;
|
|
114
|
+
cleanup();
|
|
115
|
+
resolve(Buffer.concat(buffers, length));
|
|
116
|
+
};
|
|
117
|
+
const onData = (chunk)=>{
|
|
118
|
+
const remaining = maxBytes - length;
|
|
119
|
+
if (remaining <= 0) {
|
|
120
|
+
finish();
|
|
121
|
+
stream.destroy();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const slice = chunk.length > remaining ? chunk.subarray(0, remaining) : chunk;
|
|
125
|
+
buffers.push(slice);
|
|
126
|
+
length += slice.length;
|
|
127
|
+
if (length >= maxBytes) {
|
|
128
|
+
finish();
|
|
129
|
+
stream.destroy();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const onEnd = ()=>finish();
|
|
133
|
+
const onError = (error)=>{
|
|
134
|
+
if (settled) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
settled = true;
|
|
138
|
+
cleanup();
|
|
139
|
+
reject(error);
|
|
140
|
+
};
|
|
141
|
+
stream.on('data', onData);
|
|
142
|
+
stream.once('end', onEnd);
|
|
143
|
+
stream.once('error', onError);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
86
147
|
async function enumZipEntries(zipFn, callback, nestedPath = '') {
|
|
87
148
|
return new Promise((resolve, reject)=>{
|
|
88
149
|
(0, _yauzl.open)(zipFn, {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ZipEntryOptions = {
|
|
2
|
+
compress?: boolean;
|
|
3
|
+
compressionLevel?: number;
|
|
4
|
+
};
|
|
5
|
+
export declare const ZIP_ENTRY_SNIFF_BYTES = 64;
|
|
6
|
+
export declare function zipOptionsForPatchEntry(): ZipEntryOptions;
|
|
7
|
+
export declare function zipOptionsForManifestEntry(): ZipEntryOptions;
|
|
8
|
+
export declare function zipOptionsForPayloadEntry(fileName: string, prefix?: Buffer): ZipEntryOptions;
|
|
9
|
+
export declare function zipOptionsForPayloadFile(filePath: string, entryName?: string): ZipEntryOptions;
|