react-native-update-cli 2.15.3 → 2.16.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.js +25 -4
- package/lib/app.js +1 -0
- package/lib/bin.js +3 -1
- package/lib/bundle-pack.d.ts +1 -1
- package/lib/bundle-pack.js +8 -7
- package/lib/bundle-runner.js +58 -39
- package/lib/bundle.d.ts +26 -0
- package/lib/bundle.js +18 -6
- package/lib/diff.js +53 -72
- package/lib/locales/en.d.ts +11 -0
- package/lib/locales/en.js +12 -1
- package/lib/locales/zh.d.ts +11 -0
- package/lib/locales/zh.js +12 -1
- package/lib/package.js +3 -1
- package/lib/provider.js +9 -3
- package/lib/types.d.ts +2 -2
- package/lib/utils/app-info-parser/xml-parser/binary.js +4 -3
- package/lib/utils/app-info-parser/zip.d.ts +6 -0
- package/lib/utils/app-info-parser/zip.js +20 -5
- package/lib/utils/check-lockfile.js +5 -1
- package/lib/utils/http-helper.js +20 -23
- package/lib/utils/index.js +48 -20
- package/lib/versions.js +7 -5
- package/package.json +1 -1
- package/src/api.ts +30 -5
- package/src/app.ts +1 -0
- package/src/bin.ts +1 -1
- package/src/bundle-pack.ts +12 -7
- package/src/bundle-runner.ts +66 -43
- package/src/bundle.ts +13 -8
- package/src/diff.ts +87 -111
- package/src/locales/en.ts +13 -0
- package/src/locales/zh.ts +12 -0
- package/src/package.ts +1 -1
- package/src/provider.ts +7 -3
- package/src/types.ts +3 -2
- package/src/utils/app-info-parser/xml-parser/binary.ts +4 -5
- package/src/utils/app-info-parser/zip.ts +22 -5
- package/src/utils/check-lockfile.ts +5 -1
- package/src/utils/http-helper.ts +16 -23
- package/src/utils/index.ts +51 -36
- package/src/versions.ts +5 -5
|
@@ -37,20 +37,33 @@ export class Zip {
|
|
|
37
37
|
async getEntryFromHarmonyApp(
|
|
38
38
|
regex: RegExp,
|
|
39
39
|
): Promise<Buffer | Blob | undefined> {
|
|
40
|
+
return (await this.getEntriesFromHarmonyApp([regex]))[0];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Read multiple entries in a single pass over the archive (including
|
|
45
|
+
* nested .hap extraction), instead of one full scan per entry.
|
|
46
|
+
* Returns buffers in the same order as the given regexps.
|
|
47
|
+
*/
|
|
48
|
+
async getEntriesFromHarmonyApp(
|
|
49
|
+
regexps: RegExp[],
|
|
50
|
+
): Promise<(Buffer | undefined)[]> {
|
|
51
|
+
const results: (Buffer | undefined)[] = new Array(regexps.length);
|
|
40
52
|
try {
|
|
41
|
-
let originSource: Buffer | Blob | undefined;
|
|
42
53
|
if (typeof this.file !== 'string') {
|
|
43
54
|
throw new Error('Param error: [file] must be file path in Node.');
|
|
44
55
|
}
|
|
45
56
|
await enumZipEntries(this.file, async (entry, zipFile) => {
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
for (let i = 0; i < regexps.length; i++) {
|
|
58
|
+
if (regexps[i].test(entry.fileName)) {
|
|
59
|
+
results[i] = await readEntry(entry, zipFile);
|
|
60
|
+
}
|
|
48
61
|
}
|
|
49
62
|
});
|
|
50
|
-
return originSource;
|
|
51
63
|
} catch (error) {
|
|
52
|
-
console.error('Error in
|
|
64
|
+
console.error('Error in getEntriesFromHarmonyApp:', error);
|
|
53
65
|
}
|
|
66
|
+
return results;
|
|
54
67
|
}
|
|
55
68
|
|
|
56
69
|
private async readEntries(
|
|
@@ -74,6 +87,10 @@ export class Zip {
|
|
|
74
87
|
return pattern === entryName || pattern === lowerEntryName;
|
|
75
88
|
}
|
|
76
89
|
pattern.lastIndex = 0;
|
|
90
|
+
if (pattern.test(entryName)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
pattern.lastIndex = 0;
|
|
77
94
|
return pattern.test(lowerEntryName);
|
|
78
95
|
});
|
|
79
96
|
|
|
@@ -10,8 +10,12 @@ const lockFiles = [
|
|
|
10
10
|
'bun.lock',
|
|
11
11
|
];
|
|
12
12
|
|
|
13
|
-
// Function to check if a
|
|
13
|
+
// Function to check if a directory is a monorepo root
|
|
14
|
+
// (package.json workspaces field, or pnpm-workspace.yaml)
|
|
14
15
|
function hasWorkspaces(dir: string): boolean {
|
|
16
|
+
if (fs.existsSync(path.join(dir, 'pnpm-workspace.yaml'))) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
15
19
|
const pkgPath = path.join(dir, 'package.json');
|
|
16
20
|
if (fs.existsSync(pkgPath)) {
|
|
17
21
|
try {
|
package/src/utils/http-helper.ts
CHANGED
|
@@ -23,34 +23,27 @@ export function promiseAny<T>(promises: Promise<T>[]) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export const ping = async (url: string) => {
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.then(({ status }) => {
|
|
32
|
-
pingFinished = true;
|
|
26
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
27
|
+
try {
|
|
28
|
+
return await (Promise.race([
|
|
29
|
+
runtimeFetch(url, {
|
|
30
|
+
method: 'HEAD',
|
|
31
|
+
}).then(({ status }) => {
|
|
33
32
|
if (status === 200) {
|
|
34
|
-
// console.log('ping success', url);
|
|
35
33
|
return url;
|
|
36
34
|
}
|
|
37
|
-
// console.log('ping failed', url, status, statusText);
|
|
38
35
|
throw new Error('ping failed');
|
|
39
|
-
})
|
|
40
|
-
.catch((_e) => {
|
|
41
|
-
pingFinished = true;
|
|
42
|
-
// console.log('ping error', url, e);
|
|
43
|
-
throw new Error('ping error');
|
|
44
36
|
}),
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
new Promise((_, reject) => {
|
|
38
|
+
timer = setTimeout(() => {
|
|
39
|
+
reject(new Error('ping timeout'));
|
|
40
|
+
}, 5000);
|
|
41
|
+
}),
|
|
42
|
+
]) as Promise<string | null>);
|
|
43
|
+
} finally {
|
|
44
|
+
// clear the timer so it doesn't keep the process alive for 5s
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
}
|
|
54
47
|
};
|
|
55
48
|
|
|
56
49
|
export const testUrls = async (urls?: string[]) => {
|
package/src/utils/index.ts
CHANGED
|
@@ -139,11 +139,17 @@ export function translateOptions<T extends Record<string, unknown>>(
|
|
|
139
139
|
return result as T;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
const ApkBundleFileName = /assets\/index.android.bundle/;
|
|
143
|
+
const ApkUpdateJsonName = /res\/raw\/update.json/;
|
|
144
|
+
|
|
142
145
|
export async function getApkInfo(fn: string) {
|
|
143
146
|
const appInfoParser = new AppInfoParser(fn);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
// read both entries in a single scan over the archive
|
|
148
|
+
const entries = await appInfoParser.parser.getEntries([
|
|
149
|
+
ApkBundleFileName,
|
|
150
|
+
ApkUpdateJsonName,
|
|
151
|
+
]);
|
|
152
|
+
const bundleFile = entries[String(ApkBundleFileName)];
|
|
147
153
|
if (!bundleFile) {
|
|
148
154
|
throw new Error(
|
|
149
155
|
t('bundleNotFound', {
|
|
@@ -152,9 +158,7 @@ export async function getApkInfo(fn: string) {
|
|
|
152
158
|
}),
|
|
153
159
|
);
|
|
154
160
|
}
|
|
155
|
-
const updateJsonFile =
|
|
156
|
-
/res\/raw\/update.json/,
|
|
157
|
-
);
|
|
161
|
+
const updateJsonFile = entries[String(ApkUpdateJsonName)];
|
|
158
162
|
let appCredential = {};
|
|
159
163
|
if (updateJsonFile) {
|
|
160
164
|
appCredential = JSON.parse(updateJsonFile.toString()).android;
|
|
@@ -174,7 +178,7 @@ export async function getApkInfo(fn: string) {
|
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
}
|
|
177
|
-
if (buildTime
|
|
181
|
+
if (!Number.isFinite(buildTime) || buildTime === 0) {
|
|
178
182
|
throw new Error(t('buildTimeNotFound'));
|
|
179
183
|
}
|
|
180
184
|
return { versionName, buildTime, ...appCredential };
|
|
@@ -182,9 +186,13 @@ export async function getApkInfo(fn: string) {
|
|
|
182
186
|
|
|
183
187
|
export async function getAppInfo(fn: string) {
|
|
184
188
|
const appInfoParser = new AppInfoParser(fn);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
189
|
+
// single scan (and single nested .hap extraction) for all three entries
|
|
190
|
+
const [bundleFile, updateJsonFile, metaJsonFile] =
|
|
191
|
+
await appInfoParser.parser.getEntriesFromHarmonyApp([
|
|
192
|
+
/rawfile\/bundle.harmony.js/,
|
|
193
|
+
/rawfile\/update.json/,
|
|
194
|
+
/rawfile\/meta.json/,
|
|
195
|
+
]);
|
|
188
196
|
if (!bundleFile) {
|
|
189
197
|
throw new Error(
|
|
190
198
|
t('bundleNotFound', {
|
|
@@ -193,14 +201,10 @@ export async function getAppInfo(fn: string) {
|
|
|
193
201
|
}),
|
|
194
202
|
);
|
|
195
203
|
}
|
|
196
|
-
const updateJsonFile =
|
|
197
|
-
await appInfoParser.parser.getEntryFromHarmonyApp(/rawfile\/update.json/);
|
|
198
204
|
let appCredential = {};
|
|
199
205
|
if (updateJsonFile) {
|
|
200
206
|
appCredential = JSON.parse(updateJsonFile.toString()).harmony;
|
|
201
207
|
}
|
|
202
|
-
const metaJsonFile =
|
|
203
|
-
await appInfoParser.parser.getEntryFromHarmonyApp(/rawfile\/meta.json/);
|
|
204
208
|
let metaData: ParsedAppMetaInfo = {};
|
|
205
209
|
if (metaJsonFile) {
|
|
206
210
|
metaData = JSON.parse(metaJsonFile.toString()) as ParsedAppMetaInfo;
|
|
@@ -210,17 +214,29 @@ export async function getAppInfo(fn: string) {
|
|
|
210
214
|
if (pushy_build_time) {
|
|
211
215
|
buildTime = Number(pushy_build_time);
|
|
212
216
|
}
|
|
213
|
-
if (buildTime
|
|
217
|
+
if (!Number.isFinite(buildTime) || buildTime === 0) {
|
|
214
218
|
throw new Error(t('buildTimeNotFound'));
|
|
215
219
|
}
|
|
216
220
|
return { versionName, buildTime, ...appCredential };
|
|
217
221
|
}
|
|
218
222
|
|
|
223
|
+
const IpaBundleFileName = /payload\/.+?\.app\/main.jsbundle/;
|
|
224
|
+
const IpaUpdateJsonName = /payload\/.+?\.app\/assets\/update.json/;
|
|
225
|
+
const IpaBuildTimeName = /payload\/.+?\.app\/pushy_build_time.txt/;
|
|
226
|
+
// Not in root bundle when use `use_frameworks`
|
|
227
|
+
const IpaBuildTimeFrameworkName =
|
|
228
|
+
/payload\/.+?\.app\/frameworks\/react_native_update.framework\/pushy_build_time.txt/;
|
|
229
|
+
|
|
219
230
|
export async function getIpaInfo(fn: string) {
|
|
220
231
|
const appInfoParser = new AppInfoParser(fn);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
232
|
+
// read all four entries in a single scan over the archive
|
|
233
|
+
const entries = await appInfoParser.parser.getEntries([
|
|
234
|
+
IpaBundleFileName,
|
|
235
|
+
IpaUpdateJsonName,
|
|
236
|
+
IpaBuildTimeName,
|
|
237
|
+
IpaBuildTimeFrameworkName,
|
|
238
|
+
]);
|
|
239
|
+
const bundleFile = entries[String(IpaBundleFileName)];
|
|
224
240
|
if (!bundleFile) {
|
|
225
241
|
throw new Error(
|
|
226
242
|
t('bundleNotFound', {
|
|
@@ -229,28 +245,20 @@ export async function getIpaInfo(fn: string) {
|
|
|
229
245
|
}),
|
|
230
246
|
);
|
|
231
247
|
}
|
|
232
|
-
const updateJsonFile =
|
|
233
|
-
/payload\/.+?\.app\/assets\/update.json/,
|
|
234
|
-
);
|
|
248
|
+
const updateJsonFile = entries[String(IpaUpdateJsonName)];
|
|
235
249
|
let appCredential = {};
|
|
236
250
|
if (updateJsonFile) {
|
|
237
251
|
appCredential = JSON.parse(updateJsonFile.toString()).ios;
|
|
238
252
|
}
|
|
239
253
|
const { CFBundleShortVersionString: versionName } =
|
|
240
254
|
await appInfoParser.parse<ParsedIpaInfo>();
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (!buildTimeTxtBuffer) {
|
|
245
|
-
// Not in root bundle when use `use_frameworks`
|
|
246
|
-
buildTimeTxtBuffer = await appInfoParser.parser.getEntry(
|
|
247
|
-
/payload\/.+?\.app\/frameworks\/react_native_update.framework\/pushy_build_time.txt/,
|
|
248
|
-
);
|
|
249
|
-
}
|
|
255
|
+
const buildTimeTxtBuffer =
|
|
256
|
+
entries[String(IpaBuildTimeName)] ??
|
|
257
|
+
entries[String(IpaBuildTimeFrameworkName)];
|
|
250
258
|
if (!buildTimeTxtBuffer) {
|
|
251
259
|
throw new Error(t('buildTimeNotFound'));
|
|
252
260
|
}
|
|
253
|
-
const buildTime = buildTimeTxtBuffer.toString().
|
|
261
|
+
const buildTime = buildTimeTxtBuffer.toString().trim();
|
|
254
262
|
return { versionName, buildTime, ...appCredential };
|
|
255
263
|
}
|
|
256
264
|
|
|
@@ -274,7 +282,7 @@ export async function getAabInfo(fn: string) {
|
|
|
274
282
|
|
|
275
283
|
const manifestElement = object.element;
|
|
276
284
|
if (manifestElement.name !== 'manifest') {
|
|
277
|
-
throw new Error('
|
|
285
|
+
throw new Error(t('invalidManifest'));
|
|
278
286
|
}
|
|
279
287
|
|
|
280
288
|
let versionName = '';
|
|
@@ -331,7 +339,7 @@ export async function getAabInfo(fn: string) {
|
|
|
331
339
|
}
|
|
332
340
|
}
|
|
333
341
|
|
|
334
|
-
if (buildTime === 0) {
|
|
342
|
+
if (!Number.isFinite(buildTime) || buildTime === 0) {
|
|
335
343
|
throw new Error(t('buildTimeNotFound'));
|
|
336
344
|
}
|
|
337
345
|
|
|
@@ -352,13 +360,20 @@ async function readZipEntry(fn: string, entryName: string): Promise<Buffer> {
|
|
|
352
360
|
found = true;
|
|
353
361
|
zipfile.openReadStream(entry, (streamError, readStream) => {
|
|
354
362
|
if (streamError || !readStream) {
|
|
363
|
+
zipfile.close();
|
|
355
364
|
reject(streamError ?? new Error('Failed to read zip entry'));
|
|
356
365
|
return;
|
|
357
366
|
}
|
|
358
367
|
const chunks: Buffer[] = [];
|
|
359
368
|
readStream.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
360
|
-
readStream.on('end', () =>
|
|
361
|
-
|
|
369
|
+
readStream.on('end', () => {
|
|
370
|
+
zipfile.close();
|
|
371
|
+
resolve(Buffer.concat(chunks));
|
|
372
|
+
});
|
|
373
|
+
readStream.on('error', (error) => {
|
|
374
|
+
zipfile.close();
|
|
375
|
+
reject(error);
|
|
376
|
+
});
|
|
362
377
|
});
|
|
363
378
|
} else {
|
|
364
379
|
zipfile.readEntry();
|
|
@@ -414,7 +429,7 @@ async function resolveResource(
|
|
|
414
429
|
}
|
|
415
430
|
}
|
|
416
431
|
} catch (e) {
|
|
417
|
-
console.warn('
|
|
432
|
+
console.warn(t('failedToResolveResource', { error: e }));
|
|
418
433
|
}
|
|
419
434
|
return null;
|
|
420
435
|
}
|
package/src/versions.ts
CHANGED
|
@@ -133,7 +133,7 @@ function toNumericIds(ids: string[]) {
|
|
|
133
133
|
return ids.map((id) => {
|
|
134
134
|
const numericId = Number(id);
|
|
135
135
|
if (!Number.isInteger(numericId) || numericId <= 0) {
|
|
136
|
-
throw new Error(
|
|
136
|
+
throw new Error(t('invalidId', { id }));
|
|
137
137
|
}
|
|
138
138
|
return numericId;
|
|
139
139
|
});
|
|
@@ -563,7 +563,7 @@ export const versionCommands = {
|
|
|
563
563
|
if (nonInteractive) {
|
|
564
564
|
throw new Error(t('versionIdRequired'));
|
|
565
565
|
}
|
|
566
|
-
versionId = (await chooseVersion(String(appId))).id;
|
|
566
|
+
versionId = String((await chooseVersion(String(appId))).id);
|
|
567
567
|
}
|
|
568
568
|
if (versionId === 'null') {
|
|
569
569
|
versionId = null;
|
|
@@ -640,7 +640,7 @@ export const versionCommands = {
|
|
|
640
640
|
if (nonInteractive) {
|
|
641
641
|
throw new Error(t('packageIdRequired'));
|
|
642
642
|
}
|
|
643
|
-
pkgId = (await choosePackage(String(appId))).id;
|
|
643
|
+
pkgId = String((await choosePackage(String(appId))).id);
|
|
644
644
|
}
|
|
645
645
|
|
|
646
646
|
if (!pkgId) {
|
|
@@ -693,7 +693,7 @@ export const versionCommands = {
|
|
|
693
693
|
if (nonInteractive) {
|
|
694
694
|
throw new Error(t('versionIdRequired'));
|
|
695
695
|
}
|
|
696
|
-
versionId = (await chooseVersion(String(appId))).id;
|
|
696
|
+
versionId = String((await chooseVersion(String(appId))).id);
|
|
697
697
|
}
|
|
698
698
|
|
|
699
699
|
const updateParams: Record<string, string> = {};
|
|
@@ -721,7 +721,7 @@ export const versionCommands = {
|
|
|
721
721
|
if (nonInteractive) {
|
|
722
722
|
throw new Error(t('versionIdRequired'));
|
|
723
723
|
}
|
|
724
|
-
versionIds = [(await chooseVersion(String(appId))).id];
|
|
724
|
+
versionIds = [String((await chooseVersion(String(appId))).id)];
|
|
725
725
|
}
|
|
726
726
|
|
|
727
727
|
try {
|