react-native-update-cli 2.24.2 → 2.26.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 (98) hide show
  1. package/README.md +12 -5
  2. package/README.zh-CN.md +12 -5
  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 +45 -1
  9. package/lib/bundle-runner.js +303 -34
  10. package/lib/bundle.d.ts +1 -1
  11. package/lib/bundle.js +23 -7
  12. package/lib/commands.d.ts +6 -0
  13. package/lib/commands.js +65 -0
  14. package/lib/locales/en.d.ts +7 -14
  15. package/lib/locales/en.js +10 -17
  16. package/lib/locales/zh.d.ts +7 -13
  17. package/lib/locales/zh.js +10 -16
  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 +7 -2
  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/hbcTransform.d.ts +15 -0
  29. package/lib/utils/hbcTransform.js +22 -0
  30. package/lib/utils/hermes-base.d.ts +61 -6
  31. package/lib/utils/hermes-base.js +328 -46
  32. package/lib/utils/hermes-literals.d.ts +51 -0
  33. package/lib/utils/hermes-literals.js +210 -0
  34. package/lib/utils/i18n.d.ts +5 -0
  35. package/lib/utils/i18n.js +14 -1
  36. package/lib/utils/index.d.ts +2 -1
  37. package/lib/utils/index.js +9 -4
  38. package/lib/utils/latest-version/index.js +8 -0
  39. package/lib/utils/runtime.d.ts +21 -0
  40. package/lib/utils/runtime.js +138 -5
  41. package/lib/utils/zip-range.js +3 -2
  42. package/lib/versions.js +14 -4
  43. package/package.json +6 -3
  44. package/lib/index.d.ts +0 -1
  45. package/lib/index.js +0 -17
  46. package/src/api.ts +0 -470
  47. package/src/app.ts +0 -241
  48. package/src/auto-update.ts +0 -647
  49. package/src/bin-cresc.ts +0 -8
  50. package/src/bin.ts +0 -115
  51. package/src/bundle-pack.ts +0 -61
  52. package/src/bundle-runner.ts +0 -1430
  53. package/src/bundle.ts +0 -371
  54. package/src/cache.ts +0 -20
  55. package/src/diff.ts +0 -1010
  56. package/src/exports.ts +0 -17
  57. package/src/index.ts +0 -1
  58. package/src/install.ts +0 -50
  59. package/src/locales/en.ts +0 -257
  60. package/src/locales/zh.ts +0 -234
  61. package/src/native-package.ts +0 -338
  62. package/src/package.ts +0 -482
  63. package/src/provider.ts +0 -294
  64. package/src/symbolicate.ts +0 -164
  65. package/src/types.ts +0 -150
  66. package/src/user.ts +0 -39
  67. package/src/utils/add-gitignore.ts +0 -35
  68. package/src/utils/app-info-parser/aab.ts +0 -241
  69. package/src/utils/app-info-parser/apk.ts +0 -92
  70. package/src/utils/app-info-parser/app.ts +0 -7
  71. package/src/utils/app-info-parser/index.ts +0 -54
  72. package/src/utils/app-info-parser/ipa.ts +0 -109
  73. package/src/utils/app-info-parser/resource-finder.ts +0 -508
  74. package/src/utils/app-info-parser/utils.ts +0 -161
  75. package/src/utils/app-info-parser/xml-parser/binary.ts +0 -693
  76. package/src/utils/app-info-parser/xml-parser/manifest.ts +0 -228
  77. package/src/utils/app-info-parser/zip.ts +0 -108
  78. package/src/utils/check-lockfile.ts +0 -93
  79. package/src/utils/check-plugin.ts +0 -38
  80. package/src/utils/command-result.ts +0 -24
  81. package/src/utils/constants.ts +0 -25
  82. package/src/utils/dep-versions.ts +0 -83
  83. package/src/utils/git.ts +0 -71
  84. package/src/utils/hbcTransform.ts +0 -649
  85. package/src/utils/hermes-base.ts +0 -1137
  86. package/src/utils/http-helper.ts +0 -152
  87. package/src/utils/i18n.ts +0 -39
  88. package/src/utils/index.ts +0 -698
  89. package/src/utils/latest-version/index.ts +0 -573
  90. package/src/utils/options.ts +0 -78
  91. package/src/utils/plugin-config.ts +0 -32
  92. package/src/utils/runtime.ts +0 -187
  93. package/src/utils/slim-sourcemap.ts +0 -105
  94. package/src/utils/zip-entries.ts +0 -209
  95. package/src/utils/zip-options.ts +0 -178
  96. package/src/utils/zip-range.ts +0 -727
  97. package/src/utils/zip-raw-writer.ts +0 -247
  98. package/src/versions.ts +0 -892
