Skip to content

Commit

Permalink
fix: ensure BAZEL_NODE_RUNFILES_HELPER & BAZEL_NODE_PATCH_REQUIRE are…
Browse files Browse the repository at this point in the history
… absolute (#1634)

* fix: ensure BAZEL_NODE_RUNFILES_HELPER & BAZEL_NODE_PATCH_REQUIRE are absolute

```
export BAZEL_NODE_RUNFILES_HELPER=$(rlocation "build_bazel_rules_nodejs/internal/linker/runfiles_helper.js")
```

resolves to `/Users/greg/google/rules_nodejs/internal/linker/runfiles_helper.js` when workers are on as there is no sandbox

&

resolves to `bazel-out/host/bin/external/build_bazel_rules_typescript/internal/tsc_wrapped_bin.sh.runfiles/build_bazel_rules_nodejs/internal/linker/runfiles_helper.js` when workers are off as there is a sandbox

The latter is a relative path and won't work in a require() statement unless joined with the CWD.

This commit adds the CWD in the launcher.

* test: test require(process.env['BAZEL_NODE_RUNFILES_HELPER']) in npm_package_bin
  • Loading branch information
gregmagolan authored Feb 13, 2020
1 parent d635dca commit 25600ea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/node/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,16 @@ fi

# Export the location of the runfiles helpers script
export BAZEL_NODE_RUNFILES_HELPER=$(rlocation "TEMPLATED_runfiles_helper_script")
if [[ "${BAZEL_NODE_RUNFILES_HELPER}" != /* ]] && [[ ! "${BAZEL_NODE_RUNFILES_HELPER}" =~ ^[A-Z]:[\\/] ]]; then
export BAZEL_NODE_RUNFILES_HELPER=$(pwd)/${BAZEL_NODE_RUNFILES_HELPER}
fi

# Export the location of the require patch script as it can be used to boostrap
# node require patch if needed
export BAZEL_NODE_PATCH_REQUIRE=$(rlocation "TEMPLATED_require_patch_script")
if [[ "${BAZEL_NODE_PATCH_REQUIRE}" != /* ]] && [[ ! "${BAZEL_NODE_PATCH_REQUIRE}" =~ ^[A-Z]:[\\/] ]]; then
export BAZEL_NODE_PATCH_REQUIRE=$(pwd)/${BAZEL_NODE_PATCH_REQUIRE}
fi

# The main entry point
MAIN=$(rlocation "TEMPLATED_loader_script")
Expand Down
19 changes: 19 additions & 0 deletions internal/node/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,25 @@ golden_file_test(
golden = "expand_variables.golden",
)

nodejs_binary(
name = "test_runfiles_helper",
data = [":test_runfiles_helper.golden"],
entry_point = "test_runfiles_helper.js",
)

npm_package_bin(
name = "test_runfiles_helper_ouput",
outs = ["test_runfiles_helper.out"],
args = ["$@"],
tool = ":test_runfiles_helper",
)

golden_file_test(
name = "test_runfiles_helper_test",
actual = ":test_runfiles_helper.out",
golden = "test_runfiles_helper.golden",
)

nodejs_test(
name = "fail_test",
entry_point = "fail.spec.js",
Expand Down
1 change: 1 addition & 0 deletions internal/node/test/test_runfiles_helper.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello_world
7 changes: 7 additions & 0 deletions internal/node/test/test_runfiles_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const fs = require('fs');
const args = process.argv.slice(2);
const outfile = args.shift();
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']);
const golden =
runfiles.resolve('build_bazel_rules_nodejs/internal/node/test/test_runfiles_helper.golden');
fs.writeFileSync(outfile, fs.readFileSync(golden, 'utf-8'), 'utf-8');

0 comments on commit 25600ea

Please sign in to comment.