Skip to content

Commit

Permalink
use version gating
Browse files Browse the repository at this point in the history
  • Loading branch information
wschurman committed Mar 7, 2024
1 parent 7c1d66c commit 3d9d111
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 36 deletions.
16 changes: 16 additions & 0 deletions packages/eas-cli/src/project/projectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ export async function isClassicUpdatesSupportedAsync(projectDir: string): Promis
return semver.lt(expoUpdatesPackageVersion, '0.19.0');
}

export async function isModernExpoUpdatesCLIWithRuntimeVersionCommandSupportedAsync(
projectDir: string
): Promise<boolean> {
const expoUpdatesPackageVersion = await getExpoUpdatesPackageVersionIfInstalledAsync(projectDir);
if (expoUpdatesPackageVersion === null) {
return false;
}

if (expoUpdatesPackageVersion.includes('canary')) {
return true;
}

// TODO(wschurman): add semver check once we know the SDK51 version of expo-updates that supports this
return false;
}

export async function installExpoUpdatesAsync(
projectDir: string,
options?: { silent: boolean }
Expand Down
46 changes: 25 additions & 21 deletions packages/eas-cli/src/project/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import nullthrows from 'nullthrows';
import path from 'path';
import promiseLimit from 'promise-limit';

import { isModernExpoUpdatesCLIWithRuntimeVersionCommandSupportedAsync } from './projectUtils';
import { resolveWorkflowAsync } from './workflow';
import { selectBranchOnAppAsync } from '../branch/queries';
import { getDefaultBranchNameAsync } from '../branch/utils';
Expand All @@ -32,7 +33,6 @@ import {
shouldUseVersionedExpoCLIWithExplicitPlatforms,
} from '../utils/expoCli';
import {
ExpoUpdatesCLIInvalidCommandError,
ExpoUpdatesCLIModuleNotFoundError,
expoUpdatesCommandAsync,
} from '../utils/expoUpdatesCli';
Expand Down Expand Up @@ -721,26 +721,30 @@ async function getRuntimeVersionForPlatformAsync({
return 'UNVERSIONED';
}

try {
const resolvedRuntimeVersionJSONResult = await expoUpdatesCommandAsync(projectDir, [
'runtimeversion:resolve',
'--platform',
platform,
]);
const runtimeVersionResult = JSON.parse(resolvedRuntimeVersionJSONResult);
if (runtimeVersionResult.fingerprintSources) {
Log.debug(`Resolved fingeprint runtime version for platform "${platform}". Sources:`);
Log.debug(runtimeVersionResult.fingerprintSources);
}
return nullthrows(runtimeVersionResult.runtimeVersion);
} catch (e: any) {
// if it's a known set of errors thrown by the CLI it means that we need to default back to the
// previous behavior, otherwise we throw the error since something is wrong
if (
!(e instanceof ExpoUpdatesCLIModuleNotFoundError) &&
!(e instanceof ExpoUpdatesCLIInvalidCommandError)
) {
throw e;
if (await isModernExpoUpdatesCLIWithRuntimeVersionCommandSupportedAsync(projectDir)) {
try {
const resolvedRuntimeVersionJSONResult = await expoUpdatesCommandAsync(projectDir, [
'runtimeversion:resolve',
'--platform',
platform,
]);
const runtimeVersionResult = JSON.parse(resolvedRuntimeVersionJSONResult);
if (runtimeVersionResult.fingerprintSources) {
Log.debug(`Resolved fingeprint runtime version for platform "${platform}". Sources:`);
Log.debug(runtimeVersionResult.fingerprintSources);
}
return nullthrows(
runtimeVersionResult.runtimeVersion,
`Unable to determine runtime version for ${
requestedPlatformDisplayNames[platform]
}. ${learnMore('https://docs.expo.dev/eas-update/runtime-versions/')}`
);
} catch (e: any) {
// if it's a known set of errors thrown by the CLI it means that we need to default back to the
// previous behavior, otherwise we throw the error since something is wrong
if (!(e instanceof ExpoUpdatesCLIModuleNotFoundError)) {
throw e;
}
}
}

Expand Down
13 changes: 7 additions & 6 deletions packages/eas-cli/src/project/resolveRuntimeVersionAsync.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ExpoConfig } from '@expo/config';
import { Updates } from '@expo/config-plugins';

import { isModernExpoUpdatesCLIWithRuntimeVersionCommandSupportedAsync } from './projectUtils';
import Log from '../log';
import {
ExpoUpdatesCLIInvalidCommandError,
ExpoUpdatesCLIModuleNotFoundError,
expoUpdatesCommandAsync,
} from '../utils/expoUpdatesCli';
Expand All @@ -17,6 +17,12 @@ export async function resolveRuntimeVersionAsync({
platform: 'ios' | 'android';
projectDir: string;
}): Promise<string | null> {
if (!(await isModernExpoUpdatesCLIWithRuntimeVersionCommandSupportedAsync(projectDir))) {
// fall back to the previous behavior (using the @expo/config-plugins eas-cli dependency rather
// than the versioned @expo/config-plugins dependency in the project)
return await Updates.getRuntimeVersionNullableAsync(projectDir, exp, platform);
}

try {
const resolvedRuntimeVersionJSONResult = await expoUpdatesCommandAsync(projectDir, [
'runtimeversion:resolve',
Expand All @@ -33,12 +39,7 @@ export async function resolveRuntimeVersionAsync({
// if expo-updates is not installed, there's no need for a runtime version in the build
if (e instanceof ExpoUpdatesCLIModuleNotFoundError) {
return null;
} else if (e instanceof ExpoUpdatesCLIInvalidCommandError) {
// fall back to the previous behavior (using the @expo/config-plugins eas-cli dependency rather
// than the versioned @expo/config-plugins dependency in the project)
return await Updates.getRuntimeVersionNullableAsync(projectDir, exp, platform);
}

throw e;
}
}
13 changes: 4 additions & 9 deletions packages/eas-cli/src/utils/expoUpdatesCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@ export async function expoUpdatesCommandAsync(projectDir: string, args: string[]
try {
return (await spawnAsync(expoUpdatesCli, args)).stdout;
} catch (e: any) {
if (e.stderr && typeof e.stderr === 'string') {
if (
e.stderr.includes('Invalid command') || // SDK 51+
e.stderr.includes('commands[command] is not a function') // SDK <= 50
) {
throw new ExpoUpdatesCLIInvalidCommandError(
`The command specified by ${args} was not valid in the \`expo-updates\` CLI.`
);
}
if (e.stderr && typeof e.stderr === 'string' && e.stderr.includes('Invalid command')) {
throw new ExpoUpdatesCLIInvalidCommandError(
`The command specified by ${args} was not valid in the \`expo-updates\` CLI.`
);
}
throw e;
}
Expand Down

0 comments on commit 3d9d111

Please sign in to comment.