xref: /expo/tools/src/ExpoCLI.ts (revision 75e080d0)
1import spawnAsync from '@expo/spawn-async';
2import path from 'path';
3import process from 'process';
4
5import { EXPO_DIR } from './Constants';
6
7type Options = {
8  cwd?: string;
9  root?: string;
10  stdio?: 'inherit' | 'pipe' | 'ignore';
11};
12
13export async function runExpoCliAsync(
14  command: string,
15  args: string[] = [],
16  options: Options = {}
17): Promise<void> {
18  const configArgs = options.root ? ['--config', path.resolve(options.root, 'app.json')] : [];
19
20  // Don't handle SIGINT/SIGTERM in this process...defer to expo-cli
21  process.on('SIGINT', () => {});
22  process.on('SIGTERM', () => {});
23
24  await spawnAsync('expo', [command, ...args, ...configArgs], {
25    cwd: options.cwd || options.root || EXPO_DIR,
26    stdio: options.stdio || 'inherit',
27    env: {
28      ...process.env,
29      EXPO_NO_DOCTOR: 'true',
30    },
31  });
32}
33