react-native-update-cli 2.24.1 → 2.25.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 (95) hide show
  1. package/README.md +11 -4
  2. package/README.zh-CN.md +11 -4
  3. package/cli.json +7 -1
  4. package/lib/api.d.ts +2 -0
  5. package/lib/api.js +63 -18
  6. package/lib/app.js +25 -3
  7. package/lib/bin.js +39 -45
  8. package/lib/bundle-runner.d.ts +27 -0
  9. package/lib/bundle-runner.js +240 -21
  10. package/lib/bundle.d.ts +1 -1
  11. package/lib/bundle.js +19 -6
  12. package/lib/commands.d.ts +6 -0
  13. package/lib/commands.js +65 -0
  14. package/lib/locales/en.d.ts +5 -14
  15. package/lib/locales/en.js +5 -14
  16. package/lib/locales/zh.d.ts +5 -13
  17. package/lib/locales/zh.js +5 -13
  18. package/lib/package.js +4 -0
  19. package/lib/provider.d.ts +1 -1
  20. package/lib/provider.js +3 -1
  21. package/lib/symbolicate.js +11 -3
  22. package/lib/types.d.ts +1 -0
  23. package/lib/user.js +6 -0
  24. package/lib/utils/add-gitignore.js +7 -1
  25. package/lib/utils/dep-versions.d.ts +7 -0
  26. package/lib/utils/dep-versions.js +78 -26
  27. package/lib/utils/git.js +9 -6
  28. package/lib/utils/hermes-base.js +2 -1
  29. package/lib/utils/i18n.d.ts +5 -0
  30. package/lib/utils/i18n.js +14 -1
  31. package/lib/utils/index.d.ts +2 -1
  32. package/lib/utils/index.js +9 -4
  33. package/lib/utils/latest-version/index.js +8 -0
  34. package/lib/utils/runtime.d.ts +21 -0
  35. package/lib/utils/runtime.js +138 -5
  36. package/lib/utils/slim-sourcemap.d.ts +11 -0
  37. package/lib/utils/slim-sourcemap.js +22 -0
  38. package/lib/utils/zip-range.js +3 -2
  39. package/lib/versions.js +16 -15
  40. package/package.json +4 -2
  41. package/lib/index.d.ts +0 -1
  42. package/lib/index.js +0 -17
  43. package/src/api.ts +0 -470
  44. package/src/app.ts +0 -241
  45. package/src/auto-update.ts +0 -647
  46. package/src/bin-cresc.ts +0 -8
  47. package/src/bin.ts +0 -115
  48. package/src/bundle-pack.ts +0 -61
  49. package/src/bundle-runner.ts +0 -1430
  50. package/src/bundle.ts +0 -371
  51. package/src/cache.ts +0 -20
  52. package/src/diff.ts +0 -1010
  53. package/src/exports.ts +0 -17
  54. package/src/index.ts +0 -1
  55. package/src/install.ts +0 -50
  56. package/src/locales/en.ts +0 -257
  57. package/src/locales/zh.ts +0 -234
  58. package/src/native-package.ts +0 -338
  59. package/src/package.ts +0 -482
  60. package/src/provider.ts +0 -294
  61. package/src/symbolicate.ts +0 -159
  62. package/src/types.ts +0 -150
  63. package/src/user.ts +0 -39
  64. package/src/utils/add-gitignore.ts +0 -35
  65. package/src/utils/app-info-parser/aab.ts +0 -241
  66. package/src/utils/app-info-parser/apk.ts +0 -92
  67. package/src/utils/app-info-parser/app.ts +0 -7
  68. package/src/utils/app-info-parser/index.ts +0 -54
  69. package/src/utils/app-info-parser/ipa.ts +0 -109
  70. package/src/utils/app-info-parser/resource-finder.ts +0 -508
  71. package/src/utils/app-info-parser/utils.ts +0 -161
  72. package/src/utils/app-info-parser/xml-parser/binary.ts +0 -693
  73. package/src/utils/app-info-parser/xml-parser/manifest.ts +0 -228
  74. package/src/utils/app-info-parser/zip.ts +0 -108
  75. package/src/utils/check-lockfile.ts +0 -93
  76. package/src/utils/check-plugin.ts +0 -38
  77. package/src/utils/command-result.ts +0 -24
  78. package/src/utils/constants.ts +0 -25
  79. package/src/utils/dep-versions.ts +0 -83
  80. package/src/utils/git.ts +0 -71
  81. package/src/utils/hbcTransform.ts +0 -649
  82. package/src/utils/hermes-base.ts +0 -1137
  83. package/src/utils/http-helper.ts +0 -152
  84. package/src/utils/i18n.ts +0 -39
  85. package/src/utils/index.ts +0 -698
  86. package/src/utils/latest-version/index.ts +0 -573
  87. package/src/utils/options.ts +0 -78
  88. package/src/utils/plugin-config.ts +0 -32
  89. package/src/utils/runtime.ts +0 -187
  90. package/src/utils/slim-sourcemap.ts +0 -83
  91. package/src/utils/zip-entries.ts +0 -209
  92. package/src/utils/zip-options.ts +0 -178
  93. package/src/utils/zip-range.ts +0 -727
  94. package/src/utils/zip-raw-writer.ts +0 -247
  95. package/src/versions.ts +0 -894
package/src/package.ts DELETED
@@ -1,482 +0,0 @@
1
- import * as fs from 'fs-extra';
2
- import os from 'os';
3
- import path from 'path';
4
- import { doDelete, getAllPackages, post, uploadFile } from './api';
5
- import { getSelectedApp, resolveAppId } from './app';
6
- import { createSlimNativePackage } from './native-package';
7
- import type { Package, Platform } from './types';
8
- import {
9
- getAabInfo,
10
- getApkInfo,
11
- getAppInfo,
12
- getIpaInfo,
13
- loadTtyTable,
14
- question,
15
- } from './utils';
16
- import { updateJson } from './utils/constants';
17
- import { getDepVersions } from './utils/dep-versions';
18
- import { getCommitInfo } from './utils/git';
19
- import { bundleEntryMatcher, cachePut } from './utils/hermes-base';
20
- import { t } from './utils/i18n';
21
- import { getStringListOption } from './utils/options';
22
- import { bundleLocationFields, locateZipEntry } from './utils/zip-range';
23
-
24
- type PackageCommandOptions = Record<string, unknown> & {
25
- appId?: string;
26
- appKey?: string;
27
- config?: string;
28
- platform?: Platform;
29
- version?: string;
30
- packageId?: string;
31
- packageIds?: string;
32
- packageVersion?: string;
33
- includeAllSplits?: boolean | string;
34
- splits?: string;
35
- output?: string;
36
- };
37
-
38
- type PackageVersionRef = {
39
- id?: string | number;
40
- name?: string | number;
41
- };
42
-
43
- type NativePackageInfo = {
44
- versionName?: string | number;
45
- buildTime?: string | number;
46
- /** sha256 of the JS bundle embedded in the package (content identity) */
47
- bundleHash?: string;
48
- appId?: string;
49
- appKey?: string;
50
- [key: string]: unknown;
51
- };
52
-
53
- type NativeUploadConfig = {
54
- extension: '.ipa' | '.apk' | '.app';
55
- platform: Platform;
56
- appIdMismatchKey: string;
57
- appKeyMismatchKey: string;
58
- successKey: string;
59
- getInfo: (filePath: string) => Promise<NativePackageInfo>;
60
- normalizeBuildTime?: (
61
- buildTime: NativePackageInfo['buildTime'],
62
- ) => string | number | undefined;
63
- };
64
-
65
- // the AAB parser drags in protobufjs; load it only for the aab commands
66
- function createAabParser(source: string) {
67
- const { AabParser } =
68
- require('./utils/app-info-parser/aab') as typeof import('./utils/app-info-parser/aab');
69
- return new AabParser(source);
70
- }
71
-
72
- export function normalizeUploadBuildTime(value: unknown): string {
73
- return String(value);
74
- }
75
-
76
- function ensureFileByExt(
77
- filePath: string | undefined,
78
- extension: NativeUploadConfig['extension'] | '.aab',
79
- usageKey: string,
80
- ): string {
81
- if (!filePath?.endsWith(extension)) {
82
- throw new Error(t(usageKey));
83
- }
84
- return filePath;
85
- }
86
-
87
- function parseBooleanOption(value: unknown): boolean {
88
- return value === true || value === 'true';
89
- }
90
-
91
- function parseCsvOption(value: unknown): string[] | null {
92
- if (typeof value !== 'string') {
93
- return null;
94
- }
95
- const parsed = value
96
- .split(',')
97
- .map((item) => item.trim())
98
- .filter(Boolean);
99
- return parsed.length > 0 ? parsed : null;
100
- }
101
-
102
- function toNumericIds(ids: string[]) {
103
- return ids.map((id) => {
104
- const numericId = Number(id);
105
- if (!Number.isInteger(numericId) || numericId <= 0) {
106
- throw new Error(t('invalidId', { id }));
107
- }
108
- return numericId;
109
- });
110
- }
111
-
112
- function getVersionBinding(version: unknown): PackageVersionRef | undefined {
113
- if (!version || typeof version !== 'object') {
114
- return undefined;
115
- }
116
-
117
- const v = version as PackageVersionRef;
118
- return { id: v.id, name: v.name };
119
- }
120
-
121
- async function uploadNativePackage(
122
- filePath: string,
123
- options: PackageCommandOptions,
124
- config: NativeUploadConfig,
125
- ): Promise<void> {
126
- const info = await config.getInfo(filePath);
127
- const { versionName: extractedVersionName, buildTime, bundleHash } = info;
128
- const bundleFile = (info as { bundleFile?: Buffer }).bundleFile;
129
- const { appId: appIdInPkg, appKey: appKeyInPkg } = info;
130
- const selectedApp = options.appId
131
- ? {
132
- appId: String(options.appId),
133
- appKey: typeof options.appKey === 'string' ? options.appKey : undefined,
134
- }
135
- : await getSelectedApp(config.platform, options.config);
136
- const { appId, appKey } = selectedApp;
137
- // where the expected app came from, for the mismatch messages
138
- const source = options.appId ? '--appId' : options.config || updateJson;
139
-
140
- if (appIdInPkg && String(appIdInPkg) !== appId) {
141
- throw new Error(t(config.appIdMismatchKey, { appIdInPkg, appId, source }));
142
- }
143
-
144
- if (appKeyInPkg && appKey && appKeyInPkg !== appKey) {
145
- throw new Error(
146
- t(config.appKeyMismatchKey, { appKeyInPkg, appKey, source }),
147
- );
148
- }
149
-
150
- const customVersion =
151
- typeof options.version === 'string' && options.version
152
- ? options.version
153
- : undefined;
154
- const versionName = customVersion ?? extractedVersionName;
155
- if (customVersion !== undefined) {
156
- console.log(t('usingCustomVersion', { version: versionName }));
157
- }
158
-
159
- const tempRoot = await fs.mkdtemp(
160
- path.join(os.tmpdir(), 'rnu-native-package-upload-'),
161
- );
162
- const slimPackagePath = path.join(tempRoot, `package${config.extension}`);
163
- try {
164
- await createSlimNativePackage(filePath, slimPackagePath, config.platform);
165
- const { hash } = await uploadFile(slimPackagePath, undefined, appId);
166
- // where the bundle sits inside the uploaded (slim) archive, so a later
167
- // `bundle` that falls back to this package as hermes base fetches only
168
- // the bundle with one HTTP Range request. Harmony .app nests a second
169
- // zip, so no location is reported for it.
170
- const bundleLocation =
171
- config.extension === '.app'
172
- ? {}
173
- : bundleLocationFields(
174
- await locateZipEntry(
175
- slimPackagePath,
176
- bundleEntryMatcher(config.extension.slice(1) as 'apk' | 'ipa'),
177
- ).catch(() => null),
178
- );
179
- if (bundleFile) {
180
- // keep the embedded bundle locally so a later `bundle` can use it as
181
- // hermes base without downloading it back (see hermes-base.ts); getInfo
182
- // already hashed the bundle, so pass that hash instead of hashing twice
183
- await cachePut(bundleFile, undefined, bundleHash).catch(() => {});
184
- }
185
- const normalizedBuildTime = config.normalizeBuildTime
186
- ? config.normalizeBuildTime(buildTime)
187
- : buildTime;
188
- const uploadBuildTime = normalizeUploadBuildTime(normalizedBuildTime);
189
-
190
- const { id } = await post(`/app/${appId}/package/create`, {
191
- name: versionName,
192
- hash,
193
- buildTime: uploadBuildTime,
194
- // Content identity of the embedded JS bundle; the server matches it
195
- // against the client-reported bundleHash to decide pdiff applicability.
196
- // Old servers strip unknown fields, so this is forward-compatible.
197
- ...(bundleHash ? { bundleHash } : {}),
198
- ...bundleLocation,
199
- deps: getDepVersions(),
200
- commit: await getCommitInfo(),
201
- });
202
- console.log(
203
- t(config.successKey, {
204
- id,
205
- version: versionName,
206
- buildTime: uploadBuildTime,
207
- }),
208
- );
209
- } finally {
210
- await fs.remove(tempRoot);
211
- }
212
- }
213
-
214
- /**
215
- * Print the app's native packages. Pass `packages` when the caller already
216
- * fetched them (every page of the list), to skip fetching them again.
217
- */
218
- export async function listPackage(appId: string, packages?: Package[]) {
219
- const allPkgs = packages ?? (await getAllPackages(appId)) ?? [];
220
-
221
- const header = [
222
- { value: t('nativePackageId') },
223
- { value: t('nativeVersion') },
224
- ];
225
- const rows = [];
226
- for (const pkg of allPkgs) {
227
- const { version } = pkg;
228
- let versionInfo = '';
229
- if (version) {
230
- const versionObj = getVersionBinding(version);
231
- versionInfo = t('boundTo', {
232
- name: versionObj?.name ?? version,
233
- id: versionObj?.id ?? version,
234
- });
235
- }
236
- let output = pkg.name;
237
- if (pkg.status === 'paused') {
238
- output += t('pausedStatus');
239
- }
240
- if (pkg.status === 'expired') {
241
- output += t('expiredStatus');
242
- }
243
- output += versionInfo;
244
- rows.push([pkg.id, output]);
245
- }
246
-
247
- // tty-table is ~25 ms to load; only pay for it when a table is rendered
248
- const Table = loadTtyTable();
249
- console.log(Table(header, rows).render());
250
- console.log(t('totalPackages', { count: allPkgs.length }));
251
- return allPkgs;
252
- }
253
-
254
- export async function choosePackage(appId: string, packages?: Package[]) {
255
- const list = await listPackage(appId, packages);
256
- const packageMap = new Map(list?.map((v) => [v.id.toString(), v]));
257
-
258
- while (true) {
259
- const id = await question(t('enterNativePackageId'));
260
- const app = packageMap.get(id);
261
- if (app) {
262
- return app;
263
- }
264
- }
265
- }
266
-
267
- export const packageCommands = {
268
- uploadIpa: async ({
269
- args,
270
- options,
271
- }: {
272
- args: string[];
273
- options: PackageCommandOptions;
274
- }) => {
275
- const fn = ensureFileByExt(args[0], '.ipa', 'usageUploadIpa');
276
- await uploadNativePackage(fn, options, {
277
- extension: '.ipa',
278
- platform: 'ios',
279
- appIdMismatchKey: 'appIdMismatchIpa',
280
- appKeyMismatchKey: 'appKeyMismatchIpa',
281
- successKey: 'ipaUploadSuccess',
282
- getInfo: (filePath) => getIpaInfo(filePath),
283
- });
284
- },
285
- uploadApk: async ({
286
- args,
287
- options,
288
- }: {
289
- args: string[];
290
- options: PackageCommandOptions;
291
- }) => {
292
- const fn = ensureFileByExt(args[0], '.apk', 'usageUploadApk');
293
- await uploadNativePackage(fn, options, {
294
- extension: '.apk',
295
- platform: 'android',
296
- appIdMismatchKey: 'appIdMismatchApk',
297
- appKeyMismatchKey: 'appKeyMismatchApk',
298
- successKey: 'apkUploadSuccess',
299
- getInfo: (filePath) => getApkInfo(filePath),
300
- });
301
- },
302
- uploadAab: async ({
303
- args,
304
- options,
305
- }: {
306
- args: string[];
307
- options: PackageCommandOptions;
308
- }) => {
309
- const source = ensureFileByExt(args[0], '.aab', 'usageUploadAab');
310
-
311
- // private temp dir: unpredictable path, safe against symlink squatting in
312
- // the shared tmpdir and against concurrent uploads of same-named AABs
313
- const tempRoot = await fs.mkdtemp(
314
- path.join(os.tmpdir(), 'rnu-aab-upload-'),
315
- );
316
- const output = path.join(tempRoot, 'universal.apk');
317
-
318
- const includeAllSplits = parseBooleanOption(options.includeAllSplits);
319
- const splits = parseCsvOption(options.splits);
320
-
321
- const parser = createAabParser(source);
322
- try {
323
- await parser.extractApk(output, {
324
- includeAllSplits,
325
- splits,
326
- });
327
- await packageCommands.uploadApk({
328
- args: [output],
329
- options,
330
- });
331
- } finally {
332
- await fs.remove(tempRoot);
333
- }
334
- },
335
- uploadApp: async ({
336
- args,
337
- options,
338
- }: {
339
- args: string[];
340
- options: PackageCommandOptions;
341
- }) => {
342
- const fn = ensureFileByExt(args[0], '.app', 'usageUploadApp');
343
- await uploadNativePackage(fn, options, {
344
- extension: '.app',
345
- platform: 'harmony',
346
- appIdMismatchKey: 'appIdMismatchApp',
347
- appKeyMismatchKey: 'appKeyMismatchApp',
348
- successKey: 'appUploadSuccess',
349
- getInfo: (filePath) => getAppInfo(filePath),
350
- normalizeBuildTime: (buildTime) => String(buildTime),
351
- });
352
- },
353
- parseApp: async ({ args }: { args: string[] }) => {
354
- const fn = args[0];
355
- if (!fn?.endsWith('.app')) {
356
- throw new Error(t('usageParseApp'));
357
- }
358
- console.log(await getAppInfo(fn));
359
- },
360
- parseIpa: async ({ args }: { args: string[] }) => {
361
- const fn = args[0];
362
- if (!fn?.endsWith('.ipa')) {
363
- throw new Error(t('usageParseIpa'));
364
- }
365
- console.log(await getIpaInfo(fn));
366
- },
367
- parseApk: async ({ args }: { args: string[] }) => {
368
- const fn = args[0];
369
- if (!fn?.endsWith('.apk')) {
370
- throw new Error(t('usageParseApk'));
371
- }
372
- console.log(await getApkInfo(fn));
373
- },
374
- parseAab: async ({ args }: { args: string[] }) => {
375
- const fn = args[0];
376
- if (!fn?.endsWith('.aab')) {
377
- throw new Error(t('usageParseAab'));
378
- }
379
- console.log(await getAabInfo(fn));
380
- },
381
- extractApk: async ({
382
- args,
383
- options,
384
- }: {
385
- args: string[];
386
- options: PackageCommandOptions;
387
- }) => {
388
- const source = ensureFileByExt(args[0], '.aab', 'usageExtractApk');
389
-
390
- const output =
391
- options.output ||
392
- path.join(
393
- path.dirname(source),
394
- `${path.basename(source, path.extname(source))}.apk`,
395
- );
396
-
397
- const includeAllSplits = parseBooleanOption(options.includeAllSplits);
398
- const splits = parseCsvOption(options.splits);
399
-
400
- const parser = createAabParser(source);
401
- await parser.extractApk(output, {
402
- includeAllSplits,
403
- splits,
404
- });
405
-
406
- console.log(t('apkExtracted', { output }));
407
- },
408
- packages: async ({
409
- options,
410
- }: {
411
- options: { platform: Platform; appId?: string; config?: string };
412
- }) => {
413
- await listPackage(await resolveAppId(options));
414
- },
415
- deletePackage: async ({ options }: { options: PackageCommandOptions }) => {
416
- const appId = await resolveAppId(options);
417
- let packageIds =
418
- getStringListOption(options, 'packageIds') ??
419
- getStringListOption(options, 'packageId');
420
-
421
- if (!packageIds) {
422
- const packageVersions = getStringListOption(options, 'packageVersion');
423
- if (!packageVersions) {
424
- throw new Error(t('usageDeletePackage'));
425
- }
426
-
427
- const allPkgs = await getAllPackages(appId);
428
- if (!allPkgs) {
429
- throw new Error(t('noPackagesFound', { appId }));
430
- }
431
-
432
- const allPkgsMap = new Map(allPkgs.map((pkg) => [pkg.name, pkg]));
433
-
434
- packageIds = packageVersions.map((packageVersion) => {
435
- const selectedPackage = allPkgsMap.get(packageVersion);
436
- if (!selectedPackage) {
437
- throw new Error(t('packageNotFound', { packageVersion }));
438
- }
439
- return String(selectedPackage.id);
440
- });
441
- }
442
-
443
- // Confirm deletion
444
- // const confirmDelete = await question(
445
- // t('confirmDeletePackage', { packageId }),
446
- // );
447
-
448
- // if (
449
- // confirmDelete.toLowerCase() !== 'y' &&
450
- // confirmDelete.toLowerCase() !== 'yes'
451
- // ) {
452
- // console.log(t('cancelled'));
453
- // return;
454
- // }
455
-
456
- try {
457
- if (packageIds.length === 1) {
458
- const [packageId] = packageIds;
459
- await doDelete(`/app/${appId}/package/${packageId}`);
460
- console.log(t('deletePackageSuccess', { packageId }));
461
- } else {
462
- await doDelete(`/app/${appId}/package`, {
463
- packageIds: toNumericIds(packageIds),
464
- });
465
- console.log(
466
- t('deletePackagesSuccess', {
467
- count: packageIds.length,
468
- packageIds: packageIds.join(', '),
469
- }),
470
- );
471
- }
472
- } catch (error) {
473
- const message = error instanceof Error ? error.message : String(error);
474
- throw new Error(
475
- t('deletePackageError', {
476
- packageId: packageIds.join(', '),
477
- error: message,
478
- }),
479
- );
480
- }
481
- },
482
- };