react-native-update-cli 2.23.0 → 2.23.1

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/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'
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(