xref: /expo/packages/@expo/cli/src/utils/nodeModules.ts (revision 6caf5755)
1import chalk from 'chalk';
2import fs from 'fs';
3import path from 'path';
4
5import { logNewSection } from './ora';
6
7export async function clearNodeModulesAsync(projectRoot: string) {
8  // This step can take a couple seconds, if the installation logs are enabled (with EXPO_DEBUG) then it
9  // ends up looking odd to see "Installing JavaScript dependencies" for ~5 seconds before the logs start showing up.
10  const cleanJsDepsStep = logNewSection('Cleaning JavaScript dependencies');
11  const time = Date.now();
12  // nuke the node modules
13  // TODO: this is substantially slower, we should find a better alternative to ensuring the modules are installed.
14  await fs.promises.rm(path.join(projectRoot, 'node_modules'), { recursive: true, force: true });
15  cleanJsDepsStep.succeed(
16    `Cleaned JavaScript dependencies ${chalk.gray(Date.now() - time + 'ms')}`
17  );
18}
19