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/versions.ts DELETED
@@ -1,894 +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 { slimSourceMap } 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 copy: relative paths, no dependency sourcesContent
550
- // (see slimSourceMap). Frames keep symbolicating everywhere; only inline
551
- // snippets of node_modules code are dropped, and the map shrinks by the
552
- // bulk of its bytes. If the file is not a plain map, upload it untouched.
553
- let uploadSourcemapPath = sourcemapPath;
554
- let slimTempDir: string | undefined;
555
- if (sourcemapPath) {
556
- const slimmed = slimSourceMap(
557
- fs.readFileSync(sourcemapPath, 'utf8'),
558
- process.cwd(),
559
- );
560
- if (slimmed !== null) {
561
- slimTempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rnu-sourcemap-'));
562
- uploadSourcemapPath = path.join(
563
- slimTempDir,
564
- path.basename(sourcemapPath),
565
- );
566
- fs.writeFileSync(uploadSourcemapPath, slimmed);
567
- }
568
- }
569
-
570
- // Hashing/caching the bundle and asking git for the commit are independent
571
- // of the upload, so they overlap with it instead of running afterwards.
572
- // describePpkBundle never rejects (best effort); a failed upload still
573
- // fails the publish exactly as before.
574
- // A server that predates source-map archiving (self-hosted, or a SaaS
575
- // region not yet rolled) rejects the .map upload with 400; that must not
576
- // fail the publish, only lose the archive.
577
- let sourceMapUploadError: unknown;
578
- const [{ hash }, bundleMeta, commit, sourceMapUpload] = await Promise.all([
579
- uploadFile(fn, undefined, appId),
580
- describePpkBundle(fn, options.hermesBase),
581
- getCommitInfo(),
582
- uploadSourcemapPath
583
- ? uploadFile(uploadSourcemapPath, undefined, appId).catch(
584
- (error: unknown) => {
585
- sourceMapUploadError = error;
586
- return undefined;
587
- },
588
- )
589
- : Promise.resolve(undefined),
590
- ]);
591
- if (slimTempDir) {
592
- fs.rmSync(slimTempDir, { recursive: true, force: true });
593
- }
594
- const sourceMapKey = sourceMapUpload?.hash;
595
- if (sourcemapPath && !sourceMapKey) {
596
- console.log(
597
- chalk.yellow(
598
- t('sourceMapUploadFailedWarning', {
599
- error:
600
- sourceMapUploadError instanceof Error
601
- ? sourceMapUploadError.message
602
- : String(sourceMapUploadError),
603
- }),
604
- ),
605
- );
606
- }
607
- const depVersions = getDepVersions();
608
-
609
- const versionName =
610
- name ||
611
- (nonInteractive ? '' : await question(t('versionNameQuestion'))) ||
612
- t('unnamed');
613
- const { id } = await post(`/app/${appId}/version/create`, {
614
- name: versionName,
615
- hash,
616
- description:
617
- description ??
618
- (nonInteractive ? '' : await question(t('versionDescriptionQuestion'))),
619
- metaInfo:
620
- metaInfo ??
621
- (nonInteractive ? '' : await question(t('versionMetaInfoQuestion'))),
622
- deps: depVersions,
623
- commit,
624
- // Hermes delta-mode chain metadata (old servers drop unknown fields)
625
- ...bundleMeta,
626
- // archived source map (old servers drop unknown fields)
627
- ...(sourceMapKey ? { sourceMapKey } : {}),
628
- });
629
- console.log(t('packageUploadSuccess', { id }));
630
- if (sourceMapKey) {
631
- console.log(t('sourceMapArchived', { id }));
632
- }
633
-
634
- const {
635
- packageId,
636
- packageVersion,
637
- packageVersionRange,
638
- minPackageVersion,
639
- maxPackageVersion,
640
- rollout,
641
- dryRun,
642
- } = options;
643
-
644
- if (
645
- packageId ||
646
- packageVersion ||
647
- packageVersionRange ||
648
- minPackageVersion ||
649
- maxPackageVersion
650
- ) {
651
- await versionCommands.update({
652
- options: {
653
- versionId: id,
654
- platform,
655
- appId,
656
- packageId,
657
- packageVersion,
658
- packageVersionRange,
659
- minPackageVersion,
660
- maxPackageVersion,
661
- rollout,
662
- dryRun,
663
- versionDeps: depVersions,
664
- warnDepsChanges: true,
665
- },
666
- });
667
- } else if (!nonInteractive) {
668
- const q = await question(t('updateNativePackageQuestion'));
669
- if (q.toLowerCase() === 'y') {
670
- await versionCommands.update({
671
- options: {
672
- versionId: id,
673
- platform,
674
- appId,
675
- versionDeps: depVersions,
676
- warnDepsChanges: true,
677
- },
678
- });
679
- }
680
- }
681
- return versionName;
682
- },
683
- versions: async ({ options }: { options: VersionCommandOptions }) => {
684
- const appId = await resolveAppId(options);
685
- const interactive = !(
686
- getBooleanOption(options, 'no-interactive', false) || isNonInteractive()
687
- );
688
- await listVersions(appId, interactive);
689
- },
690
- update: async ({ options }: { options: VersionCommandOptions }) => {
691
- const nonInteractive =
692
- getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
693
- const appId = await resolveAppId(options);
694
-
695
- let versionId: string | null | undefined = options.versionId;
696
- if (!versionId) {
697
- if (nonInteractive) {
698
- throw new Error(t('versionIdRequired'));
699
- }
700
- versionId = String((await chooseVersion(appId)).id);
701
- }
702
- if (versionId === 'null') {
703
- versionId = null;
704
- }
705
-
706
- let pkgId = options.packageId;
707
- let pkgVersion = options.packageVersion;
708
- let minPkgVersion = options.minPackageVersion;
709
- let maxPkgVersion = options.maxPackageVersion;
710
- let packageVersionRange = options.packageVersionRange;
711
- let rollout: number | undefined;
712
-
713
- if (options.rollout !== undefined) {
714
- rollout = Number.parseInt(String(options.rollout), 10);
715
- if (Number.isNaN(rollout) || rollout < 1 || rollout > 100) {
716
- throw new Error(t('rolloutRangeError'));
717
- }
718
- }
719
-
720
- const allPkgs = await getAllPackages(appId);
721
-
722
- if (!allPkgs) {
723
- throw new Error(t('noPackagesFound', { appId }));
724
- }
725
-
726
- const pkgMap = new Map(
727
- allPkgs.map((pkg: Package) => [String(pkg.id), pkg]),
728
- );
729
-
730
- let pkgsToBind: Package[] = [];
731
-
732
- const selectorGroups = [
733
- pkgId,
734
- pkgVersion,
735
- packageVersionRange,
736
- minPkgVersion || maxPkgVersion,
737
- ].filter(Boolean);
738
- if (selectorGroups.length > 1) {
739
- throw new Error(t('conflictingPackageSelectors'));
740
- }
741
-
742
- if (minPkgVersion || maxPkgVersion) {
743
- minPkgVersion = minPkgVersion && String(minPkgVersion).trim();
744
- maxPkgVersion = maxPkgVersion && String(maxPkgVersion).trim();
745
- pkgsToBind = allPkgs.filter((pkg: Package) => {
746
- const aboveMin =
747
- !minPkgVersion || compare(pkg.name, minPkgVersion, '>=');
748
- const belowMax =
749
- !maxPkgVersion || compare(pkg.name, maxPkgVersion, '<=');
750
- return aboveMin && belowMax;
751
- });
752
- if (pkgsToBind.length === 0) {
753
- if (minPkgVersion && maxPkgVersion) {
754
- throw new Error(
755
- t('nativeVersionNotFoundBetween', {
756
- min: minPkgVersion,
757
- max: maxPkgVersion,
758
- }),
759
- );
760
- }
761
- if (minPkgVersion) {
762
- throw new Error(
763
- t('nativeVersionNotFoundGte', { version: minPkgVersion }),
764
- );
765
- }
766
- throw new Error(
767
- t('nativeVersionNotFoundLte', { version: maxPkgVersion }),
768
- );
769
- }
770
- } else if (pkgVersion) {
771
- pkgVersion = pkgVersion.trim();
772
- const pkg = allPkgs.find((pkg: Package) => pkg.name === pkgVersion);
773
- if (pkg) {
774
- pkgsToBind = [pkg];
775
- } else {
776
- throw new Error(
777
- t('nativeVersionNotFoundMatch', { version: pkgVersion }),
778
- );
779
- }
780
- } else if (packageVersionRange) {
781
- packageVersionRange = packageVersionRange.trim();
782
- pkgsToBind = allPkgs.filter((pkg: Package) =>
783
- satisfies(pkg.name, packageVersionRange!),
784
- );
785
- if (pkgsToBind.length === 0) {
786
- throw new Error(
787
- t('nativeVersionNotFoundMatch', { version: packageVersionRange }),
788
- );
789
- }
790
- } else {
791
- if (!pkgId) {
792
- if (nonInteractive) {
793
- throw new Error(t('packageIdRequired'));
794
- }
795
- // the package list was already fetched above: no second round trip
796
- pkgId = String((await choosePackage(appId, allPkgs)).id);
797
- }
798
-
799
- if (!pkgId) {
800
- throw new Error(t('packageIdRequired'));
801
- }
802
- const pkg = pkgMap.get(String(pkgId));
803
- if (pkg) {
804
- pkgsToBind = [pkg];
805
- } else {
806
- throw new Error(t('nativePackageIdNotFound', { id: pkgId }));
807
- }
808
- }
809
-
810
- if (options.warnDepsChanges && versionId) {
811
- await printDepsChangesForPublish({
812
- appId,
813
- versionId: String(versionId),
814
- pkgs: pkgsToBind,
815
- providedVersionDeps: options.versionDeps,
816
- });
817
- }
818
-
819
- await bindVersionToPackages({
820
- appId,
821
- // keep null as-is: `--versionId null` means unbinding the version
822
- versionId: versionId ?? null,
823
- pkgs: pkgsToBind,
824
- rollout,
825
- dryRun: options.dryRun,
826
- });
827
- },
828
- updateVersionInfo: async ({
829
- options,
830
- }: {
831
- options: VersionCommandOptions;
832
- }) => {
833
- const nonInteractive =
834
- getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
835
- const appId = await resolveAppId(options);
836
-
837
- let versionId = options.versionId;
838
- if (!versionId) {
839
- if (nonInteractive) {
840
- throw new Error(t('versionIdRequired'));
841
- }
842
- versionId = String((await chooseVersion(appId)).id);
843
- }
844
-
845
- const updateParams: Record<string, string> = {};
846
- if (options.name) updateParams.name = options.name;
847
- if (options.description) updateParams.description = options.description;
848
- if (options.metaInfo) updateParams.metaInfo = options.metaInfo;
849
-
850
- await put(`/app/${appId}/version/${versionId}`, updateParams);
851
- console.log(t('operationSuccess'));
852
- },
853
- deleteVersion: async ({ options }: { options: VersionCommandOptions }) => {
854
- const nonInteractive =
855
- getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
856
- const appId = await resolveAppId(options);
857
-
858
- const parsedVersionIds =
859
- getStringListOption(options, 'versionIds') ??
860
- getStringListOption(options, 'versionId');
861
- let versionIds = parsedVersionIds;
862
- if (!versionIds) {
863
- if (nonInteractive) {
864
- throw new Error(t('versionIdRequired'));
865
- }
866
- versionIds = [String((await chooseVersion(appId)).id)];
867
- }
868
-
869
- try {
870
- if (versionIds.length === 1) {
871
- const [versionId] = versionIds;
872
- await doDelete(`/app/${appId}/version/${versionId}`);
873
- console.log(t('deleteVersionSuccess', { versionId }));
874
- } else {
875
- await doDelete(`/app/${appId}/version`, {
876
- versionIds: toNumericIds(versionIds),
877
- });
878
- console.log(
879
- t('deleteVersionsSuccess', {
880
- count: versionIds.length,
881
- versionIds: versionIds.join(', '),
882
- }),
883
- );
884
- }
885
- } catch (error: any) {
886
- throw new Error(
887
- t('deleteVersionError', {
888
- versionId: versionIds.join(', '),
889
- error: error.message,
890
- }),
891
- );
892
- }
893
- },
894
- };