@@ -23,6 +23,8 @@ export class Runfiles {
23
23
*/
24
24
repoMappings : RepoMappings | undefined ;
25
25
26
+ private _runfilesResolutionError = false ;
27
+
26
28
constructor ( private _env = process . env ) {
27
29
// If Bazel sets a variable pointing to a runfiles manifest,
28
30
// we'll always use it.
@@ -39,8 +41,7 @@ export class Runfiles {
39
41
this . runfilesDir = path . resolve ( _env [ 'RUNFILES' ] ! ) ;
40
42
this . repoMappings = this . parseRepoMapping ( this . runfilesDir ) ;
41
43
} else {
42
- throw new Error (
43
- 'Every node program run under Bazel must have a $RUNFILES_DIR, $RUNFILES or $RUNFILES_MANIFEST_FILE environment variable' ) ;
44
+ this . _runfilesResolutionError = true ;
44
45
}
45
46
// Under --noenable_runfiles (in particular on Windows)
46
47
// Bazel sets RUNFILES_MANIFEST_ONLY=1.
@@ -65,6 +66,13 @@ export class Runfiles {
65
66
}
66
67
}
67
68
69
+ private _assertRunfilesResolved ( ) {
70
+ if ( this . _runfilesResolutionError ) {
71
+ throw new Error (
72
+ 'Every node program run under Bazel must have a $RUNFILES_DIR, $RUNFILES or $RUNFILES_MANIFEST_FILE environment variable' ) ;
73
+ }
74
+ }
75
+
68
76
/** Resolves the given path from the runfile manifest. */
69
77
private _resolveFromManifest ( searchPath : string ) : string | undefined {
70
78
if ( ! this . manifest ) return undefined ;
@@ -100,7 +108,6 @@ export class Runfiles {
100
108
return result ;
101
109
}
102
110
103
-
104
111
/**
105
112
* The runfiles manifest maps from short_path
106
113
* https://docs.bazel.build/versions/main/skylark/lib/File.html#short_path
@@ -152,6 +159,8 @@ export class Runfiles {
152
159
153
160
/** Resolves the given module path. */
154
161
resolve ( modulePath : string , sourceRepo ?: string ) : string {
162
+ this . _assertRunfilesResolved ( ) ;
163
+
155
164
// Normalize path by converting to forward slashes and removing all trailing
156
165
// forward slashes
157
166
modulePath = modulePath . replace ( / \\ / g, '/' ) . replace ( / \/ + $ / g, '' )
0 commit comments