| 331 | } |
| 332 | |
| 333 | function install(root, useYarn, usePnp, dependencies, verbose, isOnline) { |
| 334 | return new Promise((resolve, reject) => { |
| 335 | let command; |
| 336 | let args; |
| 337 | if (useYarn) { |
| 338 | command = 'yarnpkg'; |
| 339 | args = ['add', '--exact']; |
| 340 | if (!isOnline) { |
| 341 | args.push('--offline'); |
| 342 | } |
| 343 | if (usePnp) { |
| 344 | args.push('--enable-pnp'); |
| 345 | } |
| 346 | [].push.apply(args, dependencies); |
| 347 | |
| 348 | // Explicitly set cwd() to work around issues like |
| 349 | // https://github.com/facebook/create-react-app/issues/3326. |
| 350 | // Unfortunately we can only do this for Yarn because npm support for |
| 351 | // equivalent --prefix flag doesn't help with this issue. |
| 352 | // This is why for npm, we run checkThatNpmCanReadCwd() early instead. |
| 353 | args.push('--cwd'); |
| 354 | args.push(root); |
| 355 | |
| 356 | if (!isOnline) { |
| 357 | console.log(chalk.yellow('You appear to be offline.')); |
| 358 | console.log(chalk.yellow('Falling back to the local Yarn cache.')); |
| 359 | console.log(); |
| 360 | } |
| 361 | } else { |
| 362 | command = 'npm'; |
| 363 | args = [ |
| 364 | 'install', |
| 365 | '--no-audit', // https://github.com/facebook/create-react-app/issues/11174 |
| 366 | '--save', |
| 367 | '--save-exact', |
| 368 | '--loglevel', |
| 369 | 'error', |
| 370 | ].concat(dependencies); |
| 371 | |
| 372 | if (usePnp) { |
| 373 | console.log(chalk.yellow("NPM doesn't support PnP.")); |
| 374 | console.log(chalk.yellow('Falling back to the regular installs.')); |
| 375 | console.log(); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | if (verbose) { |
| 380 | args.push('--verbose'); |
| 381 | } |
| 382 | |
| 383 | const child = spawn(command, args, { stdio: 'inherit' }); |
| 384 | child.on('close', code => { |
| 385 | if (code !== 0) { |
| 386 | reject({ |
| 387 | command: `${command} ${args.join(' ')}`, |
| 388 | }); |
| 389 | return; |
| 390 | } |