@@ -76,6 +76,7 @@ const program = new commander.Command(packageJson.name)
76
76
'use a non-standard version of react-scripts'
77
77
)
78
78
. option ( '--use-npm' )
79
+ . option ( '--use-pnp' )
79
80
. allowUnknownOption ( )
80
81
. on ( '--help' , ( ) => {
81
82
console . log ( ` Only ${ chalk . green ( '<project-directory>' ) } is required.` ) ;
@@ -178,10 +179,11 @@ createApp(
178
179
program . verbose ,
179
180
program . scriptsVersion ,
180
181
program . useNpm ,
182
+ program . usePnp ,
181
183
hiddenProgram . internalTestingTemplate
182
184
) ;
183
185
184
- function createApp ( name , verbose , version , useNpm , template ) {
186
+ function createApp ( name , verbose , version , useNpm , usePnp , template ) {
185
187
const root = path . resolve ( name ) ;
186
188
const appName = path . basename ( root ) ;
187
189
@@ -241,7 +243,16 @@ function createApp(name, verbose, version, useNpm, template) {
241
243
242
244
}
243
245
}
244
- run ( root , appName , version , verbose , originalDirectory , template , useYarn ) ;
246
+ run (
247
+ root ,
248
+ appName ,
249
+ version ,
250
+ verbose ,
251
+ originalDirectory ,
252
+ template ,
253
+ useYarn ,
254
+ usePnp
255
+ ) ;
245
256
}
246
257
247
258
function shouldUseYarn ( ) {
@@ -253,7 +264,7 @@ function shouldUseYarn() {
253
264
}
254
265
}
255
266
256
- function install ( root , useYarn , dependencies , verbose , isOnline ) {
267
+ function install ( root , useYarn , usePnp , dependencies , verbose , isOnline ) {
257
268
return new Promise ( ( resolve , reject ) => {
258
269
let command ;
259
270
let args ;
@@ -263,6 +274,9 @@ function install(root, useYarn, dependencies, verbose, isOnline) {
263
274
if ( ! isOnline ) {
264
275
args . push ( '--offline' ) ;
265
276
}
277
+ if ( usePnp ) {
278
+ args . push ( '--enable-pnp' ) ;
279
+ }
266
280
[ ] . push . apply ( args , dependencies ) ;
267
281
268
282
// Explicitly set cwd() to work around issues like
@@ -287,6 +301,12 @@ function install(root, useYarn, dependencies, verbose, isOnline) {
287
301
'--loglevel' ,
288
302
'error' ,
289
303
] . concat ( dependencies ) ;
304
+
305
+ if ( usePnp ) {
306
+ console . log ( chalk . yellow ( "NPM doesn't support PnP." ) ) ;
307
+ console . log ( chalk . yellow ( 'Falling back to the regular installs.' ) ) ;
308
+ console . log ( ) ;
309
+ }
290
310
}
291
311
292
312
if ( verbose ) {
@@ -313,7 +333,8 @@ function run(
313
333
verbose ,
314
334
originalDirectory ,
315
335
template ,
316
- useYarn
336
+ useYarn ,
337
+ usePnp
317
338
) {
318
339
const packageToInstall = getInstallPackage ( version , originalDirectory ) ;
319
340
const allDependencies = [ 'react' , 'react-dom' , packageToInstall ] ;
@@ -336,9 +357,14 @@ function run(
336
357
) ;
337
358
console . log ( ) ;
338
359
339
- return install ( root , useYarn , allDependencies , verbose , isOnline ) . then (
340
- ( ) => packageName
341
- ) ;
360
+ return install (
361
+ root ,
362
+ useYarn ,
363
+ usePnp ,
364
+ allDependencies ,
365
+ verbose ,
366
+ isOnline
367
+ ) . then ( ( ) => packageName ) ;
342
368
} )
343
369
. then ( async packageName => {
344
370
checkNodeVersion ( packageName ) ;
0 commit comments