From b8cffade0031b5ae8a4a4c7a486db59e0d69e5c7 Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Wed, 13 Mar 2024 11:07:41 +1100 Subject: [PATCH 1/2] Match Bazel `env` attribute behaviour --- internal/node/node.bzl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/node/node.bzl b/internal/node/node.bzl index e6b7389e..109088dd 100755 --- a/internal/node/node.bzl +++ b/internal/node/node.bzl @@ -194,8 +194,9 @@ def _nodejs_binary_impl(ctx): env_vars = "" # Add all env vars from the ctx attr + expanded_env = {} for [key, value] in ctx.attr.env.items(): - env_vars += "export %s=%s\n" % (key, expand_location_into_runfiles(ctx, value, ctx.attr.data)) + expanded_env[key] = expand_location_into_runfiles(ctx, value, ctx.attr.data) # While we can derive the workspace from the pwd when running locally # because it is in the execroot path `execroot/my_wksp`, on RBE the @@ -361,6 +362,7 @@ fi # since this will be called from a nodejs_test, where the entrypoint is going to be the test file # we shouldn't add the entrypoint as a attribute to collect here coverage_common.instrumented_files_info(ctx, dependency_attributes = ["data"], extensions = ["js", "ts"]), + RunEnvironmentInfo(expanded_env), ] _NODEJS_EXECUTABLE_ATTRS = { From 7c95524a81d023b7c3ecd74628ff6b48a5c28f17 Mon Sep 17 00:00:00 2001 From: Jordan Mele Date: Wed, 13 Mar 2024 12:37:53 +1100 Subject: [PATCH 2/2] Update docs --- internal/node/node.bzl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/node/node.bzl b/internal/node/node.bzl index 109088dd..d0dfe144 100755 --- a/internal/node/node.bzl +++ b/internal/node/node.bzl @@ -469,8 +469,9 @@ nodejs_binary( allow_files = True, ), "env": attr.string_dict( - doc = """Specifies additional environment variables to set when the target is executed, subject to location -expansion. + doc = """ + Specifies additional environment variables to set when the target is executed with `run` and `test`. + Subject to location expansion. """, default = {}, ),