Skip to content
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

Add temporary support for Node 4.x to global CLI #2214

Merged
merged 1 commit into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 'react-scripts@0.9.x';
}

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 = 'react-scripts@0.9.x';
}
}
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 === 'react-scripts@0.9.x') {
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