Skip to content

Commit

Permalink
NPM version check for tip (#1193)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rangle-mobinni authored and gaearon committed Feb 24, 2017
1 parent c8d9c47 commit 53db95a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea/
.vscode/
node_modules/
build
.DS_Store
Expand Down
25 changes: 24 additions & 1 deletion packages/create-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 53db95a

Please sign in to comment.