Compare commits

...
+20 -29
View File
@@ -1,11 +1,11 @@
import { ExpoConfig } from '@expo/config-types'; import { ExpoConfig } from '@expo/config-types';
import spawnAsync from '@expo/spawn-async'; import { createForProject } from '@expo/package-manager';
import chalk from 'chalk'; import chalk from 'chalk';
import { boolish } from 'getenv'; import { boolish } from 'getenv';
import resolveFrom, { silent as silentResolveFrom } from 'resolve-from'; import resolveFrom from 'resolve-from';
import semver from 'semver'; import semver from 'semver';
import Log, { link } from '../log'; import Log from '../log';
import { memoize } from './expodash/memoize'; import { memoize } from './expodash/memoize';
// Aggressively returns `true` (UNVERSIONED, invalid SDK version format) to push users towards the versioned CLI. // Aggressively returns `true` (UNVERSIONED, invalid SDK version format) to push users towards the versioned CLI.
@@ -53,7 +53,7 @@ export function shouldUseVersionedExpoCLIExpensive(
} }
// Finally ensure the CLI is available for sanity. // Finally ensure the CLI is available for sanity.
return !!resolveFrom.silent(projectDir, '@expo/cli'); return !!resolveFrom.silent(projectDir, 'expo');
} }
/** /**
@@ -64,7 +64,8 @@ export function shouldUseVersionedExpoCLIExpensive(
export function shouldUseVersionedExpoCLIWithExplicitPlatformsExpensive( export function shouldUseVersionedExpoCLIWithExplicitPlatformsExpensive(
projectDir: string projectDir: string
): boolean { ): boolean {
const expoCliPath = resolveFrom.silent(projectDir, '@expo/cli/package.json'); const expoPath = resolveFrom.silent(projectDir, 'expo');
const expoCliPath = expoPath && resolveFrom.silent(expoPath, '@expo/cli/package.json');
if (!expoCliPath) { if (!expoCliPath) {
return false; return false;
} }
@@ -82,41 +83,31 @@ export async function expoCommandAsync(
args: string[], args: string[],
{ silent = false }: { silent?: boolean } = {} { silent = false }: { silent?: boolean } = {}
): Promise<void> { ): Promise<void> {
let expoCliPath; const packageManager = createForProject(projectDir, {
try { silent,
expoCliPath = stdio: ['inherit', 'pipe', 'pipe'],
silentResolveFrom(projectDir, 'expo/bin/cli') ?? resolveFrom(projectDir, 'expo/bin/cli.js');
} catch (e: any) {
if (e.code === 'MODULE_NOT_FOUND') {
throw new Error(
`The \`expo\` package was not found. Follow the installation directions at ${link(
'https://docs.expo.dev/bare/installing-expo-modules/'
)}`
);
}
throw e;
}
const spawnPromise = spawnAsync(expoCliPath, args, {
stdio: ['inherit', 'pipe', 'pipe'], // inherit stdin so user can install a missing expo-cli from inside this command
}); });
const {
child: { stdout, stderr }, const commandPromise = packageManager.runAsync(['expo', ...args]);
} = spawnPromise; const { child: spawnPromise } = commandPromise;
if (!(stdout && stderr)) {
if (!spawnPromise.stdout || !spawnPromise.stderr) {
throw new Error('Failed to spawn expo-cli'); throw new Error('Failed to spawn expo-cli');
} }
if (!silent) { if (!silent) {
stdout.on('data', data => { spawnPromise.stdout.on('data', data => {
for (const line of data.toString().trim().split('\n')) { for (const line of data.toString().trim().split('\n')) {
Log.log(`${chalk.gray('[expo-cli]')} ${line}`); Log.log(`${chalk.gray('[expo-cli]')} ${line}`);
} }
}); });
stderr.on('data', data => {
spawnPromise.stderr.on('data', data => {
for (const line of data.toString().trim().split('\n')) { for (const line of data.toString().trim().split('\n')) {
Log.warn(`${chalk.gray('[expo-cli]')} ${line}`); Log.warn(`${chalk.gray('[expo-cli]')} ${line}`);
} }
}); });
} }
await spawnPromise;
await commandPromise;
} }