@@ -340,19 +340,25 @@ function run(
340
340
( ) => packageName
341
341
) ;
342
342
} )
343
- . then ( packageName => {
343
+ . then ( async packageName => {
344
344
checkNodeVersion ( packageName ) ;
345
345
setCaretRangeForRuntimeDeps ( packageName ) ;
346
346
347
- const scriptsPath = path . resolve (
348
- process . cwd ( ) ,
349
- 'node_modules' ,
350
- packageName ,
351
- 'scripts' ,
352
- 'init.js'
347
+ const pnpPath = path . resolve ( process . cwd ( ) , '.pnp.js' ) ;
348
+
349
+ const nodeArgs = fs . existsSync ( pnpPath ) ? [ '--require' , pnpPath ] : [ ] ;
350
+
351
+ await executeNodeScript (
352
+ {
353
+ cwd : process . cwd ( ) ,
354
+ args : nodeArgs ,
355
+ } ,
356
+ [ root , appName , verbose , originalDirectory , template ] ,
357
+ `
358
+ var init = require('${ packageName } /scripts/init.js');
359
+ init.apply(null, JSON.parse(process.argv[1]));
360
+ `
353
361
) ;
354
- const init = require ( scriptsPath ) ;
355
- init ( root , appName , verbose , originalDirectory , template ) ;
356
362
357
363
if ( version === '[email protected] ' ) {
358
364
console . log (
@@ -799,3 +805,23 @@ function checkIfOnline(useYarn) {
799
805
} ) ;
800
806
} ) ;
801
807
}
808
+
809
+ function executeNodeScript ( { cwd, args } , data , source ) {
810
+ return new Promise ( ( resolve , reject ) => {
811
+ const child = spawn (
812
+ process . execPath ,
813
+ [ ...args , '-e' , source , '--' , JSON . stringify ( data ) ] ,
814
+ { stdio : 'inherit' }
815
+ ) ;
816
+
817
+ child . on ( 'close' , code => {
818
+ if ( code !== 0 ) {
819
+ reject ( {
820
+ command : `${ command } ${ args . join ( ' ' ) } ` ,
821
+ } ) ;
822
+ return ;
823
+ }
824
+ resolve ( ) ;
825
+ } ) ;
826
+ } ) ;
827
+ }
0 commit comments