Skip to content

Commit

Permalink
Add temporary support for Node 4.x to global CLI (facebook#2214)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored and romaindso committed Jul 10, 2017
1 parent 82692e5 commit 218a723
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 20 deletions.
70 changes: 53 additions & 17 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,34 @@ function createApp(name, verbose, version, template) {
const originalDirectory = process.cwd();
process.chdir(root);

run(root, appName, version, verbose, originalDirectory, template);
if (!semver.satisfies(process.version, '>=6.0.0')) {
console.log(
chalk.yellow(
`You are using Node ${process.version} so the project will be boostrapped with an old unsupported version of tools.\n\n` +
`Please update to Node 6 or higher for a better, fully supported experience.\n`
)
);
// Fall back to latest supported react-scripts on Node 4
version = '[email protected]';
}

const useYarn = shouldUseYarn();
if (!useYarn) {
const npmInfo = checkNpmVersion();
if (!npmInfo.hasMinNpm) {
if (npmInfo.npmVersion) {
console.log(
chalk.yellow(
`You are using npm ${npmInfo.npmVersion} so the project will be boostrapped with an old unsupported version of tools.\n\n` +
`Please update to npm 3 or higher for a better, fully supported experience.\n`
)
);
}
// Fall back to latest supported react-scripts for npm 3
version = '[email protected]';
}
}
run(root, appName, version, verbose, originalDirectory, template, useYarn);
}

function shouldUseYarn() {
Expand Down Expand Up @@ -190,7 +217,6 @@ function install(useYarn, dependencies, verbose, isOnline) {
console.log();
}
} else {
checkNpmVersion();
command = 'npm';
args = ['install', '--save', '--save-exact'].concat(dependencies);
}
Expand All @@ -212,13 +238,19 @@ function install(useYarn, dependencies, verbose, isOnline) {
});
}

function run(root, appName, version, verbose, originalDirectory, template) {
function run(
root,
appName,
version,
verbose,
originalDirectory,
template,
useYarn
) {
const packageToInstall = getInstallPackage(version);
const allDependencies = ['react', 'react-dom', packageToInstall];

console.log('Installing packages. This might take a couple minutes.');

const useYarn = shouldUseYarn();
getPackageName(packageToInstall)
.then(packageName => checkIfOnline(useYarn).then(isOnline => ({
isOnline: isOnline,
Expand Down Expand Up @@ -253,6 +285,15 @@ function run(root, appName, version, verbose, originalDirectory, template) {
);
const init = require(scriptsPath);
init(root, appName, verbose, originalDirectory, template);

if (version === '[email protected]') {
console.log(
chalk.yellow(
`\nNote: the project was boostrapped with an old unsupported version of tools.\n` +
`Please update to Node >=6 and npm >=3 to get supported tools in new projects.\n`
)
);
}
})
.catch(reason => {
console.log();
Expand Down Expand Up @@ -399,22 +440,17 @@ function getPackageName(installPackage) {

function checkNpmVersion() {
let hasMinNpm = false;
let npmVersion = null;
try {
const npmVersion = execSync('npm --version').toString();
npmVersion = execSync('npm --version').toString().trim();
hasMinNpm = semver.gte(npmVersion, '3.0.0');
} catch (err) {
return;
}

if (!hasMinNpm) {
console.error(
chalk.red(
'Create React App requires npm 3 or higher. \n' +
'Please update your version of npm.'
)
);
process.exit(1);
// ignore
}
return {
hasMinNpm: hasMinNpm,
npmVersion: npmVersion,
};
}

function checkNodeVersion(packageName) {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-react-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ var currentNodeVersion = process.versions.node;
var semver = currentNodeVersion.split('.');
var major = semver[0];

if (major < 6) {
if (major < 4) {
console.error(
chalk.red(
'You are running Node ' +
currentNodeVersion +
'.\n' +
'Create React App requires Node 6 or higher. \n' +
'Create React App requires Node 4 or higher. \n' +
'Please update your version of Node.'
)
);
Expand Down
2 changes: 1 addition & 1 deletion packages/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"repository": "facebookincubator/create-react-app",
"license": "BSD-3-Clause",
"engines": {
"node": ">=6"
"node": ">=4"
},
"bugs": {
"url": "https://github.com/facebookincubator/create-react-app/issues"
Expand Down

0 comments on commit 218a723

Please sign in to comment.