Skip to content

Commit 53db95a

Browse files
rangle-mobinnigaearon
authored andcommittedFeb 24, 2017
NPM version check for tip (facebook#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
1 parent c8d9c47 commit 53db95a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.idea/
2+
.vscode/
13
node_modules/
24
build
35
.DS_Store

‎packages/create-react-app/index.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ function install(dependencies, verbose, callback) {
152152
command = 'yarnpkg';
153153
args = [ 'add', '--exact'].concat(dependencies);
154154
} else {
155+
checkNpmVersion();
155156
command = 'npm';
156157
args = ['install', '--save', '--save-exact'].concat(dependencies);
157158
}
@@ -173,7 +174,10 @@ function run(root, appName, version, verbose, originalDirectory, template) {
173174
var allDependencies = ['react', 'react-dom', packageToInstall];
174175

175176
console.log('Installing packages. This might take a couple minutes.');
176-
console.log('Installing ' + chalk.cyan('react, react-dom, ' + packageName) + '...');
177+
console.log(
178+
'Installing ' + chalk.cyan('react') + ', ' + chalk.cyan('react-dom') +
179+
', and ' + chalk.cyan(packageName) + '...'
180+
);
177181
console.log();
178182

179183
install(allDependencies, verbose, function(code, command, args) {
@@ -230,6 +234,25 @@ function getPackageName(installPackage) {
230234
return installPackage;
231235
}
232236

237+
function checkNpmVersion() {
238+
var isNpm2 = false;
239+
try {
240+
var npmVersion = execSync('npm --version').toString();
241+
isNpm2 = semver.lt(npmVersion, '3.0.0');
242+
} catch (err) {
243+
return;
244+
}
245+
if (!isNpm2) {
246+
return;
247+
}
248+
console.log(chalk.yellow('It looks like you are using npm 2.'));
249+
console.log(chalk.yellow(
250+
'We suggest using npm 3 or Yarn for faster install times ' +
251+
'and less disk space usage.'
252+
));
253+
console.log();
254+
}
255+
233256
function checkNodeVersion(packageName) {
234257
var packageJsonPath = path.resolve(
235258
process.cwd(),

0 commit comments

Comments
 (0)
Please sign in to comment.