66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { readFileSync } from 'fs' ;
10- import { runfiles } from '@bazel/runfiles' ;
9+ import fs from 'node:fs' ;
1110import browserSync from 'browser-sync' ;
12- import http from 'http' ;
13- import path from 'path' ;
11+ import http from 'node: http' ;
12+ import path from 'node: path' ;
1413import send from 'send' ;
14+ import assert from 'node:assert' ;
15+
16+ // The current working directory is the runfiles root.
17+ const runfilesRoot = process . env [ 'RUNFILES_DIR' ] ! ;
18+ assert ( runfilesRoot , 'Expected `RUNFILES_DIR` to be set.' ) ;
1519
1620/**
1721 * Http Server implementation that uses browser-sync internally. This server
@@ -26,22 +30,7 @@ export class HttpServer {
2630 server = browserSync . create ( ) ;
2731
2832 /** Options of the browser-sync server. */
29- options : browserSync . Options = {
30- open : false ,
31- online : false ,
32- port : this . port ,
33- notify : false ,
34- ghostMode : false ,
35- server : {
36- directory : false ,
37- middleware : [
38- ( req , res ) => {
39- this . _corsMiddleware ( req , res ) ;
40- this . _bazelMiddleware ( req , res ) ;
41- } ,
42- ] ,
43- } ,
44- } ;
33+ options : browserSync . Options ;
4534
4635 constructor (
4736 readonly port : number ,
@@ -51,6 +40,23 @@ export class HttpServer {
5140 private _environmentVariables : string [ ] = [ ] ,
5241 private _relaxCors : boolean = false ,
5342 ) {
43+ this . options = {
44+ open : false ,
45+ online : false ,
46+ port : this . port ,
47+ notify : false ,
48+ ghostMode : false ,
49+ server : {
50+ directory : false ,
51+ middleware : [
52+ ( req , res ) => {
53+ this . _corsMiddleware ( req , res ) ;
54+ this . _bazelMiddleware ( req , res ) ;
55+ } ,
56+ ] ,
57+ } ,
58+ } ;
59+
5460 if ( enableUi === false ) {
5561 this . options . ui = false ;
5662 }
@@ -131,12 +137,15 @@ export class HttpServer {
131137 return new URL ( reqURL , `http://_` ) . pathname ;
132138 }
133139
134- /** Resolves a given URL from the runfiles using the corresponding manifest path. */
140+ /** Resolves a given URL from the runfiles using a computed manifest path. */
135141 private _resolveUrlFromRunfiles ( url : string ) : string | null {
136142 for ( let rootPath of this . _rootPaths ) {
137- try {
138- return runfiles . resolve ( path . posix . join ( rootPath , getManifestPath ( url ) ) ) ;
139- } catch { }
143+ const fragment = path . posix . join ( rootPath , getManifestPath ( url ) ) ;
144+ const diskPath = path . join ( runfilesRoot , fragment ) ;
145+
146+ if ( fs . existsSync ( diskPath ) ) {
147+ return diskPath ;
148+ }
140149 }
141150 return null ;
142151 }
@@ -155,7 +164,7 @@ export class HttpServer {
155164 }
156165
157166 const variables : Record < string , string | undefined > = { } ;
158- const content = readFileSync ( indexPath , 'utf8' ) ;
167+ const content = fs . readFileSync ( indexPath , 'utf8' ) ;
159168
160169 // Populate variables object that will be inlined.
161170 this . _environmentVariables . forEach ( ( name ) => ( variables [ name ] = process . env [ name ] ) ) ;
0 commit comments