@@ -5,39 +5,27 @@ module.exports = function() {
55 return false
66 }
77
8- const package = JSON . parse ( readFileSync ( 'package.json' , { encoding : 'utf8' } ) )
9- if ( ! ( package . dependencies && package . dependencies [ 'react-scripts' ] ) ) {
8+ const packageSettings = JSON . parse ( readFileSync ( 'package.json' , { encoding : 'utf8' } ) )
9+ const { dependencies, scripts } = packageSettings
10+ if ( ! ( dependencies && dependencies [ 'react-scripts' ] ) ) {
1011 return false
1112 }
1213
13- const settings = {
14+ const npmCommand = scripts && ( ( scripts . start && 'start' ) || ( scripts . serve && 'serve' ) || ( scripts . run && 'run' ) )
15+
16+ if ( ! npmCommand ) {
17+ console . error ( "Couldn't determine the script to run. Use the -c flag." )
18+ process . exit ( 1 )
19+ }
20+
21+ const yarnExists = existsSync ( 'yarn.lock' )
22+ return {
23+ cmd : yarnExists ? 'yarn' : 'npm' ,
1424 port : 8888 ,
1525 proxyPort : 3000 ,
1626 env : { ...process . env , BROWSER : 'none' , PORT : 3000 } ,
17- args : [ ] ,
27+ args : yarnExists || npmCommand != 'start' ? [ 'run' , npmCommand ] : [ npmCommand ] ,
1828 urlRegexp : new RegExp ( `(http://)([^:]+:)${ 3000 } (/)?` , 'g' ) ,
1929 dist : 'dist'
2030 }
21-
22- if ( package ) {
23- if ( existsSync ( 'yarn.lock' ) ) {
24- settings . cmd = 'yarn'
25- } else {
26- settings . cmd = 'npm'
27- settings . args . push ( 'run' )
28- }
29-
30- if ( package . scripts . start ) {
31- settings . args . push ( 'start' )
32- } else if ( package . scripts . serve ) {
33- settings . args . push ( 'serve' )
34- } else if ( package . scripts . run ) {
35- settings . args . push ( 'run' )
36- } else {
37- console . error ( "Couldn't determine the script to run. Use the -c flag." )
38- process . exit ( 1 )
39- }
40-
41- return settings
42- }
4331}
0 commit comments