xref: /expo/packages/@expo/cli/src/install/index.ts (revision feef0cca)
1#!/usr/bin/env node
2import chalk from 'chalk';
3
4import { Command } from '../../bin/cli';
5import { assertWithOptionsArgs, printHelp } from '../utils/args';
6
7export const expoInstall: Command = async (argv) => {
8  const args = assertWithOptionsArgs(
9    {
10      // Other options are parsed manually.
11      '--help': Boolean,
12      // Aliases
13      '-h': '--help',
14    },
15    {
16      argv,
17      // Allow other options, we'll throw an error if unexpected values are passed.
18      permissive: true,
19    }
20  );
21
22  if (args['--help']) {
23    printHelp(
24      `Install a module or other package to a project`,
25      `npx expo install`,
26      [
27        `--check     Check which installed packages need to be updated`,
28        `--fix       Automatically update any invalid package versions`,
29        chalk`--npm       Use npm to install dependencies. {dim Default when package-lock.json exists}`,
30        chalk`--yarn      Use Yarn to install dependencies. {dim Default when yarn.lock exists}`,
31        `-h, --help  Usage info`,
32      ].join('\n'),
33      [
34        '',
35        chalk`  Additional options can be passed to the underlying install command by using {bold --}`,
36        chalk`    {dim $} npx expo install react -- --verbose`,
37        chalk`    {dim >} yarn add react --verbose`,
38        '',
39      ].join('\n')
40    );
41  }
42
43  // Load modules after the help prompt so `npx expo install -h` shows as fast as possible.
44  const { installAsync } = require('./installAsync') as typeof import('./installAsync');
45  const { logCmdError } = require('../utils/errors') as typeof import('../utils/errors');
46  const { resolveArgsAsync } = require('./resolveOptions') as typeof import('./resolveOptions');
47
48  const { variadic, options, extras } = await resolveArgsAsync(process.argv.slice(3)).catch(
49    logCmdError
50  );
51  return installAsync(variadic, options, extras).catch(logCmdError);
52};
53