* Resolve a path that came from a Bazel $(location …) expansion. * * When a js_binary runs inside a js_run_binary action Bazel sets BAZEL_BINDIR * and the js_binary wrapper calls process.chdir(BAZEL_BINDIR) before handing * control to the script. $(location) values are relative to the *execroot*
(p)
| 126 | * Outside Bazel (BAZEL_BINDIR unset) paths are resolved normally. |
| 127 | */ |
| 128 | function resolveInputPath(p) { |
| 129 | if (!p) return null |
| 130 | if (!process.env.BAZEL_BINDIR) return resolve(p) |
| 131 | // Normalize both strings to forward slashes before prefix-stripping so that |
| 132 | // mixed separators on Windows (BAZEL_BINDIR uses '\', $(location) uses '/') |
| 133 | // do not cause the startsWith check to silently fail. |
| 134 | const normalizedP = p.replaceAll('\\', '/') |
| 135 | const normalizedBindir = process.env.BAZEL_BINDIR.replaceAll('\\', '/') |
| 136 | const prefix = normalizedBindir + '/' |
| 137 | return resolve(normalizedP.startsWith(prefix) ? normalizedP.slice(prefix.length) : normalizedP) |
| 138 | } |
| 139 | |
| 140 | // ============================================================ |
| 141 | // Main |
no test coverage detected