fix(runfiles): permit workspace-absolute labels
Also recognize the environment variables set by rules_js, which differ from rules_nodejs.
fixes https://github.com/aspect-build/rules_js/issues/406
diff --git a/packages/runfiles/runfiles.ts b/packages/runfiles/runfiles.ts
index 37528d8..e067963 100755
--- a/packages/runfiles/runfiles.ts
+++ b/packages/runfiles/runfiles.ts
@@ -44,11 +44,16 @@
--spawn_strategy=standalone to the command line.`);
}
// Bazel starts actions with pwd=execroot/my_wksp or pwd=runfiles/my_wksp
- this.workspace = _env['BAZEL_WORKSPACE'] || undefined;
+ this.workspace = _env['BAZEL_WORKSPACE'] || _env['JS_BINARY__WORKSPACE'] || undefined;
// If target is from an external workspace such as @npm//rollup/bin:rollup
// resolvePackageRelative is not supported since package is in an external
// workspace.
- const target = _env['BAZEL_TARGET'];
+ // However, if the target is formatted as @//some:target that's fine, it's
+ // syntax-sugar for "the workspace the build is in"
+ let target = _env['BAZEL_TARGET'] || _env['JS_BINARY__TARGET'];
+ if (target.startsWith('@//')) {
+ target = target.substring(3)
+ }
if (!!target && !target.startsWith('@')) {
// //path/to:target -> path/to
this.package = target.split(':')[0].replace(/^\/\//, '');