-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "[build-tools] Update expo-updates runtime version res…
- Loading branch information
Showing
6 changed files
with
116 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import spawnAsync from '@expo/spawn-async'; | ||
import resolveFrom, { silent as silentResolveFrom } from 'resolve-from'; | ||
|
||
export class ExpoUpdatesCLIModuleNotFoundError extends Error {} | ||
export class ExpoUpdatesCLIInvalidCommandError extends Error {} | ||
|
||
export async function expoUpdatesCommandAsync(projectDir: string, args: string[]): Promise<string> { | ||
let expoUpdatesCli; | ||
try { | ||
expoUpdatesCli = | ||
silentResolveFrom(projectDir, 'expo-updates/bin/cli') ?? | ||
resolveFrom(projectDir, 'expo-updates/bin/cli.js'); | ||
} catch (e: any) { | ||
if (e.code === 'MODULE_NOT_FOUND') { | ||
throw new ExpoUpdatesCLIModuleNotFoundError( | ||
`The \`expo-updates\` package was not found. Follow the installation directions at https://docs.expo.dev/bare/installing-expo-modules/` | ||
); | ||
} | ||
throw e; | ||
} | ||
|
||
try { | ||
return (await spawnAsync(expoUpdatesCli, args)).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.` | ||
); | ||
} | ||
throw e; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/build-tools/src/utils/resolveRuntimeVersionAsync.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ExpoConfig } from '@expo/config'; | ||
import { Updates } from '@expo/config-plugins'; | ||
import { bunyan } from '@expo/logger'; | ||
|
||
import { ExpoUpdatesCLIModuleNotFoundError, expoUpdatesCommandAsync } from './expoUpdatesCli'; | ||
import { isModernExpoUpdatesCLIWithRuntimeVersionCommandSupported } from './expoUpdates'; | ||
|
||
export async function resolveRuntimeVersionAsync({ | ||
exp, | ||
platform, | ||
projectDir, | ||
logger, | ||
expoUpdatesPackageVersion, | ||
}: { | ||
exp: ExpoConfig; | ||
platform: 'ios' | 'android'; | ||
projectDir: string; | ||
logger: bunyan; | ||
expoUpdatesPackageVersion: string; | ||
}): Promise<string | null> { | ||
if (!isModernExpoUpdatesCLIWithRuntimeVersionCommandSupported(expoUpdatesPackageVersion)) { | ||
// 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', | ||
'--platform', | ||
platform, | ||
]); | ||
const runtimeVersionResult = JSON.parse(resolvedRuntimeVersionJSONResult); | ||
if (runtimeVersionResult.fingerprintSources) { | ||
logger.debug(`Resolved fingeprint runtime version for platform "${platform}". Sources:`); | ||
logger.debug(runtimeVersionResult.fingerprintSources); | ||
} | ||
return runtimeVersionResult.runtimeVersion ?? null; | ||
} catch (e: any) { | ||
// if expo-updates is not installed, there's no need for a runtime version in the build | ||
if (e instanceof ExpoUpdatesCLIModuleNotFoundError) { | ||
return null; | ||
} | ||
throw e; | ||
} | ||
} |