From c5cbee88da5f14826ab83cee22ccb862630a0141 Mon Sep 17 00:00:00 2001 From: Mo Binni Date: Wed, 7 Dec 2016 10:37:32 -0500 Subject: [PATCH 1/5] Implemented a version check of npm to give a soft tip during the install procedure and fixed gitignore --- .gitignore | 1 + packages/create-react-app/index.js | 15 +++++++++++++++ packages/react-scripts/package.json | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0aa0ed568ba..4bc0979112e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.vscode/ node_modules/ build .DS_Store diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index d8d28496cbf..3c119dc7f64 100755 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -121,6 +121,21 @@ function createApp(name, verbose, version, template) { ); console.log(); + // Check npm version + var npmVersionProc = spawn.sync('npm', ['--version']), + npmVersion = npmVersionProc.stdout; + if (npmVersion) { + var recommendVersion = semver.lt(npmVersion.toString(), '3.0.0'); + if (recommendVersion) { + console.log( + chalk.green( + 'Tip: It looks like you are using npm 2.\n' + + 'We suggest using npm 3 or Yarn for faster install times and less disk space usage.' + ) + ); + } + } + var packageJson = { name: appName, version: '0.1.0', diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 3b721779741..0e3e7106f50 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -72,4 +72,4 @@ "optionalDependencies": { "fsevents": "1.0.17" } -} +} \ No newline at end of file From 97f49f949f56d93b817cb4ebf4e39171f57338d9 Mon Sep 17 00:00:00 2001 From: Mo Binni Date: Fri, 24 Feb 2017 11:37:56 -0500 Subject: [PATCH 2/5] Moved NPM check to method, it is only executed when you use NPM and the version is < 3. --- .gitignore | 1 + packages/create-react-app/index.js | 34 +++++++++++++++++------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 4bc0979112e..79ce88915d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea/ .vscode/ node_modules/ build diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index 3c119dc7f64..920a6be5edf 100755 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -121,21 +121,6 @@ function createApp(name, verbose, version, template) { ); console.log(); - // Check npm version - var npmVersionProc = spawn.sync('npm', ['--version']), - npmVersion = npmVersionProc.stdout; - if (npmVersion) { - var recommendVersion = semver.lt(npmVersion.toString(), '3.0.0'); - if (recommendVersion) { - console.log( - chalk.green( - 'Tip: It looks like you are using npm 2.\n' + - 'We suggest using npm 3 or Yarn for faster install times and less disk space usage.' - ) - ); - } - } - var packageJson = { name: appName, version: '0.1.0', @@ -167,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); } @@ -245,6 +231,24 @@ function getPackageName(installPackage) { return installPackage; } +function checkNpmVersion() { + // Check npm version + var npmVersionProc = spawn.sync('npm', ['--version']), + npmVersion = npmVersionProc.stdout; + + if (npmVersion) { + var recommendVersion = semver.lt(npmVersion.toString(), '3.0.0'); + if (recommendVersion) { + console.log( + chalk.green( + 'Tip: It looks like you are using npm 2.\n' + + 'We suggest using npm 3 or Yarn for faster install times and less disk space usage.' + ) + ); + } + } +} + function checkNodeVersion(packageName) { var packageJsonPath = path.resolve( process.cwd(), From 812fb201ef81a36545584aa7fb1a1bddc6bcb29e Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 24 Feb 2017 20:09:59 +0000 Subject: [PATCH 3/5] Minor formatting tweaks --- packages/create-react-app/index.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index 920a6be5edf..06d5379950c 100755 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -174,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) { @@ -239,12 +242,12 @@ function checkNpmVersion() { if (npmVersion) { var recommendVersion = semver.lt(npmVersion.toString(), '3.0.0'); if (recommendVersion) { - console.log( - chalk.green( - 'Tip: It looks like you are using npm 2.\n' + - 'We suggest using npm 3 or Yarn for faster install times and less disk space usage.' - ) - ); + 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(); } } } From 89adca52869a60ecdce33259d4aa1d095cedfe6d Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 24 Feb 2017 20:24:20 +0000 Subject: [PATCH 4/5] Simplify the code --- packages/create-react-app/index.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/create-react-app/index.js b/packages/create-react-app/index.js index 06d5379950c..ace43f43ed6 100755 --- a/packages/create-react-app/index.js +++ b/packages/create-react-app/index.js @@ -235,21 +235,22 @@ function getPackageName(installPackage) { } function checkNpmVersion() { - // Check npm version - var npmVersionProc = spawn.sync('npm', ['--version']), - npmVersion = npmVersionProc.stdout; - - if (npmVersion) { - var recommendVersion = semver.lt(npmVersion.toString(), '3.0.0'); - if (recommendVersion) { - 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(); - } + 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) { From a080fa7e2dde182393f7590b5428b9dbe0696303 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 24 Feb 2017 20:24:53 +0000 Subject: [PATCH 5/5] Remove unnecessary change --- packages/react-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 0e3e7106f50..3b721779741 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -72,4 +72,4 @@ "optionalDependencies": { "fsevents": "1.0.17" } -} \ No newline at end of file +}