Skip to content

Commit

Permalink
[eas-cli] Fix display of errors when expo-updates CLI command fails
Browse files Browse the repository at this point in the history
  • Loading branch information
wschurman committed Apr 12, 2024
1 parent c29018d commit 351deeb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
13 changes: 9 additions & 4 deletions packages/eas-cli/src/project/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,16 +723,21 @@ async function getRuntimeVersionForPlatformAsync({

if (await isModernExpoUpdatesCLIWithRuntimeVersionCommandSupportedAsync(projectDir)) {
try {
Log.debug('Using expo-updates runtimeversion:resolve CLI for runtime version resolution');

const extraArgs = Log.isDebug ? ['--debug'] : [];

const resolvedRuntimeVersionJSONResult = await expoUpdatesCommandAsync(projectDir, [
'runtimeversion:resolve',
'--platform',
platform,
...extraArgs,
]);
const runtimeVersionResult = JSON.parse(resolvedRuntimeVersionJSONResult);
if (runtimeVersionResult.fingerprintSources) {
Log.debug(`Resolved fingeprint runtime version for platform "${platform}". Sources:`);
Log.debug(runtimeVersionResult.fingerprintSources);
}

Log.debug('runtimeversion:resolve output:');
Log.debug(resolvedRuntimeVersionJSONResult);

return nullthrows(
runtimeVersionResult.runtimeVersion,
`Unable to determine runtime version for ${
Expand Down
13 changes: 9 additions & 4 deletions packages/eas-cli/src/project/resolveRuntimeVersionAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ export async function resolveRuntimeVersionAsync({
}

try {
Log.debug('Using expo-updates runtimeversion:resolve CLI for runtime version resolution');

const extraArgs = Log.isDebug ? ['--debug'] : [];

const resolvedRuntimeVersionJSONResult = await expoUpdatesCommandAsync(projectDir, [
'runtimeversion:resolve',
'--platform',
platform,
...extraArgs,
]);
const runtimeVersionResult = JSON.parse(resolvedRuntimeVersionJSONResult);
if (runtimeVersionResult.fingerprintSources) {
Log.debug(`Resolved fingeprint runtime version for platform "${platform}". Sources:`);
Log.debug(runtimeVersionResult.fingerprintSources);
}

Log.debug('runtimeversion:resolve output:');
Log.debug(resolvedRuntimeVersionJSONResult);

return runtimeVersionResult.runtimeVersion ?? null;
} catch (e: any) {
// if expo-updates is not installed, there's no need for a runtime version in the build
Expand Down
16 changes: 11 additions & 5 deletions packages/eas-cli/src/utils/expoUpdatesCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { link } from '../log';

export class ExpoUpdatesCLIModuleNotFoundError extends Error {}
export class ExpoUpdatesCLIInvalidCommandError extends Error {}
export class ExpoUpdatesCLICommandFailedError extends Error {}

export async function expoUpdatesCommandAsync(projectDir: string, args: string[]): Promise<string> {
let expoUpdatesCli;
Expand All @@ -24,13 +25,18 @@ export async function expoUpdatesCommandAsync(projectDir: string, args: string[]
}

try {
return (await spawnAsync(expoUpdatesCli, args)).stdout;
return (await spawnAsync(expoUpdatesCli, args, { stdio: 'pipe' })).stdout;
} catch (e: any) {
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.`
);
if (e.stderr && typeof e.stderr === 'string') {
if (e.stderr.includes('Invalid command')) {
throw new ExpoUpdatesCLIInvalidCommandError(
`The command specified by ${args} was not valid in the \`expo-updates\` CLI.`
);
} else {
throw new ExpoUpdatesCLICommandFailedError(e.stderr);
}
}

throw e;
}
}

0 comments on commit 351deeb

Please sign in to comment.