@@ -108,37 +108,48 @@ function createApp(name, verbose, version) {
108
108
}
109
109
110
110
function install ( packageToInstall , verbose , callback ) {
111
- var args = [
111
+ function fallbackToNpm ( ) {
112
+ var npmArgs = [
113
+ 'install' ,
114
+ verbose && '--verbose' ,
115
+ '--save-dev' ,
116
+ '--save-exact' ,
117
+ packageToInstall ,
118
+ ] . filter ( function ( e ) { return e ; } ) ;
119
+ var npmProc = spawn ( 'npm' , npmArgs , { stdio : 'inherit' } ) ;
120
+ npmProc . on ( 'close' , function ( code ) {
121
+ callback ( code , 'npm' , npmArgs ) ;
122
+ } ) ;
123
+ }
124
+
125
+ var yarnArgs = [
112
126
'add' ,
113
127
'--dev' ,
114
128
'--exact' ,
115
129
packageToInstall ,
116
130
] ;
117
- var proc = spawn ( 'yarn' , args , { stdio : 'inherit' } ) ;
118
-
131
+ var yarnProc ;
119
132
var yarnExists = true ;
120
- proc . on ( 'error' , function ( err ) {
133
+ try {
134
+ yarnProc = spawn ( 'yarn' , yarnArgs , { stdio : 'inherit' } ) ;
135
+ } catch ( err ) {
136
+ // It's not clear why we end up here in some cases but we need this.
137
+ // https://github.com/facebookincubator/create-react-app/issues/1200
138
+ yarnExists = false ;
139
+ fallbackToNpm ( ) ;
140
+ return ;
141
+ }
142
+ yarnProc . on ( 'error' , function ( err ) {
121
143
if ( err . code === 'ENOENT' ) {
122
144
yarnExists = false ;
123
145
}
124
146
} ) ;
125
- proc . on ( 'close' , function ( code ) {
147
+ yarnProc . on ( 'close' , function ( code ) {
126
148
if ( yarnExists ) {
127
- callback ( code , 'yarn' , args ) ;
128
- return ;
149
+ callback ( code , 'yarn' , yarnArgs ) ;
150
+ } else {
151
+ fallbackToNpm ( ) ;
129
152
}
130
- // No Yarn installed, continuing with npm.
131
- args = [
132
- 'install' ,
133
- verbose && '--verbose' ,
134
- '--save-dev' ,
135
- '--save-exact' ,
136
- packageToInstall ,
137
- ] . filter ( function ( e ) { return e ; } ) ;
138
- var npmProc = spawn ( 'npm' , args , { stdio : 'inherit' } ) ;
139
- npmProc . on ( 'close' , function ( code ) {
140
- callback ( code , 'npm' , args ) ;
141
- } ) ;
142
153
} ) ;
143
154
}
144
155
0 commit comments