xref: /expo/packages/@expo/cli/src/install/index.ts (revision bb5069cd)
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        chalk`--pnpm      Use pnpm to install dependencies. {dim Default when pnpm-lock.yaml exists}`,
32        `-h, --help  Usage info`,
33      ].join('\n'),
34      [
35        '',
36        chalk`  Additional options can be passed to the underlying install command by using {bold --}`,
37        chalk`    {dim $} npx expo install react -- --verbose`,
38        chalk`    {dim >} yarn add react --verbose`,
39        '',
40      ].join('\n')
41    );
42  }
43
44  // Load modules after the help prompt so `npx expo install -h` shows as fast as possible.
45  const { installAsync } = require('./installAsync') as typeof import('./installAsync');
46  const { logCmdError } = require('../utils/errors') as typeof import('../utils/errors');
47  const { resolveArgsAsync } = require('./resolveOptions') as typeof import('./resolveOptions');
48
49  const { variadic, options, extras } = await resolveArgsAsync(process.argv.slice(3)).catch(
50    logCmdError
51  );
52  return installAsync(variadic, options, extras).catch(logCmdError);
53};
54