mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-06-15 18:08:15 +08:00
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
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
.idea/
|
||||
.vscode/
|
||||
node_modules/
|
||||
build
|
||||
.DS_Store
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user