From b90dd21a4cf4eed1aa57f173d12c47b840870d32 Mon Sep 17 00:00:00 2001 From: Mo Binni Date: Fri, 24 Feb 2017 15:25:18 -0500 Subject: [PATCH] NPM version check for tip (#1193) * Implemented a version check of npm to give a soft tip during the install procedure and fixed gitignore * Moved NPM check to method, it is only executed when you use NPM and the version is < 3. * Minor formatting tweaks * Simplify the code * Remove unnecessary change --- .gitignore | 2 ++ packages/create-react-app/index.js | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0aa0ed56..79ce8891 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.idea/ +.vscode/ node_modules/ build .DS_Store diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index 48d1b557..6b7dce9b 100755 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -152,6 +152,7 @@ function install(dependencies, verbose, callback) { command = 'yarnpkg'; args = [ 'add', '--exact'].concat(dependencies); } else { + checkNpmVersion(); command = 'npm'; args = ['install', '--save', '--save-exact'].concat(dependencies); } @@ -173,7 +174,10 @@ function run(root, appName, version, verbose, originalDirectory, template) { var allDependencies = ['react', 'react-dom', packageToInstall]; console.log('Installing packages. This might take a couple minutes.'); - console.log('Installing ' + chalk.cyan('react, react-dom, ' + packageName) + '...'); + console.log( + 'Installing ' + chalk.cyan('react') + ', ' + chalk.cyan('react-dom') + + ', and ' + chalk.cyan(packageName) + '...' + ); console.log(); install(allDependencies, verbose, function(code, command, args) { @@ -230,6 +234,25 @@ function getPackageName(installPackage) { return installPackage; } +function checkNpmVersion() { + var isNpm2 = false; + try { + var npmVersion = execSync('npm --version').toString(); + isNpm2 = semver.lt(npmVersion, '3.0.0'); + } catch (err) { + return; + } + if (!isNpm2) { + return; + } + console.log(chalk.yellow('It looks like you are using npm 2.')); + console.log(chalk.yellow( + 'We suggest using npm 3 or Yarn for faster install times ' + + 'and less disk space usage.' + )); + console.log(); +} + function checkNodeVersion(packageName) { var packageJsonPath = path.resolve( process.cwd(),