@@ -105,16 +105,44 @@ module.exports = function(
105
105
'..'
106
106
) ;
107
107
108
+ let templateJsonPath ;
109
+ if ( templateName ) {
110
+ templateJsonPath = path . join ( templatePath , 'template.json' ) ;
111
+ } else {
112
+ // TODO: Remove support for this in v4.
113
+ templateJsonPath = path . join ( appPath , '.template.dependencies.json' ) ;
114
+ }
115
+
116
+ let templateJson = { } ;
117
+ if ( fs . existsSync ( templateJsonPath ) ) {
118
+ templateJson = require ( templateJsonPath ) ;
119
+ }
120
+
108
121
// Copy over some of the devDependencies
109
122
appPackage . dependencies = appPackage . dependencies || { } ;
110
123
111
124
// Setup the script rules
112
- appPackage . scripts = {
113
- start : 'react-scripts start' ,
114
- build : 'react-scripts build' ,
115
- test : 'react-scripts test' ,
116
- eject : 'react-scripts eject' ,
117
- } ;
125
+ const templateScripts = templateJson . scripts || { } ;
126
+ appPackage . scripts = Object . assign (
127
+ {
128
+ start : 'react-scripts start' ,
129
+ build : 'react-scripts build' ,
130
+ test : 'react-scripts test' ,
131
+ eject : 'react-scripts eject' ,
132
+ } ,
133
+ templateScripts
134
+ ) ;
135
+
136
+ // Update scripts for Yarn users
137
+ if ( useYarn ) {
138
+ appPackage . scripts = Object . entries ( appPackage . scripts ) . reduce (
139
+ ( acc , [ key , value ] ) => ( {
140
+ ...acc ,
141
+ [ key ] : value . replace ( / ( n p m r u n | n p m ) / , 'yarn ' ) ,
142
+ } ) ,
143
+ { }
144
+ ) ;
145
+ }
118
146
119
147
// Setup the eslint config
120
148
appPackage . eslintConfig = {
@@ -196,21 +224,13 @@ module.exports = function(
196
224
}
197
225
198
226
// Install additional template dependencies, if present
199
- let templateJsonPath ;
200
- if ( templateName ) {
201
- templateJsonPath = path . join ( templatePath , 'template.json' ) ;
202
- } else {
203
- templateJsonPath = path . join ( appPath , '.template.dependencies.json' ) ;
204
- }
205
-
206
- if ( fs . existsSync ( templateJsonPath ) ) {
207
- const templateDependencies = require ( templateJsonPath ) . dependencies ;
227
+ const templateDependencies = templateJson . dependencies ;
228
+ if ( templateDependencies ) {
208
229
args = args . concat (
209
230
Object . keys ( templateDependencies ) . map ( key => {
210
231
return `${ key } @${ templateDependencies [ key ] } ` ;
211
232
} )
212
233
) ;
213
- fs . unlinkSync ( templateJsonPath ) ;
214
234
}
215
235
216
236
// Install react and react-dom for backward compatibility with old CRA cli
0 commit comments