7
7
*/
8
8
9
9
import yargs from 'yargs' ;
10
+ import assert from 'node:assert' ;
10
11
11
12
import { HttpServer } from './server' ;
12
13
import { setupBazelWatcherSupport } from './ibazel' ;
13
14
14
- const { rootPaths, historyApiFallback, enableDevUi, environmentVariables, port, relaxCors} = yargs (
15
- process . argv . slice ( 2 ) ,
16
- )
15
+ const {
16
+ rootPaths,
17
+ historyApiFallback,
18
+ enableDevUi,
19
+ environmentVariables,
20
+ port : cliPort ,
21
+ relaxCors,
22
+ } = yargs ( process . argv . slice ( 2 ) )
17
23
. strict ( )
18
24
. option ( 'port' , {
19
25
type : 'number' ,
20
- default : process . env [ 'PORT' ] !== undefined ? Number ( process . env [ 'PORT' ] ) : 4200 ,
21
- defaultDescription : '${PORT}, or 4200 if unset' ,
26
+ default : 4200 ,
22
27
} )
23
28
. option ( 'historyApiFallback' , { type : 'boolean' , default : false } )
24
29
. option ( 'rootPaths' , { type : 'array' , string : true , default : [ '' ] } )
@@ -27,6 +32,13 @@ const {rootPaths, historyApiFallback, enableDevUi, environmentVariables, port, r
27
32
. option ( 'relaxCors' , { type : 'boolean' , default : false } )
28
33
. parseSync ( ) ;
29
34
35
+ let port = cliPort ;
36
+ // Process environment port always overrides the CLI, or rule attribute-specified port.
37
+ if ( process . env . PORT !== undefined ) {
38
+ port = Number ( process . env . PORT ) ;
39
+ assert ( ! isNaN ( port ) , 'Expected `PORT` environment variable to be a valid number.' ) ;
40
+ }
41
+
30
42
// In non-test executions, we will never allow for the browser-sync dev UI.
31
43
const enableUi = process . env . TEST_TARGET === undefined && enableDevUi ;
32
44
const server = new HttpServer (
0 commit comments