-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Remove code duplication #1241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove code duplication #1241
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,30 @@ | |
'use strict'; | ||
|
||
var chalk = require('chalk'); | ||
var path = require('path'); | ||
var semver = require('semver'); | ||
|
||
function checkNodeVersion(packageJsonPath) { | ||
var packageJson = require(packageJsonPath); | ||
if (!packageJson.engines || !packageJson.engines.node) { | ||
return; | ||
} | ||
|
||
if (!semver.satisfies(process.version, packageJson.engines.node)) { | ||
console.error( | ||
chalk.red( | ||
'You are running Node %s.\n' + | ||
'Create React App requires Node %s or higher. \n' + | ||
'Please update your version of Node.' | ||
), | ||
process.version, | ||
packageJson.engines.node | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
checkNodeVersion(path.resolve(__dirname, 'package.json')); | ||
|
||
var currentNodeVersion = process.versions.node | ||
if (currentNodeVersion.split('.')[0] < 4) { | ||
|
@@ -54,10 +78,8 @@ if (currentNodeVersion.split('.')[0] < 4) { | |
|
||
var commander = require('commander'); | ||
var fs = require('fs-extra'); | ||
var path = require('path'); | ||
var execSync = require('child_process').execSync; | ||
var spawn = require('cross-spawn'); | ||
var semver = require('semver'); | ||
|
||
var projectName; | ||
|
||
|
@@ -180,7 +202,13 @@ function run(root, appName, version, verbose, originalDirectory, template) { | |
process.exit(1); | ||
} | ||
|
||
checkNodeVersion(packageName); | ||
var packageJsonPath = path.resolve( | ||
process.cwd(), | ||
'node_modules', | ||
packageName, | ||
'package.json' | ||
); | ||
checkNodeVersion(packageJsonPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not even sure if this line is still useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This lets us increase minimal version with time if |
||
|
||
var scriptsPath = path.resolve( | ||
process.cwd(), | ||
|
@@ -219,32 +247,6 @@ function getPackageName(installPackage) { | |
return installPackage; | ||
} | ||
|
||
function checkNodeVersion(packageName) { | ||
var packageJsonPath = path.resolve( | ||
process.cwd(), | ||
'node_modules', | ||
packageName, | ||
'package.json' | ||
); | ||
var packageJson = require(packageJsonPath); | ||
if (!packageJson.engines || !packageJson.engines.node) { | ||
return; | ||
} | ||
|
||
if (!semver.satisfies(process.version, packageJson.engines.node)) { | ||
console.error( | ||
chalk.red( | ||
'You are running Node %s.\n' + | ||
'Create React App requires Node %s or higher. \n' + | ||
'Please update your version of Node.' | ||
), | ||
process.version, | ||
packageJson.engines.node | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function checkAppName(appName) { | ||
// TODO: there should be a single place that holds the dependencies | ||
var dependencies = ['react', 'react-dom']; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this check then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows us to check the minimal supported version asap for the whole cra to work.
The problem was that it took ~10 minutes with node v0.10 to get to an halt with error, using a lot of resources meanwhile as it still installs all the dependencies, even thou it warns about the problem.