6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { readFileSync } from 'fs' ;
10
- import { runfiles } from '@bazel/runfiles' ;
9
+ import fs from 'node:fs' ;
11
10
import 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' ;
14
13
import 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.' ) ;
15
19
16
20
/**
17
21
* Http Server implementation that uses browser-sync internally. This server
@@ -26,22 +30,7 @@ export class HttpServer {
26
30
server = browserSync . create ( ) ;
27
31
28
32
/** 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 ;
45
34
46
35
constructor (
47
36
readonly port : number ,
@@ -51,6 +40,23 @@ export class HttpServer {
51
40
private _environmentVariables : string [ ] = [ ] ,
52
41
private _relaxCors : boolean = false ,
53
42
) {
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
+
54
60
if ( enableUi === false ) {
55
61
this . options . ui = false ;
56
62
}
@@ -131,12 +137,15 @@ export class HttpServer {
131
137
return new URL ( reqURL , `http://_` ) . pathname ;
132
138
}
133
139
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. */
135
141
private _resolveUrlFromRunfiles ( url : string ) : string | null {
136
142
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
+ }
140
149
}
141
150
return null ;
142
151
}
@@ -155,7 +164,7 @@ export class HttpServer {
155
164
}
156
165
157
166
const variables : Record < string , string | undefined > = { } ;
158
- const content = readFileSync ( indexPath , 'utf8' ) ;
167
+ const content = fs . readFileSync ( indexPath , 'utf8' ) ;
159
168
160
169
// Populate variables object that will be inlined.
161
170
this . _environmentVariables . forEach ( ( name ) => ( variables [ name ] = process . env [ name ] ) ) ;
0 commit comments