Commit 270fe06c authored by Dan Abramov's avatar Dan Abramov Committed by GitHub
Browse files

Catch synchronous errors from spawning yarn (#1204)

* Catch synchronous errors from spawning yarn

* Fix issues
parent 0a9865db
No related merge requests found
Showing with 30 additions and 19 deletions
+30 -19
...@@ -108,37 +108,48 @@ function createApp(name, verbose, version) { ...@@ -108,37 +108,48 @@ function createApp(name, verbose, version) {
} }
function install(packageToInstall, verbose, callback) { function install(packageToInstall, verbose, callback) {
var args = [ function fallbackToNpm() {
var npmArgs = [
'install',
verbose && '--verbose',
'--save-dev',
'--save-exact',
packageToInstall,
].filter(function(e) { return e; });
var npmProc = spawn('npm', npmArgs, {stdio: 'inherit'});
npmProc.on('close', function (code) {
callback(code, 'npm', npmArgs);
});
}
var yarnArgs = [
'add', 'add',
'--dev', '--dev',
'--exact', '--exact',
packageToInstall, packageToInstall,
]; ];
var proc = spawn('yarn', args, {stdio: 'inherit'}); var yarnProc;
var yarnExists = true; var yarnExists = true;
proc.on('error', function (err) { try {
yarnProc = spawn('yarn', yarnArgs, {stdio: 'inherit'});
} catch (err) {
// It's not clear why we end up here in some cases but we need this.
// https://github.com/facebookincubator/create-react-app/issues/1200
yarnExists = false;
fallbackToNpm();
return;
}
yarnProc.on('error', function (err) {
if (err.code === 'ENOENT') { if (err.code === 'ENOENT') {
yarnExists = false; yarnExists = false;
} }
}); });
proc.on('close', function (code) { yarnProc.on('close', function (code) {
if (yarnExists) { if (yarnExists) {
callback(code, 'yarn', args); callback(code, 'yarn', yarnArgs);
return; } else {
fallbackToNpm();
} }
// No Yarn installed, continuing with npm.
args = [
'install',
verbose && '--verbose',
'--save-dev',
'--save-exact',
packageToInstall,
].filter(function(e) { return e; });
var npmProc = spawn('npm', args, {stdio: 'inherit'});
npmProc.on('close', function (code) {
callback(code, 'npm', args);
});
}); });
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment