Skip to content

Commit fff00b6

Browse files
Aghassijbedard
andauthored
fix: js_run_binary doesn't accept select() (#2137)
I have a situation internally where I need to pass a different environment variable based on CI or remote development. Right now, `select` is not a `dict` so this fails. This is not an issue with skylibs `run_binary` or `bazel-lib`'s `run_binary`. By flipping this to a `|` merger, the issue goes away. --------- Co-authored-by: Jason Bedard <jason+github@jbedard.ca>
1 parent 2679d36 commit fff00b6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

examples/js_binary/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ js_run_binary(
176176
"@mycorp/pkg-a",
177177
],
178178
chdir = package_name(),
179+
# This specifically tests that a `select` can be used when setting `env`.
180+
env = select({
181+
"//conditions:default": {
182+
"NODE_ENV": "production",
183+
},
184+
}),
179185
out_dirs = ["out4-dist"],
180186
tool = ":bin4",
181187
)
@@ -200,6 +206,12 @@ js_run_binary(
200206
"@mycorp/pkg-b",
201207
],
202208
chdir = package_name(),
209+
# This specifically tests that a `select` and `|` operator can be used when setting `env`.
210+
env = {} | select({
211+
"//conditions:default": {
212+
"NODE_ENV": "production",
213+
},
214+
}),
203215
tool = ":bin4",
204216
)
205217

js/private/js_run_binary.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ load("@aspect_rules_js//js:defs.bzl", "js_run_binary")
1313
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", _copy_to_bin = "copy_to_bin")
1414
load("@aspect_bazel_lib//lib:run_binary.bzl", _run_binary = "run_binary")
1515
load("@aspect_bazel_lib//lib:utils.bzl", bazel_lib_utils = "utils")
16-
load("@bazel_skylib//lib:dicts.bzl", "dicts")
1716
load(":js_helpers.bzl", _envs_for_log_level = "envs_for_log_level")
1817
load(":js_info_files.bzl", _js_info_files = "js_info_files")
1918
load(":js_library.bzl", _js_library = "js_library")
@@ -401,7 +400,7 @@ See https://github.com/aspect-build/rules_js/tree/main/docs#using-binaries-publi
401400
_run_binary(
402401
name = name,
403402
tool = tool,
404-
env = dicts.add(fixed_env, env),
403+
env = fixed_env | env,
405404
srcs = srcs + extra_srcs,
406405
outs = outs + extra_outs,
407406
out_dirs = out_dirs,

0 commit comments

Comments
 (0)