react-native-update-cli 2.23.0 → 2.24.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/src/bundle.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { getPlatform, getSelectedApp } from './app';
2
+ import { AppNotSelectedError, getPlatform, resolveAppId } from './app';
3
3
  import { packBundle } from './bundle-pack';
4
4
  import {
5
5
  copyDebugidForSentry,
@@ -41,6 +41,8 @@ type NormalizedBundleOptions = {
41
41
  verifyHermesBase: boolean;
42
42
  resetCache: boolean;
43
43
  cacheMaxMb?: number;
44
+ appId?: string;
45
+ config?: string;
44
46
  name?: string;
45
47
  description?: string;
46
48
  metaInfo?: string;
@@ -55,12 +57,14 @@ type NormalizedBundleOptions = {
55
57
  sentryDist?: string;
56
58
  };
57
59
 
60
+ /** Parse a positive cache-size option expressed in megabytes. */
58
61
  function parseCacheMaxMb(value: unknown): number | undefined {
59
62
  const parsed = typeof value === 'string' ? Number(value) : (value as number);
60
63
  return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
61
64
  }
62
65
 
63
66
  type PublishBundlePayload = {
67
+ appId: string;
64
68
  name?: string;
65
69
  description?: string;
66
70
  metaInfo?: string;
@@ -76,6 +80,7 @@ type PublishBundlePayload = {
76
80
  sourcemap?: string;
77
81
  };
78
82
 
83
+ /** Read either spelling of an aliased optional CLI string option. */
79
84
  function getAliasedOptionalStringOption(
80
85
  options: Record<string, unknown>,
81
86
  key: string,
@@ -87,6 +92,7 @@ function getAliasedOptionalStringOption(
87
92
  );
88
93
  }
89
94
 
95
+ /** Normalize translated CLI values into the bundle command's typed options. */
90
96
  export function normalizeBundleOptions(
91
97
  translatedOptions: Record<string, unknown>,
92
98
  platform: string,
@@ -125,6 +131,8 @@ export function normalizeBundleOptions(
125
131
  ),
126
132
  resetCache: getBooleanOption(translatedOptions, 'resetCache', true),
127
133
  cacheMaxMb: parseCacheMaxMb(translatedOptions.cacheMaxMb),
134
+ appId: getOptionalStringOption(translatedOptions, 'appId'),
135
+ config: getOptionalStringOption(translatedOptions, 'config'),
128
136
  name: getOptionalStringOption(translatedOptions, 'name'),
129
137
  description: getOptionalStringOption(translatedOptions, 'description'),
130
138
  metaInfo: getOptionalStringOption(translatedOptions, 'metaInfo'),
@@ -160,6 +168,7 @@ export function normalizeBundleOptions(
160
168
  };
161
169
  }
162
170
 
171
+ /** Upload generated Sentry artifacts when the detected plugin requires them. */
163
172
  async function uploadSentryArtifactsIfNeeded(
164
173
  shouldUpload: boolean,
165
174
  bundleName: string,
@@ -182,6 +191,7 @@ async function uploadSentryArtifactsIfNeeded(
182
191
  );
183
192
  }
184
193
 
194
+ /** Publish a packed bundle through the version command implementation. */
185
195
  async function publishBundleVersion(
186
196
  outputPath: string,
187
197
  platform: Platform,
@@ -197,6 +207,7 @@ async function publishBundleVersion(
197
207
  }
198
208
 
199
209
  export const bundleCommands = {
210
+ /** Build a bundle and optionally publish it to one operation-scoped app. */
200
211
  bundle: async ({
201
212
  options,
202
213
  }: {
@@ -214,10 +225,48 @@ export const bundleCommands = {
214
225
  });
215
226
  const normalized = normalizeBundleOptions(translatedOptions, platform);
216
227
 
228
+ // One app per operation: the Hermes base lookup and the publish step must
229
+ // never see different apps, so the target is resolved once and reused.
230
+ let appId: string | undefined;
231
+ const getAppId = async () =>
232
+ (appId ??= await resolveAppId({
233
+ appId: normalized.appId,
234
+ config: normalized.config,
235
+ platform,
236
+ }));
237
+ const hermesBase =
238
+ normalized.dev === 'true'
239
+ ? undefined
240
+ : {
241
+ option: normalized.hermesBase,
242
+ verify: normalized.verifyHermesBase,
243
+ cacheMaxMb: normalized.cacheMaxMb,
244
+ };
245
+
246
+ // Resolve before any side effect or expensive work. A named bundle is
247
+ // published, so a missing app fails right here; a bundle-only run only
248
+ // needs the app for the remote Hermes base lookup and may go on without
249
+ // one (it then compiles a full bundle). Any other config error (e.g.
250
+ // malformed JSON) is reported immediately either way.
251
+ if (normalized.name) {
252
+ await getAppId();
253
+ } else if (hermesBase?.option === 'auto') {
254
+ try {
255
+ await getAppId();
256
+ } catch (error) {
257
+ if (!(error instanceof AppNotSelectedError)) {
258
+ throw error;
259
+ }
260
+ }
261
+ }
262
+
217
263
  checkLockFiles();
218
264
  addGitIgnore();
219
265
 
220
- const bundleParams = await checkPlugins();
266
+ const [bundleParams] = await Promise.all([
267
+ checkPlugins(),
268
+ cleanStaleTmp().catch(() => {}),
269
+ ]);
221
270
  const sourcemapOutput = path.join(
222
271
  normalized.intermediaDir,
223
272
  `${normalized.bundleName}.map`,
@@ -233,23 +282,6 @@ export const bundleCommands = {
233
282
 
234
283
  console.log(t('bundlingWithRN', { version: depVersions['react-native'] }));
235
284
 
236
- await cleanStaleTmp().catch(() => {});
237
- // the hermes base lookup needs the app; resolve it up front but never
238
- // fail the bundle over it (publishing resolves it again and reports)
239
- let appIdForBase: string | undefined =
240
- typeof options.appId === 'string' && options.appId
241
- ? options.appId
242
- : undefined;
243
- if (!appIdForBase && normalized.hermesBase === 'auto') {
244
- try {
245
- appIdForBase = (
246
- await getSelectedApp(platform, options.config as string | undefined)
247
- ).appId;
248
- } catch {
249
- appIdForBase = undefined;
250
- }
251
- }
252
-
253
285
  const hermesResult = await runReactNativeBundleCommand({
254
286
  bundleName: normalized.bundleName,
255
287
  dev: normalized.dev,
@@ -259,15 +291,7 @@ export const bundleCommands = {
259
291
  sourcemapOutput:
260
292
  normalized.sourcemap || bundleParams.sourcemap ? sourcemapOutput : '',
261
293
  forceHermes: normalized.hermes,
262
- hermesBase:
263
- normalized.dev === 'true'
264
- ? undefined
265
- : {
266
- option: normalized.hermesBase,
267
- appId: appIdForBase,
268
- verify: normalized.verifyHermesBase,
269
- cacheMaxMb: normalized.cacheMaxMb,
270
- },
294
+ hermesBase: hermesBase ? { ...hermesBase, appId } : undefined,
271
295
  resetCache: normalized.resetCache,
272
296
  cli: {
273
297
  taro: normalized.taro,
@@ -288,6 +312,7 @@ export const bundleCommands = {
288
312
 
289
313
  if (normalized.name) {
290
314
  await publishBundleVersion(realOutput, platform, {
315
+ appId: await getAppId(),
291
316
  name: normalized.name,
292
317
  description: normalized.description,
293
318
  metaInfo: normalized.metaInfo,
@@ -322,6 +347,7 @@ export const bundleCommands = {
322
347
  const v = await question(t('uploadBundlePrompt'));
323
348
  if (v.toLowerCase() === 'y') {
324
349
  await publishBundleVersion(realOutput, platform, {
350
+ appId: await getAppId(),
325
351
  hermesBase: baseMeta,
326
352
  sourcemap:
327
353
  normalized.sourcemap || bundleParams.sourcemap
package/src/locales/en.ts CHANGED
@@ -16,23 +16,29 @@ export default {
16
16
  aabParseResourcesError: 'Parser resources.arsc error: {{error}}',
17
17
  appId: 'App ID',
18
18
  appIdMismatchApk:
19
- 'App ID mismatch! Current APK: {{appIdInPkg}}, current update.json: {{appId}}',
19
+ 'App ID mismatch! Current APK: {{appIdInPkg}}, current {{- source}}: {{appId}}',
20
20
  appIdMismatchApp:
21
- 'App ID mismatch! Current APP: {{appIdInPkg}}, current update.json: {{appId}}',
21
+ 'App ID mismatch! Current APP: {{appIdInPkg}}, current {{- source}}: {{appId}}',
22
22
  appIdMismatchIpa:
23
- 'App ID mismatch! Current IPA: {{appIdInPkg}}, current update.json: {{appId}}',
23
+ 'App ID mismatch! Current IPA: {{appIdInPkg}}, current {{- source}}: {{appId}}',
24
24
  appKeyMismatchApk:
25
- 'App Key mismatch! Current APK: {{appKeyInPkg}}, current update.json: {{appKey}}',
25
+ 'App Key mismatch! Current APK: {{appKeyInPkg}}, current {{- source}}: {{appKey}}',
26
26
  appKeyMismatchApp:
27
- 'App Key mismatch! Current APP: {{appKeyInPkg}}, current update.json: {{appKey}}',
27
+ 'App Key mismatch! Current APP: {{appKeyInPkg}}, current {{- source}}: {{appKey}}',
28
28
  appKeyMismatchIpa:
29
- 'App Key mismatch! Current IPA: {{appKeyInPkg}}, current update.json: {{appKey}}',
29
+ 'App Key mismatch! Current IPA: {{appKeyInPkg}}, current {{- source}}: {{appKey}}',
30
30
  appName: 'App Name',
31
31
  appNameQuestion: 'App Name:',
32
+ appPlatformMismatch:
33
+ 'App {{appId}} is a {{appPlatform}} app, but this command targets {{platform}}',
32
34
  appNotSelected:
33
35
  'App not selected. run `cresc selectApp --platform {{platform}}` first!',
34
36
  appUploadSuccess:
35
37
  'Successfully uploaded APP native package (id: {{id}}, version: {{version}}, buildTime: {{buildTime}})',
38
+ autoUpdatePermission:
39
+ 'CLI auto-update was skipped because the global package directory is not writable. Fix the package-manager prefix permissions, then run: {{- command}}',
40
+ autoUpdateSuccess:
41
+ 'CLI was automatically updated in the background: {{from}} -> {{to}}',
36
42
  apkUploadSuccess:
37
43
  'Successfully uploaded APK native package (id: {{id}}, version: {{version}}, buildTime: {{buildTime}})',
38
44
  boundTo: ', bound to: {{name}} ({{id}})',
@@ -57,7 +63,7 @@ export default {
57
63
  expiredStatus: '(Expired)',
58
64
  failedToParseIcon: '[Warning] failed to parse icon: {{error}}',
59
65
  failedToParseUpdateJson:
60
- 'Failed to parse file `update.json`. Try to remove it manually.',
66
+ 'Failed to parse file `{{- configPath}}`. Try to remove it manually.',
61
67
  fileGenerated: '{{- file}} generated.',
62
68
  fileSizeExceeded:
63
69
  'This file size is {{fileSize}} , exceeding the current quota {{maxSize}} . You may consider upgrading to a higher plan to increase this quota. Details can be found at: {{- pricingPageUrl}}',
package/src/locales/zh.ts CHANGED
@@ -14,23 +14,28 @@ export default {
14
14
  aabParseResourcesError: '解析 resources.arsc 出错:{{error}}',
15
15
  appId: '应用 id',
16
16
  appIdMismatchApk:
17
- 'appId不匹配!当前apk: {{appIdInPkg}}, 当前update.json: {{appId}}',
17
+ 'appId不匹配!当前apk: {{appIdInPkg}}, 当前{{- source}}: {{appId}}',
18
18
  appIdMismatchApp:
19
- 'appId不匹配!当前app: {{appIdInPkg}}, 当前update.json: {{appId}}',
19
+ 'appId不匹配!当前app: {{appIdInPkg}}, 当前{{- source}}: {{appId}}',
20
20
  appIdMismatchIpa:
21
- 'appId不匹配!当前ipa: {{appIdInPkg}}, 当前update.json: {{appId}}',
21
+ 'appId不匹配!当前ipa: {{appIdInPkg}}, 当前{{- source}}: {{appId}}',
22
22
  appKeyMismatchApk:
23
- 'appKey不匹配!当前apk: {{appKeyInPkg}}, 当前update.json: {{appKey}}',
23
+ 'appKey不匹配!当前apk: {{appKeyInPkg}}, 当前{{- source}}: {{appKey}}',
24
24
  appKeyMismatchApp:
25
- 'appKey不匹配!当前app: {{appKeyInPkg}}, 当前update.json: {{appKey}}',
25
+ 'appKey不匹配!当前app: {{appKeyInPkg}}, 当前{{- source}}: {{appKey}}',
26
26
  appKeyMismatchIpa:
27
- 'appKey不匹配!当前ipa: {{appKeyInPkg}}, 当前update.json: {{appKey}}',
27
+ 'appKey不匹配!当前ipa: {{appKeyInPkg}}, 当前{{- source}}: {{appKey}}',
28
28
  appName: '应用名称',
29
29
  appNameQuestion: '应用名称:',
30
+ appPlatformMismatch:
31
+ '应用 {{appId}} 是 {{appPlatform}} 平台的应用,但当前命令的平台是 {{platform}}',
30
32
  appNotSelected:
31
33
  '尚未选择应用。请先运行 `pushy selectApp --platform {{platform}}` 来选择应用',
32
34
  appUploadSuccess:
33
35
  '已成功上传app原生包(id: {{id}}, version: {{version}}, buildTime: {{buildTime}})',
36
+ autoUpdatePermission:
37
+ 'CLI 自动更新已跳过:全局包目录不可写。请修复包管理器的全局目录权限后运行:{{- command}}',
38
+ autoUpdateSuccess: 'CLI 已在后台自动更新:{{from}} -> {{to}}',
34
39
  apkUploadSuccess:
35
40
  '已成功上传apk原生包(id: {{id}}, version: {{version}}, buildTime: {{buildTime}})',
36
41
  boundTo: ', 已绑定:{{name}} ({{id}})',
@@ -53,7 +58,7 @@ export default {
53
58
  errorInHarmonyApp: '获取 Harmony 应用入口时出错:{{error}}',
54
59
  expiredStatus: '(已过期)',
55
60
  failedToParseIcon: '[警告] 解析图标失败:{{error}}',
56
- failedToParseUpdateJson: '无法解析文件 `update.json`。请手动删除它。',
61
+ failedToParseUpdateJson: '无法解析文件 `{{- configPath}}`。请手动删除它。',
57
62
  fileGenerated: '已生成 {{- file}}',
58
63
  fileSizeExceeded:
59
64
  '此文件大小 {{fileSize}} , 超出当前额度 {{maxSize}} 。您可以考虑升级付费业务以提升此额度。详情请访问: {{- pricingPageUrl}}',
package/src/package.ts CHANGED
@@ -2,7 +2,7 @@ import * as fs from 'fs-extra';
2
2
  import os from 'os';
3
3
  import path from 'path';
4
4
  import { doDelete, getAllPackages, post, uploadFile } from './api';
5
- import { getPlatform, getSelectedApp } from './app';
5
+ import { getSelectedApp, resolveAppId } from './app';
6
6
  import { createSlimNativePackage } from './native-package';
7
7
  import type { Package, Platform } from './types';
8
8
  import {
@@ -13,6 +13,7 @@ import {
13
13
  loadTtyTable,
14
14
  question,
15
15
  } from './utils';
16
+ import { updateJson } from './utils/constants';
16
17
  import { getDepVersions } from './utils/dep-versions';
17
18
  import { getCommitInfo } from './utils/git';
18
19
  import { bundleEntryMatcher, cachePut } from './utils/hermes-base';
@@ -23,6 +24,7 @@ import { bundleLocationFields, locateZipEntry } from './utils/zip-range';
23
24
  type PackageCommandOptions = Record<string, unknown> & {
24
25
  appId?: string;
25
26
  appKey?: string;
27
+ config?: string;
26
28
  platform?: Platform;
27
29
  version?: string;
28
30
  packageId?: string;
@@ -130,18 +132,19 @@ async function uploadNativePackage(
130
132
  appId: String(options.appId),
131
133
  appKey: typeof options.appKey === 'string' ? options.appKey : undefined,
132
134
  }
133
- : await getSelectedApp(
134
- config.platform,
135
- options.config as string | undefined,
136
- );
135
+ : await getSelectedApp(config.platform, options.config);
137
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;
138
139
 
139
140
  if (appIdInPkg && String(appIdInPkg) !== appId) {
140
- throw new Error(t(config.appIdMismatchKey, { appIdInPkg, appId }));
141
+ throw new Error(t(config.appIdMismatchKey, { appIdInPkg, appId, source }));
141
142
  }
142
143
 
143
144
  if (appKeyInPkg && appKey && appKeyInPkg !== appKey) {
144
- throw new Error(t(config.appKeyMismatchKey, { appKeyInPkg, appKey }));
145
+ throw new Error(
146
+ t(config.appKeyMismatchKey, { appKeyInPkg, appKey, source }),
147
+ );
145
148
  }
146
149
 
147
150
  const customVersion =
@@ -407,28 +410,14 @@ export const packageCommands = {
407
410
  }: {
408
411
  options: { platform: Platform; appId?: string; config?: string };
409
412
  }) => {
410
- let appId = options.appId;
411
- if (!appId) {
412
- const platform = await getPlatform(options.platform);
413
- appId = (
414
- await getSelectedApp(platform, options.config as string | undefined)
415
- ).appId;
416
- }
417
- await listPackage(String(appId));
413
+ await listPackage(await resolveAppId(options));
418
414
  },
419
415
  deletePackage: async ({ options }: { options: PackageCommandOptions }) => {
420
- let { appId } = options;
416
+ const appId = await resolveAppId(options);
421
417
  let packageIds =
422
418
  getStringListOption(options, 'packageIds') ??
423
419
  getStringListOption(options, 'packageId');
424
420
 
425
- if (!appId) {
426
- const platform = await getPlatform(options.platform);
427
- appId = (
428
- await getSelectedApp(platform, options.config as string | undefined)
429
- ).appId;
430
- }
431
-
432
421
  if (!packageIds) {
433
422
  const packageVersions = getStringListOption(options, 'packageVersion');
434
423
  if (!packageVersions) {
package/src/provider.ts CHANGED
@@ -96,6 +96,8 @@ export class CLIProviderImpl implements CLIProvider {
96
96
  verifyHermesBase: options.verifyHermesBase ?? true,
97
97
  sentryRelease: options.sentryRelease,
98
98
  sentryDist: options.sentryDist,
99
+ appId: options.appId,
100
+ config: options.config,
99
101
  });
100
102
 
101
103
  const { bundleCommands } = await import('./bundle');
@@ -205,9 +207,10 @@ export class CLIProviderImpl implements CLIProvider {
205
207
 
206
208
  async getSelectedApp(
207
209
  platform?: Platform,
210
+ config?: string,
208
211
  ): Promise<{ appId: string; platform: Platform }> {
209
212
  const resolvedPlatform = await this.getPlatform(platform);
210
- return getSelectedApp(resolvedPlatform);
213
+ return getSelectedApp(resolvedPlatform, config);
211
214
  }
212
215
 
213
216
  async listApps(platform?: Platform): Promise<CommandResult> {
package/src/types.ts CHANGED
@@ -67,6 +67,10 @@ export interface BundleOptions {
67
67
  resetCache?: boolean;
68
68
  sentryRelease?: string;
69
69
  sentryDist?: string;
70
+ /** publish to this app instead of the one selected in the config file */
71
+ appId?: string;
72
+ /** selected-app config file (default: update.json) */
73
+ config?: string;
70
74
  }
71
75
 
72
76
  export interface PublishOptions {
@@ -131,6 +135,7 @@ export interface CLIProvider {
131
135
  listApps: (platform?: Platform) => Promise<CommandResult>;
132
136
  getSelectedApp: (
133
137
  platform?: Platform,
138
+ config?: string,
134
139
  ) => Promise<{ appId: string; platform: Platform }>;
135
140
 
136
141
  listVersions: (appId: string) => Promise<CommandResult>;
@@ -12,7 +12,9 @@ export const isPPKBundleFileName = (fileName: string) =>
12
12
  ppkBundleFileNames.includes(fileName);
13
13
 
14
14
  export const credentialFile = IS_CRESC ? '.cresc.token' : '.update';
15
- export const updateJson = IS_CRESC ? 'cresc.config.json' : 'update.json';
15
+ // Both brands select apps in update.json: the cresc docs and the client SDK
16
+ // (`import _updateConfig from './update.json'`) read that name too.
17
+ export const updateJson = 'update.json';
16
18
  export const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';
17
19
  export const pricingPageUrl = IS_CRESC
18
20
  ? 'https://cresc.dev/pricing'
@@ -560,6 +560,8 @@ export interface VersionCheck {
560
560
  done: Promise<void>;
561
561
  /** wait for the check, but never longer than `graceMs` */
562
562
  settle: (graceMs: number) => Promise<void>;
563
+ /** launch a detached self-update after the foreground command is done */
564
+ startAutoUpdate: () => void;
563
565
  /**
564
566
  * Print the "newer version available" hints if the check has completed by
565
567
  * now; a no-op while it is still pending, when nothing is newer, and after
@@ -597,6 +599,27 @@ export async function printVersionCommand({
597
599
  console.log(
598
600
  `react-native-update-cli: ${pkg.version}${latestTag(latestCliVersion)}`,
599
601
  );
602
+ try {
603
+ const { consumeAutoUpdateNotice } =
604
+ require('../auto-update') as typeof import('../auto-update');
605
+ const notice = consumeAutoUpdateNotice(pkg.version);
606
+ if (notice?.kind === 'updated') {
607
+ console.log(
608
+ t('autoUpdateSuccess', {
609
+ from: notice.currentVersion,
610
+ to: notice.targetVersion,
611
+ }),
612
+ );
613
+ } else if (notice?.kind === 'permission') {
614
+ console.warn(
615
+ t('autoUpdatePermission', {
616
+ command: notice.command,
617
+ }),
618
+ );
619
+ }
620
+ } catch {
621
+ // A corrupt/unwritable updater cache cannot affect normal commands.
622
+ }
600
623
  if (rnuVersion) {
601
624
  console.log(
602
625
  `react-native-update: ${rnuVersion}${latestTag(latestRnuVersion)}`,
@@ -654,7 +677,22 @@ export async function printVersionCommand({
654
677
  return Promise.race([check, grace]).then(() => clearTimeout(timer));
655
678
  };
656
679
 
657
- return { done: check, settle, printHints };
680
+ let autoUpdateStarted = false;
681
+ const startAutoUpdate = () => {
682
+ if (autoUpdateStarted || !isNewer(latest?.[0], pkg.version)) {
683
+ return;
684
+ }
685
+ autoUpdateStarted = true;
686
+ try {
687
+ const { launchAutoUpdate } =
688
+ require('../auto-update') as typeof import('../auto-update');
689
+ launchAutoUpdate(pkg.version, latest?.[0]);
690
+ } catch {
691
+ // Self-update is strictly opportunistic and never affects the command.
692
+ }
693
+ };
694
+
695
+ return { done: check, settle, startAutoUpdate, printHints };
658
696
  }
659
697
 
660
698
  export { checkPlugins };
package/src/versions.ts CHANGED
@@ -2,7 +2,7 @@ import chalk from 'chalk';
2
2
  import { compare, satisfies } from 'compare-versions';
3
3
  import fs from 'fs';
4
4
  import { doDelete, get, getAllPackages, post, put, uploadFile } from './api';
5
- import { getPlatform, getSelectedApp } from './app';
5
+ import { getPlatform, resolveAppId } from './app';
6
6
  import { choosePackage } from './package';
7
7
  import type { Package, Platform, Version } from './types';
8
8
  import { isNonInteractive, loadTtyTable, question } from './utils';
@@ -525,12 +525,7 @@ export const versionCommands = {
525
525
  }
526
526
 
527
527
  const platform = await getPlatform(options.platform);
528
- let appId = options.appId;
529
- if (!appId) {
530
- appId = (
531
- await getSelectedApp(platform, options.config as string | undefined)
532
- ).appId;
533
- }
528
+ const appId = await resolveAppId({ ...options, platform });
534
529
  const nonInteractive =
535
530
  getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
536
531
 
@@ -631,6 +626,7 @@ export const versionCommands = {
631
626
  options: {
632
627
  versionId: id,
633
628
  platform,
629
+ appId,
634
630
  packageId,
635
631
  packageVersion,
636
632
  packageVersionRange,
@@ -649,6 +645,7 @@ export const versionCommands = {
649
645
  options: {
650
646
  versionId: id,
651
647
  platform,
648
+ appId,
652
649
  versionDeps: depVersions,
653
650
  warnDepsChanges: true,
654
651
  },
@@ -658,38 +655,23 @@ export const versionCommands = {
658
655
  return versionName;
659
656
  },
660
657
  versions: async ({ options }: { options: VersionCommandOptions }) => {
661
- let appId = options.appId;
662
- if (!appId) {
663
- const platform = await getPlatform(options.platform);
664
- appId = (
665
- await getSelectedApp(platform, options.config as string | undefined)
666
- ).appId;
667
- }
658
+ const appId = await resolveAppId(options);
668
659
  const interactive = !(
669
660
  getBooleanOption(options, 'no-interactive', false) || isNonInteractive()
670
661
  );
671
- await listVersions(String(appId), interactive);
662
+ await listVersions(appId, interactive);
672
663
  },
673
664
  update: async ({ options }: { options: VersionCommandOptions }) => {
674
665
  const nonInteractive =
675
666
  getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
676
- let appId = options.appId;
677
- let platform = options.platform;
678
- if (!appId) {
679
- platform = await getPlatform(platform);
680
- appId = (
681
- await getSelectedApp(platform, options.config as string | undefined)
682
- ).appId;
683
- } else if (platform) {
684
- platform = await getPlatform(platform);
685
- }
667
+ const appId = await resolveAppId(options);
686
668
 
687
669
  let versionId: string | null | undefined = options.versionId;
688
670
  if (!versionId) {
689
671
  if (nonInteractive) {
690
672
  throw new Error(t('versionIdRequired'));
691
673
  }
692
- versionId = String((await chooseVersion(String(appId))).id);
674
+ versionId = String((await chooseVersion(appId)).id);
693
675
  }
694
676
  if (versionId === 'null') {
695
677
  versionId = null;
@@ -709,7 +691,7 @@ export const versionCommands = {
709
691
  }
710
692
  }
711
693
 
712
- const allPkgs = await getAllPackages(String(appId));
694
+ const allPkgs = await getAllPackages(appId);
713
695
 
714
696
  if (!allPkgs) {
715
697
  throw new Error(t('noPackagesFound', { appId }));
@@ -785,7 +767,7 @@ export const versionCommands = {
785
767
  throw new Error(t('packageIdRequired'));
786
768
  }
787
769
  // the package list was already fetched above: no second round trip
788
- pkgId = String((await choosePackage(String(appId), allPkgs)).id);
770
+ pkgId = String((await choosePackage(appId, allPkgs)).id);
789
771
  }
790
772
 
791
773
  if (!pkgId) {
@@ -801,7 +783,7 @@ export const versionCommands = {
801
783
 
802
784
  if (options.warnDepsChanges && versionId) {
803
785
  await printDepsChangesForPublish({
804
- appId: String(appId),
786
+ appId,
805
787
  versionId: String(versionId),
806
788
  pkgs: pkgsToBind,
807
789
  providedVersionDeps: options.versionDeps,
@@ -809,7 +791,7 @@ export const versionCommands = {
809
791
  }
810
792
 
811
793
  await bindVersionToPackages({
812
- appId: String(appId),
794
+ appId,
813
795
  // keep null as-is: `--versionId null` means unbinding the version
814
796
  versionId: versionId ?? null,
815
797
  pkgs: pkgsToBind,
@@ -824,23 +806,14 @@ export const versionCommands = {
824
806
  }) => {
825
807
  const nonInteractive =
826
808
  getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
827
- let appId = options.appId;
828
- let platform = options.platform;
829
- if (!appId) {
830
- platform = await getPlatform(platform);
831
- appId = (
832
- await getSelectedApp(platform, options.config as string | undefined)
833
- ).appId;
834
- } else if (platform) {
835
- await getPlatform(platform);
836
- }
809
+ const appId = await resolveAppId(options);
837
810
 
838
811
  let versionId = options.versionId;
839
812
  if (!versionId) {
840
813
  if (nonInteractive) {
841
814
  throw new Error(t('versionIdRequired'));
842
815
  }
843
- versionId = String((await chooseVersion(String(appId))).id);
816
+ versionId = String((await chooseVersion(appId)).id);
844
817
  }
845
818
 
846
819
  const updateParams: Record<string, string> = {};
@@ -848,19 +821,13 @@ export const versionCommands = {
848
821
  if (options.description) updateParams.description = options.description;
849
822
  if (options.metaInfo) updateParams.metaInfo = options.metaInfo;
850
823
 
851
- await put(`/app/${String(appId)}/version/${versionId}`, updateParams);
824
+ await put(`/app/${appId}/version/${versionId}`, updateParams);
852
825
  console.log(t('operationSuccess'));
853
826
  },
854
827
  deleteVersion: async ({ options }: { options: VersionCommandOptions }) => {
855
828
  const nonInteractive =
856
829
  getBooleanOption(options, 'no-interactive', false) || isNonInteractive();
857
- let appId = options.appId;
858
- if (!appId) {
859
- const platform = await getPlatform(options.platform);
860
- appId = (
861
- await getSelectedApp(platform, options.config as string | undefined)
862
- ).appId;
863
- }
830
+ const appId = await resolveAppId(options);
864
831
 
865
832
  const parsedVersionIds =
866
833
  getStringListOption(options, 'versionIds') ??
@@ -870,16 +837,16 @@ export const versionCommands = {
870
837
  if (nonInteractive) {
871
838
  throw new Error(t('versionIdRequired'));
872
839
  }
873
- versionIds = [String((await chooseVersion(String(appId))).id)];
840
+ versionIds = [String((await chooseVersion(appId)).id)];
874
841
  }
875
842
 
876
843
  try {
877
844
  if (versionIds.length === 1) {
878
845
  const [versionId] = versionIds;
879
- await doDelete(`/app/${String(appId)}/version/${versionId}`);
846
+ await doDelete(`/app/${appId}/version/${versionId}`);
880
847
  console.log(t('deleteVersionSuccess', { versionId }));
881
848
  } else {
882
- await doDelete(`/app/${String(appId)}/version`, {
849
+ await doDelete(`/app/${appId}/version`, {
883
850
  versionIds: toNumericIds(versionIds),
884
851
  });
885
852
  console.log(