1- ' use strict' ;
1+ " use strict" ;
22
33// Do this as the first thing so that any code reading it knows the right env.
4- process . env . BABEL_ENV = ' development' ;
5- process . env . NODE_ENV = ' development' ;
4+ process . env . BABEL_ENV = " development" ;
5+ process . env . NODE_ENV = " development" ;
66
77// Makes the script crash on unhandled rejections instead of silently
88// ignoring them. In the future, promise rejections that are not handled will
99// terminate the Node.js process with a non-zero exit code.
10- process . on ( ' unhandledRejection' , err => {
10+ process . on ( " unhandledRejection" , ( err ) => {
1111 throw err ;
1212} ) ;
1313
1414// Ensure environment variables are read.
15- require ( ' ../config/env' ) ;
15+ require ( " ../config/env" ) ;
1616
17- const fs = require ( 'fs' ) ;
18- const chalk = require ( ' react-dev-utils/chalk' ) ;
19- const webpack = require ( ' webpack' ) ;
20- const WebpackDevServer = require ( ' webpack-dev-server' ) ;
21- const clearConsole = require ( ' react-dev-utils/clearConsole' ) ;
22- const checkRequiredFiles = require ( ' react-dev-utils/checkRequiredFiles' ) ;
17+ const fs = require ( "fs" ) ;
18+ const chalk = require ( " react-dev-utils/chalk" ) ;
19+ const webpack = require ( " webpack" ) ;
20+ const WebpackDevServer = require ( " webpack-dev-server" ) ;
21+ const clearConsole = require ( " react-dev-utils/clearConsole" ) ;
22+ const checkRequiredFiles = require ( " react-dev-utils/checkRequiredFiles" ) ;
2323const {
2424 choosePort,
2525 createCompiler,
2626 prepareProxy,
2727 prepareUrls,
28- } = require ( ' react-dev-utils/WebpackDevServerUtils' ) ;
29- const openBrowser = require ( ' react-dev-utils/openBrowser' ) ;
30- const semver = require ( ' semver' ) ;
31- const paths = require ( ' ../config/paths' ) ;
32- const configFactory = require ( ' ../config/webpack.config' ) ;
33- const createDevServerConfig = require ( ' ../config/webpackDevServer.config' ) ;
34- const getClientEnvironment = require ( ' ../config/env' ) ;
35- const react = require ( require . resolve ( ' react' , { paths : [ paths . appPath ] } ) ) ;
28+ } = require ( " react-dev-utils/WebpackDevServerUtils" ) ;
29+ const openBrowser = require ( " react-dev-utils/openBrowser" ) ;
30+ const semver = require ( " semver" ) ;
31+ const paths = require ( " ../config/paths" ) ;
32+ const configFactory = require ( " ../config/webpack.config" ) ;
33+ const createDevServerConfig = require ( " ../config/webpackDevServer.config" ) ;
34+ const getClientEnvironment = require ( " ../config/env" ) ;
35+ const react = require ( require . resolve ( " react" , { paths : [ paths . appPath ] } ) ) ;
3636
3737const env = getClientEnvironment ( paths . publicUrlOrPath . slice ( 0 , - 1 ) ) ;
3838const useYarn = fs . existsSync ( paths . yarnLockFile ) ;
@@ -45,50 +45,50 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
4545
4646// Tools like Cloud9 rely on this.
4747const DEFAULT_PORT = parseInt ( process . env . PORT , 10 ) || 3000 ;
48- const HOST = process . env . HOST || ' 0.0.0.0' ;
48+ const HOST = process . env . HOST || " 0.0.0.0" ;
4949
5050if ( process . env . HOST ) {
5151 console . log (
5252 chalk . cyan (
5353 `Attempting to bind to HOST environment variable: ${ chalk . yellow (
54- chalk . bold ( process . env . HOST )
55- ) } `
56- )
54+ chalk . bold ( process . env . HOST ) ,
55+ ) } `,
56+ ) ,
5757 ) ;
5858 console . log (
59- `If this was unintentional, check that you haven't mistakenly set it in your shell.`
59+ `If this was unintentional, check that you haven't mistakenly set it in your shell.` ,
6060 ) ;
6161 console . log (
62- `Learn more here: ${ chalk . yellow ( ' https://cra.link/advanced-config' ) } `
62+ `Learn more here: ${ chalk . yellow ( " https://cra.link/advanced-config" ) } ` ,
6363 ) ;
6464 console . log ( ) ;
6565}
6666
6767// We require that you explicitly set browsers and do not fall back to
6868// browserslist defaults.
69- const { checkBrowsers } = require ( ' react-dev-utils/browsersHelper' ) ;
69+ const { checkBrowsers } = require ( " react-dev-utils/browsersHelper" ) ;
7070checkBrowsers ( paths . appPath , isInteractive )
7171 . then ( ( ) => {
7272 // We attempt to use the default port but if it is busy, we offer the user to
7373 // run on a different port. `choosePort()` Promise resolves to the next free port.
7474 return choosePort ( HOST , DEFAULT_PORT ) ;
7575 } )
76- . then ( port => {
76+ . then ( ( port ) => {
7777 if ( port == null ) {
7878 // We have not found a port.
7979 return ;
8080 }
8181
82- const config = configFactory ( ' development' ) ;
83- const protocol = process . env . HTTPS === ' true' ? ' https' : ' http' ;
82+ const config = configFactory ( " development" ) ;
83+ const protocol = process . env . HTTPS === " true" ? " https" : " http" ;
8484 const appName = require ( paths . appPackageJson ) . name ;
8585
8686 const useTypeScript = fs . existsSync ( paths . appTsConfig ) ;
8787 const urls = prepareUrls (
8888 protocol ,
8989 HOST ,
9090 port ,
91- paths . publicUrlOrPath . slice ( 0 , - 1 )
91+ paths . publicUrlOrPath . slice ( 0 , - 1 ) ,
9292 ) ;
9393 // Create a webpack compiler that is configured with custom messages.
9494 const compiler = createCompiler ( {
@@ -104,7 +104,7 @@ checkBrowsers(paths.appPath, isInteractive)
104104 const proxyConfig = prepareProxy (
105105 proxySetting ,
106106 paths . appPublic ,
107- paths . publicUrlOrPath
107+ paths . publicUrlOrPath ,
108108 ) ;
109109 // Serve webpack assets generated by the compiler over a web server.
110110 const serverConfig = {
@@ -119,34 +119,34 @@ checkBrowsers(paths.appPath, isInteractive)
119119 clearConsole ( ) ;
120120 }
121121
122- if ( env . raw . FAST_REFRESH && semver . lt ( react . version , ' 16.10.0' ) ) {
122+ if ( env . raw . FAST_REFRESH && semver . lt ( react . version , " 16.10.0" ) ) {
123123 console . log (
124124 chalk . yellow (
125- `Fast Refresh requires React 16.10 or higher. You are using React ${ react . version } .`
126- )
125+ `Fast Refresh requires React 16.10 or higher. You are using React ${ react . version } .` ,
126+ ) ,
127127 ) ;
128128 }
129129
130- console . log ( chalk . cyan ( ' Starting the development server...\n' ) ) ;
130+ console . log ( chalk . cyan ( " Starting the development server...\n" ) ) ;
131131 openBrowser ( urls . localUrlForBrowser ) ;
132132 } ) ;
133133
134- [ ' SIGINT' , ' SIGTERM' ] . forEach ( function ( sig ) {
134+ [ " SIGINT" , " SIGTERM" ] . forEach ( function ( sig ) {
135135 process . on ( sig , function ( ) {
136- devServer . close ( ) ;
137- process . exit ( ) ;
136+ console . log ( chalk . yellow ( "Stopping the development server..." ) ) ;
137+ devServer . stop ( ) . then ( ( ) => process . exit ( ) ) ;
138138 } ) ;
139139 } ) ;
140140
141- if ( process . env . CI !== ' true' ) {
141+ if ( process . env . CI !== " true" ) {
142142 // Gracefully exit when stdin ends
143- process . stdin . on ( ' end' , function ( ) {
144- devServer . close ( ) ;
145- process . exit ( ) ;
143+ process . stdin . on ( " end" , function ( ) {
144+ console . log ( chalk . yellow ( "Stopping the development server..." ) ) ;
145+ devServer . stop ( ) . then ( ( ) => process . exit ( ) ) ;
146146 } ) ;
147147 }
148148 } )
149- . catch ( err => {
149+ . catch ( ( err ) => {
150150 if ( err && err . message ) {
151151 console . log ( err . message ) ;
152152 }
0 commit comments