@@ -76,6 +76,7 @@ const program = new commander.Command(packageJson.name)
7676 'use a non-standard version of react-scripts'
7777 )
7878 . option ( '--use-npm' )
79+ . option ( '--use-pnp' )
7980 . allowUnknownOption ( )
8081 . on ( '--help' , ( ) => {
8182 console . log ( ` Only ${ chalk . green ( '<project-directory>' ) } is required.` ) ;
@@ -178,10 +179,11 @@ createApp(
178179 program . verbose ,
179180 program . scriptsVersion ,
180181 program . useNpm ,
182+ program . usePnp ,
181183 hiddenProgram . internalTestingTemplate
182184) ;
183185
184- function createApp ( name , verbose , version , useNpm , template ) {
186+ function createApp ( name , verbose , version , useNpm , usePnp , template ) {
185187 const root = path . resolve ( name ) ;
186188 const appName = path . basename ( root ) ;
187189
@@ -241,7 +243,16 @@ function createApp(name, verbose, version, useNpm, template) {
241243 version = 'react-scripts@0.9.x' ;
242244 }
243245 }
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+ ) ;
245256}
246257
247258function shouldUseYarn ( ) {
@@ -253,7 +264,7 @@ function shouldUseYarn() {
253264 }
254265}
255266
256- function install ( root , useYarn , dependencies , verbose , isOnline ) {
267+ function install ( root , useYarn , usePnp , dependencies , verbose , isOnline ) {
257268 return new Promise ( ( resolve , reject ) => {
258269 let command ;
259270 let args ;
@@ -263,6 +274,9 @@ function install(root, useYarn, dependencies, verbose, isOnline) {
263274 if ( ! isOnline ) {
264275 args . push ( '--offline' ) ;
265276 }
277+ if ( usePnp ) {
278+ args . push ( '--enable-pnp' ) ;
279+ }
266280 [ ] . push . apply ( args , dependencies ) ;
267281
268282 // Explicitly set cwd() to work around issues like
@@ -287,6 +301,12 @@ function install(root, useYarn, dependencies, verbose, isOnline) {
287301 '--loglevel' ,
288302 'error' ,
289303 ] . 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+ }
290310 }
291311
292312 if ( verbose ) {
@@ -313,7 +333,8 @@ function run(
313333 verbose ,
314334 originalDirectory ,
315335 template ,
316- useYarn
336+ useYarn ,
337+ usePnp
317338) {
318339 const packageToInstall = getInstallPackage ( version , originalDirectory ) ;
319340 const allDependencies = [ 'react' , 'react-dom' , packageToInstall ] ;
@@ -336,9 +357,14 @@ function run(
336357 ) ;
337358 console . log ( ) ;
338359
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 ) ;
342368 } )
343369 . then ( async packageName => {
344370 checkNodeVersion ( packageName ) ;
0 commit comments