77 */
88
99import yargs from 'yargs' ;
10+ import assert from 'node:assert' ;
1011
1112import { HttpServer } from './server' ;
1213import { setupBazelWatcherSupport } from './ibazel' ;
1314
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 ) )
1723 . strict ( )
1824 . option ( 'port' , {
1925 type : 'number' ,
20- default : process . env [ 'PORT' ] !== undefined ? Number ( process . env [ 'PORT' ] ) : 4200 ,
21- defaultDescription : '${PORT}, or 4200 if unset' ,
26+ default : 4200 ,
2227 } )
2328 . option ( 'historyApiFallback' , { type : 'boolean' , default : false } )
2429 . option ( 'rootPaths' , { type : 'array' , string : true , default : [ '' ] } )
@@ -27,6 +32,13 @@ const {rootPaths, historyApiFallback, enableDevUi, environmentVariables, port, r
2732 . option ( 'relaxCors' , { type : 'boolean' , default : false } )
2833 . parseSync ( ) ;
2934
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+
3042// In non-test executions, we will never allow for the browser-sync dev UI.
3143const enableUi = process . env . TEST_TARGET === undefined && enableDevUi ;
3244const server = new HttpServer (
0 commit comments