-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Catch synchronous errors from spawning yarn #1204
Changes from 1 commit
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 |
---|---|---|
|
@@ -108,38 +108,47 @@ function createApp(name, verbose, version) { | |
} | ||
|
||
function install(packageToInstall, verbose, callback) { | ||
var args = [ | ||
'add', | ||
'--dev', | ||
'--exact', | ||
packageToInstall, | ||
]; | ||
var proc = spawn('yarn', args, {stdio: 'inherit'}); | ||
|
||
var yarnExists = true; | ||
proc.on('error', function (err) { | ||
if (err.code === 'ENOENT') { | ||
yarnExists = false; | ||
} | ||
}); | ||
proc.on('close', function (code) { | ||
if (yarnExists) { | ||
callback(code, 'yarn', args); | ||
return; | ||
} | ||
// No Yarn installed, continuing with npm. | ||
args = [ | ||
function fallbackToNpm() { | ||
var npmArgs = [ | ||
'install', | ||
verbose && '--verbose', | ||
'--save-dev', | ||
'--save-exact', | ||
packageToInstall, | ||
].filter(function(e) { return e; }); | ||
var npmProc = spawn('npm', args, {stdio: 'inherit'}); | ||
var npmProc = spawn('npm', npmArgs, {stdio: 'inherit'}); | ||
npmProc.on('close', function (code) { | ||
callback(code, 'npm', args); | ||
callback(code, 'npm', npmArgs); | ||
}); | ||
}); | ||
} | ||
|
||
var yarnArgs = [ | ||
'add', | ||
'--dev', | ||
'--exact', | ||
packageToInstall, | ||
]; | ||
var yarnProc; | ||
var yarnExists = true; | ||
try { | ||
yarnProc = spawn('yarn', yarnArgs, {stdio: 'inherit'}); | ||
yarnProc.on('error', function (err) { | ||
if (err.code === 'ENOENT') { | ||
yarnExists = false; | ||
} | ||
}); | ||
yarnProc.on('close', function (code) { | ||
if (yarnExists) { | ||
callback(code, 'yarn', yarnArgs); | ||
return; | ||
} | ||
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. You need to call 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. Addressed |
||
}); | ||
} 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(); | ||
} | ||
} | ||
|
||
function run(root, appName, version, verbose, originalDirectory) { | ||
|
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.
I'd only wrap this single line with
try-catch
, because that's the thing we need to catch the errors from. I don't want us to get stuck in an infinite loop if something else fails in the fallbacknpm
command for example.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.
Addressed