package/src/versions.ts DELETED
@@ -1,892 +0,0 @@
1
- import chalk from 'chalk';
2
- import { compare, satisfies } from 'compare-versions';
3
- import fs from 'fs';
4
- import os from 'os';
5
- import path from 'path';
6
- import { doDelete, get, getAllPackages, post, put, uploadFile } from './api';
7
- import { getPlatform, resolveAppId } from './app';
8
- import { choosePackage } from './package';
9
- import type { Package, Platform, Version } from './types';
10
- import { isNonInteractive, loadTtyTable, question } from './utils';
11
- import { getDepVersions } from './utils/dep-versions';
12
- import { getCommitInfo } from './utils/git';
13
- import { getHbcVersion } from './utils/hbcTransform';
14
- import {
15
- BUNDLE_ENTRY_NAMES,
16
- cachePut,
17
- extractBundleFromArchive,
18
- type HermesBaseMeta,
19
- sha256Hex,
20
- } from './utils/hermes-base';
21
- import { t } from './utils/i18n';
22
- import { getBooleanOption, getStringListOption } from './utils/options';
23
- import { packSourceMap } from './utils/slim-sourcemap';
24
- import {
25
- bundleLocationFields,
26
- readZipEntryWithLocation,
27
- } from './utils/zip-range';
28
-
29
- interface VersionCommandOptions {
30
- [key: string]: unknown;
31
- config?: string;
32
- appKey?: string;
33
- appId?: string;
34
- name?: string;
35
- description?: string;
36
- metaInfo?: string;
37
- platform?: Platform;
38
- versionId?: string;
39
- versionIds?: string;
40
- packageId?: string;
41
- packageVersion?: string;
42
- minPackageVersion?: string;
43
- maxPackageVersion?: string;
44
- packageVersionRange?: string;
45
- rollout?: number | string;
46
- dryRun?: boolean;
47
- versionDeps?: Record<string, string>;
48
- warnDepsChanges?: boolean;
49
- /** internal: chain metadata from the bundle step (not a CLI flag) */
50
- hermesBase?: HermesBaseMeta;
51
- 'no-interactive'?: boolean | string;
52
- }
53
-
54
- type Deps = Record<string, string>;
55
- type DepChangeType = 'added' | 'removed' | 'changed';
56
-
57
- interface DepChange {
58
- dependency: string;
59
- oldVersion: string;
60
- newVersion: string;
61
- type: DepChangeType;
62
- }
63
-
64
- interface DepsChangeSummary {
65
- added: number;
66
- removed: number;
67
- changed: number;
68
- }
69
-
70
- export function normalizeDeps(input: unknown): Deps | undefined {
71
- if (!input) {
72
- return undefined;
73
- }
74
-
75
- let raw: unknown = input;
76
- if (typeof input === 'string') {
77
- try {
78
- raw = JSON.parse(input);
79
- } catch (_e) {
80
- return undefined;
81
- }
82
- }
83
-
84
- if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
85
- return undefined;
86
- }
87
-
88
- const deps: Deps = {};
89
- for (const [name, version] of Object.entries(
90
- raw as Record<string, unknown>,
91
- )) {
92
- if (typeof version === 'string' && version) {
93
- deps[name] = version;
94
- }
95
- }
96
-
97
- return Object.keys(deps).length > 0 ? deps : undefined;
98
- }
99
-
100
- function getDepsChanges(oldDeps?: Deps, newDeps?: Deps): DepChange[] {
101
- if (!oldDeps || !newDeps) {
102
- return [];
103
- }
104
-
105
- const rows: DepChange[] = [];
106
- const keys = Object.keys({ ...oldDeps, ...newDeps }).sort((a, b) =>
107
- a.localeCompare(b),
108
- );
109
-
110
- for (const key of keys) {
111
- const oldVersion = oldDeps[key];
112
- const newVersion = newDeps[key];
113
-
114
- if (oldVersion === undefined && newVersion !== undefined) {
115
- rows.push({
116
- dependency: key,
117
- oldVersion: '-',
118
- newVersion,
119
- type: 'added',
120
- });
121
- continue;
122
- }
123
-
124
- if (oldVersion !== undefined && newVersion === undefined) {
125
- rows.push({
126
- dependency: key,
127
- oldVersion,
128
- newVersion: '-',
129
- type: 'removed',
130
- });
131
- continue;
132
- }
133
-
134
- if (
135
- oldVersion !== undefined &&
136
- newVersion !== undefined &&
137
- oldVersion !== newVersion
138
- ) {
139
- rows.push({
140
- dependency: key,
141
- oldVersion,
142
- newVersion,
143
- type: 'changed',
144
- });
145
- }
146
- }
147
-
148
- return rows;
149
- }
150
-
151
- function toNumericIds(ids: string[]) {
152
- return ids.map((id) => {
153
- const numericId = Number(id);
154
- if (!Number.isInteger(numericId) || numericId <= 0) {
155
- throw new Error(t('invalidId', { id }));
156
- }
157
- return numericId;
158
- });
159
- }
160
-
161
- function getDepsChangeSummary(changes: DepChange[]): DepsChangeSummary {
162
- return changes.reduce(
163
- (acc, item) => {
164
- if (item.type === 'added') {
165
- acc.added += 1;
166
- } else if (item.type === 'removed') {
167
- acc.removed += 1;
168
- } else {
169
- acc.changed += 1;
170
- }
171
- return acc;
172
- },
173
- { added: 0, removed: 0, changed: 0 },
174
- );
175
- }
176
-
177
- function renderVersionChange(change: DepChange) {
178
- const arrow = chalk.gray(` ${t('depsChangeArrow')} `);
179
-
180
- if (change.type === 'added') {
181
- return `${chalk.red(t('depsChangeAddedLabel'))} | ${chalk.gray(
182
- change.oldVersion,
183
- )}${arrow}${chalk.red(change.newVersion)}`;
184
- }
185
-
186
- if (change.type === 'removed') {
187
- return `${chalk.green(t('depsChangeRemovedLabel'))} | ${chalk.green(
188
- change.oldVersion,
189
- )}${arrow}${chalk.gray(change.newVersion)}`;
190
- }
191
-
192
- return `${chalk.yellow(t('depsChangeChangedLabel'))} | ${chalk.yellow(
193
- change.oldVersion,
194
- )}${arrow}${chalk.yellow(change.newVersion)}`;
195
- }
196
-
197
- function printDepsChangesForPackage({
198
- pkg,
199
- versionDeps,
200
- }: {
201
- pkg: Package;
202
- versionDeps: Deps;
203
- }) {
204
- const pkgDeps = normalizeDeps(pkg.deps);
205
- if (!pkgDeps) {
206
- return false;
207
- }
208
-
209
- const changes = getDepsChanges(pkgDeps, versionDeps);
210
- if (changes.length === 0) {
211
- return false;
212
- }
213
-
214
- const summary = getDepsChangeSummary(changes);
215
- const summaryText = t('depsChangeSummary', {
216
- added: chalk.red(String(summary.added)),
217
- removed: chalk.green(String(summary.removed)),
218
- changed: chalk.yellow(String(summary.changed)),
219
- });
220
- const header = [
221
- { value: t('depsChangeDependencyHeader') },
222
- { value: t('depsChangeVersionHeader') },
223
- ];
224
- const rows = changes.map((change) => [
225
- change.dependency,
226
- renderVersionChange(change),
227
- ]);
228
-
229
- console.log('');
230
- console.log(chalk.bgYellow.black.bold(` ${t('depsChangeWarningTitle')} `));
231
- console.log(
232
- chalk.yellow(
233
- t('depsChangeTargetPackage', {
234
- packageName: pkg.name,
235
- packageId: pkg.id,
236
- }),
237
- ),
238
- );
239
- console.log(summaryText);
240
- // tty-table is ~25 ms to load; only pay for it when a table is rendered
241
- const Table = loadTtyTable();
242
- console.log(Table(header, rows).render());
243
- console.log(chalk.yellow(t('depsChangeRiskWarning')));
244
- return true;
245
- }
246
-
247
- async function findVersionDeps(appId: string, versionId: string) {
248
- const targetId = String(versionId);
249
- const limit = 100;
250
- let offset = 0;
251
-
252
- while (true) {
253
- const { data, count } = await get(
254
- `/app/${appId}/version/list?offset=${offset}&limit=${limit}`,
255
- );
256
- const versions: Version[] = Array.isArray(data) ? data : [];
257
- const version = versions.find((item) => String(item.id) === targetId);
258
-
259
- if (version) {
260
- return normalizeDeps(version.deps);
261
- }
262
-
263
- offset += versions.length;
264
- if (versions.length === 0 || offset >= Number(count || 0)) {
265
- break;
266
- }
267
- }
268
-
269
- return undefined;
270
- }
271
-
272
- async function printDepsChangesForPublish({
273
- appId,
274
- versionId,
275
- pkgs,
276
- providedVersionDeps,
277
- }: {
278
- appId: string;
279
- versionId?: string;
280
- pkgs: Package[];
281
- providedVersionDeps?: Deps;
282
- }) {
283
- if (!versionId || pkgs.length !== 1) {
284
- return;
285
- }
286
-
287
- let versionDeps = normalizeDeps(providedVersionDeps);
288
- if (!versionDeps) {
289
- try {
290
- versionDeps = await findVersionDeps(appId, versionId);
291
- } catch (error: any) {
292
- console.warn(
293
- chalk.yellow(
294
- t('depsChangeFetchFailed', {
295
- error: error?.message || String(error),
296
- }),
297
- ),
298
- );
299
- return;
300
- }
301
- }
302
-
303
- if (!versionDeps) {
304
- return;
305
- }
306
-
307
- let hasChanges = false;
308
- for (const pkg of pkgs) {
309
- const printed = printDepsChangesForPackage({ pkg, versionDeps });
310
- hasChanges = hasChanges || printed;
311
- }
312
-
313
- if (hasChanges) {
314
- console.log(chalk.yellow(t('depsChangeNonBlockingHint')));
315
- }
316
- }
317
-
318
- const versionPageLimit = 10;
319
-
320
- export async function fetchVersions(
321
- appId: string,
322
- offset = 0,
323
- limit = versionPageLimit,
324
- ): Promise<Version[]> {
325
- const { data } = await get(
326
- `/app/${appId}/version/list?offset=${offset}&limit=${limit}`,
327
- );
328
- return Array.isArray(data) ? data : [];
329
- }
330
-
331
- async function showVersion(appId: string, offset: number) {
332
- const data = await fetchVersions(appId, offset, versionPageLimit);
333
- console.log(t('offset', { offset }));
334
- for (const version of data) {
335
- const pkgCount = version.packages?.length || 0;
336
- let packageInfo = '';
337
- if (pkgCount === 0) {
338
- packageInfo = 'no package';
339
- } else {
340
- packageInfo = (version.packages ?? [])
341
- .slice(0, 3)
342
- .map((pkg: Package) => pkg.name)
343
- .join(', ');
344
- if (pkgCount > 3) {
345
- packageInfo += `...and ${pkgCount - 3} more`;
346
- } else {
347
- packageInfo = `[${packageInfo}]`;
348
- }
349
- }
350
- console.log(
351
- `${version.id}) ${version.hash.slice(0, 8)} ${
352
- version.name
353
- } ${packageInfo}`,
354
- );
355
- }
356
- return data;
357
- }
358
-
359
- async function listVersions(appId: string, interactive = true) {
360
- let offset = 0;
361
- while (true) {
362
- const data = await showVersion(appId, offset);
363
- if (!interactive) {
364
- return data;
365
- }
366
- const cmd = await question('page Up/page Down/Begin/Quit(U/D/B/Q)');
367
- switch (cmd.toLowerCase()) {
368
- case 'u':
369
- offset = Math.max(0, offset - 10);
370
- break;
371
- case 'd':
372
- offset += 10;
373
- break;
374
- case 'b':
375
- offset = 0;
376
- break;
377
- case 'q':
378
- return data;
379
- case '':
380
- return data;
381
- }
382
- }
383
- }
384
-
385
- async function chooseVersion(appId: string) {
386
- let offset = 0;
387
- while (true) {
388
- const data = await showVersion(appId, offset);
389
- if (isNonInteractive()) {
390
- throw new Error(t('versionIdRequired'));
391
- }
392
- const cmd = await question(
393
- 'Enter versionId or page Up/page Down/Begin(U/D/B)',
394
- );
395
- switch (cmd.toUpperCase()) {
396
- case 'U':
397
- offset = Math.max(0, offset - 10);
398
- break;
399
- case 'D':
400
- offset += 10;
401
- break;
402
- case 'B':
403
- offset = 0;
404
- break;
405
- default: {
406
- const versionId = Number.parseInt(cmd, 10);
407
- const v = data.find(
408
- (version: Version) => String(version.id) === String(versionId),
409
- );
410
- if (v) {
411
- return v;
412
- }
413
- }
414
- }
415
- }
416
- }
417
-
418
- export const bindVersionToPackages = async ({
419
- appId,
420
- versionId,
421
- pkgs,
422
- rollout,
423
- dryRun,
424
- }: {
425
- appId: string;
426
- versionId: string | null;
427
- pkgs: Package[];
428
- rollout?: number;
429
- dryRun?: boolean;
430
- }) => {
431
- if (dryRun) {
432
- console.log(chalk.yellow(t('dryRun')));
433
- }
434
- if (rollout !== undefined) {
435
- console.log(
436
- `${t('rolloutConfigSet', {
437
- version: versionId,
438
- versions: pkgs.map((pkg: Package) => pkg.name).join(', '),
439
- rollout: rollout,
440
- })}`,
441
- );
442
- }
443
-
444
- if (!dryRun) {
445
- if (pkgs.length === 1) {
446
- await post(`/app/${appId}/binding`, {
447
- versionId,
448
- rollout,
449
- packageId: pkgs[0].id,
450
- });
451
- } else {
452
- await post(`/app/${appId}/binding`, {
453
- versionId,
454
- rollout,
455
- packageIds: toNumericIds(pkgs.map((pkg) => String(pkg.id))),
456
- });
457
- }
458
- }
459
-
460
- for (const pkg of pkgs) {
461
- console.log(
462
- `${t('versionBind', {
463
- version: versionId,
464
- nativeVersion: pkg.name,
465
- id: pkg.id,
466
- })}`,
467
- );
468
- }
469
- console.log(t('operationComplete', { count: pkgs.length }));
470
- };
471
-
472
- /**
473
- * Content identity of the ppk's bundle for the server (bundleHash, HBC version)
474
- * plus the base used to compile it, and a copy of the bundle in the local
475
- * cache so it can serve as a future base without a download.
476
- */
477
- async function describePpkBundle(
478
- ppkPath: string,
479
- base?: HermesBaseMeta,
480
- ): Promise<Record<string, unknown>> {
481
- // Only known values are sent: the server's optional-field parsers treat an
482
- // explicit JSON null as invalid (that contract broke 2.22.0/2.22.1 publishes
483
- // with "Expected baseHash string"), and omitting a field is what every
484
- // server version — strict, tolerant or too old to know the field — accepts.
485
- const meta: Record<string, unknown> = {};
486
- try {
487
- // one pass over the ppk: the bundle itself plus where its compressed
488
- // bytes live, so the next build can fetch just them with one HTTP Range
489
- // request
490
- const found = ppkPath.toLowerCase().endsWith('.ppk')
491
- ? await readZipEntryWithLocation(ppkPath, (name) =>
492
- BUNDLE_ENTRY_NAMES.includes(name),
493
- ).catch(() => null)
494
- : null;
495
- const bundle = found?.data ?? (await extractBundleFromArchive(ppkPath));
496
- if (bundle) {
497
- const bundleHash = sha256Hex(bundle);
498
- meta.bundleHash = bundleHash;
499
- const hbcVersion = getHbcVersion(bundle) ?? base?.bytecodeVersion;
500
- if (hbcVersion != null) meta.bytecodeVersion = hbcVersion;
501
- await cachePut(bundle, undefined, bundleHash).catch(() => {});
502
- Object.assign(meta, bundleLocationFields(found?.location));
503
- }
504
- } catch {
505
- // best effort: metadata never blocks a publish
506
- }
507
- if (base?.baseVersionId != null) meta.baseVersionId = base.baseVersionId;
508
- if (base?.baseHash) meta.baseHash = base.baseHash;
509
- return meta;
510
- }
511
-
512
- /** Exported for tests: the version/create fields derived from a ppk + base. */
513
- export const describePpkBundleForTests = describePpkBundle;
514
-
515
- export const versionCommands = {
516
- publish: async ({
517
- args,
518
- options,
519
- }: {
520
- args: string[];
521
- options: VersionCommandOptions;
522
- }) => {
523
- const fn = args[0];
524
- const { name, description, metaInfo } = options;
525
-
526
- if (!fn?.endsWith('.ppk')) {
527
- throw new Error(t('publishUsage'));
528
- }
529
-
530
- const platform = await getPlatform(options.platform);
531
- const appId = await resolveAppId({ ...options, platform });
532
- const nonInteractive =
533
- getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
534
-
535
- // The source map is archived with the version so `pushy symbolicate` can
536
- // map crashes back to source. An explicit path that does not exist is a
537
- // publish error; no path at all is a loud warning (custom pipelines that
538
- // never produced a map keep working).
539
- const sourcemapPath =
540
- typeof options.sourcemap === 'string' && options.sourcemap
541
- ? options.sourcemap
542
- : undefined;
543
- if (sourcemapPath && !fs.existsSync(sourcemapPath)) {
544
- throw new Error(t('sourceMapNotFound', { path: sourcemapPath }));
545
- }
546
- if (!sourcemapPath) {
547
- console.log(chalk.yellow(t('sourceMapMissingWarning')));
548
- }
549
- // Archive a slimmed, gzipped copy (see packSourceMap): relative paths, no
550
- // dependency sourcesContent, ~5x smaller on the wire. Frames keep
551
- // symbolicating everywhere; only inline snippets of node_modules code are
552
- // dropped. The temp file keeps the .map extension because /upload routes
553
- // by extension; readers detect gzip by magic bytes.
554
- let uploadSourcemapPath = sourcemapPath;
555
- let packTempDir: string | undefined;
556
- if (sourcemapPath) {
557
- packTempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rnu-sourcemap-'));
558
- uploadSourcemapPath = path.join(
559
- packTempDir,
560
- path.basename(sourcemapPath),
561
- );
562
- fs.writeFileSync(
563
- uploadSourcemapPath,
564
- packSourceMap(fs.readFileSync(sourcemapPath, 'utf8'), process.cwd()),
565
- );
566
- }
567
-
568
- // Hashing/caching the bundle and asking git for the commit are independent
569
- // of the upload, so they overlap with it instead of running afterwards.
570
- // describePpkBundle never rejects (best effort); a failed upload still
571
- // fails the publish exactly as before.
572
- // A server that predates source-map archiving (self-hosted, or a SaaS
573
- // region not yet rolled) rejects the .map upload with 400; that must not
574
- // fail the publish, only lose the archive.
575
- let sourceMapUploadError: unknown;
576
- const [{ hash }, bundleMeta, commit, sourceMapUpload] = await Promise.all([
577
- uploadFile(fn, undefined, appId),
578
- describePpkBundle(fn, options.hermesBase),
579
- getCommitInfo(),
580
- uploadSourcemapPath
581
- ? uploadFile(uploadSourcemapPath, undefined, appId).catch(
582
- (error: unknown) => {
583
- sourceMapUploadError = error;
584
- return undefined;
585
- },
586
- )
587
- : Promise.resolve(undefined),
588
- ]);
589
- if (packTempDir) {
590
- fs.rmSync(packTempDir, { recursive: true, force: true });
591
- }
592
- const sourceMapKey = sourceMapUpload?.hash;
593
- if (sourcemapPath && !sourceMapKey) {
594
- console.log(
595
- chalk.yellow(
596
- t('sourceMapUploadFailedWarning', {
597
- error:
598
- sourceMapUploadError instanceof Error
599
- ? sourceMapUploadError.message
600
- : String(sourceMapUploadError),
601
- }),
602
- ),
603
- );
604
- }
605
- const depVersions = getDepVersions();
606
-
607
- const versionName =
608
- name ||
609
- (nonInteractive ? '' : await question(t('versionNameQuestion'))) ||
610
- t('unnamed');
611
- const { id } = await post(`/app/${appId}/version/create`, {
612
- name: versionName,
613
- hash,
614
- description:
615
- description ??
616
- (nonInteractive ? '' : await question(t('versionDescriptionQuestion'))),
617
- metaInfo:
618
- metaInfo ??
619
- (nonInteractive ? '' : await question(t('versionMetaInfoQuestion'))),
620
- deps: depVersions,
621
- commit,
622
- // Hermes delta-mode chain metadata (old servers drop unknown fields)
623
- ...bundleMeta,
624
- // archived source map (old servers drop unknown fields)
625
- ...(sourceMapKey ? { sourceMapKey } : {}),
626
- });
627
- console.log(t('packageUploadSuccess', { id }));
628
- if (sourceMapKey) {
629
- console.log(t('sourceMapArchived', { id }));
630
- }
631
-
632
- const {
633
- packageId,
634
- packageVersion,
635
- packageVersionRange,
636
- minPackageVersion,
637
- maxPackageVersion,
638
- rollout,
639
- dryRun,
640
- } = options;
641
-
642
- if (
643
- packageId ||
644
- packageVersion ||
645
- packageVersionRange ||
646
- minPackageVersion ||
647
- maxPackageVersion
648
- ) {
649
- await versionCommands.update({
650
- options: {
651
- versionId: id,
652
- platform,
653
- appId,
654
- packageId,
655
- packageVersion,
656
- packageVersionRange,
657
- minPackageVersion,
658
- maxPackageVersion,
659
- rollout,
660
- dryRun,
661
- versionDeps: depVersions,
662
- warnDepsChanges: true,
663
- },
664
- });
665
- } else if (!nonInteractive) {
666
- const q = await question(t('updateNativePackageQuestion'));
667
- if (q.toLowerCase() === 'y') {
668
- await versionCommands.update({
669
- options: {
670
- versionId: id,
671
- platform,
672
- appId,
673
- versionDeps: depVersions,
674
- warnDepsChanges: true,
675
- },
676
- });
677
- }
678
- }
679
- return versionName;
680
- },
681
- versions: async ({ options }: { options: VersionCommandOptions }) => {
682
- const appId = await resolveAppId(options);
683
- const interactive = !(
684
- getBooleanOption(options, 'no-interactive', false) || isNonInteractive()
685
- );
686
- await listVersions(appId, interactive);
687
- },
688
- update: async ({ options }: { options: VersionCommandOptions }) => {
689
- const nonInteractive =
690
- getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
691
- const appId = await resolveAppId(options);
692
-
693
- let versionId: string | null | undefined = options.versionId;
694
- if (!versionId) {
695
- if (nonInteractive) {
696
- throw new Error(t('versionIdRequired'));
697
- }
698
- versionId = String((await chooseVersion(appId)).id);
699
- }
700
- if (versionId === 'null') {
701
- versionId = null;
702
- }
703
-
704
- let pkgId = options.packageId;
705
- let pkgVersion = options.packageVersion;
706
- let minPkgVersion = options.minPackageVersion;
707
- let maxPkgVersion = options.maxPackageVersion;
708
- let packageVersionRange = options.packageVersionRange;
709
- let rollout: number | undefined;
710
-
711
- if (options.rollout !== undefined) {
712
- rollout = Number.parseInt(String(options.rollout), 10);
713
- if (Number.isNaN(rollout) || rollout < 1 || rollout > 100) {
714
- throw new Error(t('rolloutRangeError'));
715
- }
716
- }
717
-
718
- const allPkgs = await getAllPackages(appId);
719
-
720
- if (!allPkgs) {
721
- throw new Error(t('noPackagesFound', { appId }));
722
- }
723
-
724
- const pkgMap = new Map(
725
- allPkgs.map((pkg: Package) => [String(pkg.id), pkg]),
726
- );
727
-
728
- let pkgsToBind: Package[] = [];
729
-
730
- const selectorGroups = [
731
- pkgId,
732
- pkgVersion,
733
- packageVersionRange,
734
- minPkgVersion || maxPkgVersion,
735
- ].filter(Boolean);
736
- if (selectorGroups.length > 1) {
737
- throw new Error(t('conflictingPackageSelectors'));
738
- }
739
-
740
- if (minPkgVersion || maxPkgVersion) {
741
- minPkgVersion = minPkgVersion && String(minPkgVersion).trim();
742
- maxPkgVersion = maxPkgVersion && String(maxPkgVersion).trim();
743
- pkgsToBind = allPkgs.filter((pkg: Package) => {
744
- const aboveMin =
745
- !minPkgVersion || compare(pkg.name, minPkgVersion, '>=');
746
- const belowMax =
747
- !maxPkgVersion || compare(pkg.name, maxPkgVersion, '<=');
748
- return aboveMin && belowMax;
749
- });
750
- if (pkgsToBind.length === 0) {
751
- if (minPkgVersion && maxPkgVersion) {
752
- throw new Error(
753
- t('nativeVersionNotFoundBetween', {
754
- min: minPkgVersion,
755
- max: maxPkgVersion,
756
- }),
757
- );
758
- }
759
- if (minPkgVersion) {
760
- throw new Error(
761
- t('nativeVersionNotFoundGte', { version: minPkgVersion }),
762
- );
763
- }
764
- throw new Error(
765
- t('nativeVersionNotFoundLte', { version: maxPkgVersion }),
766
- );
767
- }
768
- } else if (pkgVersion) {
769
- pkgVersion = pkgVersion.trim();
770
- const pkg = allPkgs.find((pkg: Package) => pkg.name === pkgVersion);
771
- if (pkg) {
772
- pkgsToBind = [pkg];
773
- } else {
774
- throw new Error(
775
- t('nativeVersionNotFoundMatch', { version: pkgVersion }),
776
- );
777
- }
778
- } else if (packageVersionRange) {
779
- packageVersionRange = packageVersionRange.trim();
780
- pkgsToBind = allPkgs.filter((pkg: Package) =>
781
- satisfies(pkg.name, packageVersionRange!),
782
- );
783
- if (pkgsToBind.length === 0) {
784
- throw new Error(
785
- t('nativeVersionNotFoundMatch', { version: packageVersionRange }),
786
- );
787
- }
788
- } else {
789
- if (!pkgId) {
790
- if (nonInteractive) {
791
- throw new Error(t('packageIdRequired'));
792
- }
793
- // the package list was already fetched above: no second round trip
794
- pkgId = String((await choosePackage(appId, allPkgs)).id);
795
- }
796
-
797
- if (!pkgId) {
798
- throw new Error(t('packageIdRequired'));
799
- }
800
- const pkg = pkgMap.get(String(pkgId));
801
- if (pkg) {
802
- pkgsToBind = [pkg];
803
- } else {
804
- throw new Error(t('nativePackageIdNotFound', { id: pkgId }));
805
- }
806
- }
807
-
808
- if (options.warnDepsChanges && versionId) {
809
- await printDepsChangesForPublish({
810
- appId,
811
- versionId: String(versionId),
812
- pkgs: pkgsToBind,
813
- providedVersionDeps: options.versionDeps,
814
- });
815
- }
816
-
817
- await bindVersionToPackages({
818
- appId,
819
- // keep null as-is: `--versionId null` means unbinding the version
820
- versionId: versionId ?? null,
821
- pkgs: pkgsToBind,
822
- rollout,
823
- dryRun: options.dryRun,
824
- });
825
- },
826
- updateVersionInfo: async ({
827
- options,
828
- }: {
829
- options: VersionCommandOptions;
830
- }) => {
831
- const nonInteractive =
832
- getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
833
- const appId = await resolveAppId(options);
834
-
835
- let versionId = options.versionId;
836
- if (!versionId) {
837
- if (nonInteractive) {
838
- throw new Error(t('versionIdRequired'));
839
- }
840
- versionId = String((await chooseVersion(appId)).id);
841
- }
842
-
843
- const updateParams: Record<string, string> = {};
844
- if (options.name) updateParams.name = options.name;
845
- if (options.description) updateParams.description = options.description;
846
- if (options.metaInfo) updateParams.metaInfo = options.metaInfo;
847
-
848
- await put(`/app/${appId}/version/${versionId}`, updateParams);
849
- console.log(t('operationSuccess'));
850
- },
851
- deleteVersion: async ({ options }: { options: VersionCommandOptions }) => {
852
- const nonInteractive =
853
- getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
854
- const appId = await resolveAppId(options);
855
-
856
- const parsedVersionIds =
857
- getStringListOption(options, 'versionIds') ??
858
- getStringListOption(options, 'versionId');
859
- let versionIds = parsedVersionIds;
860
- if (!versionIds) {
861
- if (nonInteractive) {
862
- throw new Error(t('versionIdRequired'));
863
- }
864
- versionIds = [String((await chooseVersion(appId)).id)];
865
- }
866
-
867
- try {
868
- if (versionIds.length === 1) {
869
- const [versionId] = versionIds;
870
- await doDelete(`/app/${appId}/version/${versionId}`);
871
- console.log(t('deleteVersionSuccess', { versionId }));
872
- } else {
873
- await doDelete(`/app/${appId}/version`, {
874
- versionIds: toNumericIds(versionIds),
875
- });
876
- console.log(
877
- t('deleteVersionsSuccess', {
878
- count: versionIds.length,
879
- versionIds: versionIds.join(', '),
880
- }),
881
- );
882
- }
883
- } catch (error: any) {
884
- throw new Error(
885
- t('deleteVersionError', {
886
- versionId: versionIds.join(', '),
887
- error: error.message,
888
- }),
889
- );
890
- }
891
- },
892
- };