Skip to content

Commit eb3bd7e

Browse files
authored
feat(esbuild): support location expansion in esbuild args (#2564)
When an esbuild rule is passed an argument like "--inject:path/in/repo.js", this works when building in the local workspace, as esbuild is invoked with the correct working directory. But if the esbuild rule is in a remote workspace (eg bazel build @other_workspace//path/in:esbuild_rule), then the path is no longer valid. By expanding $(location ...) references in provided arguments, it allows callers of the rule to pass arguments like the following, which work in both local and remote repo cases: esbuild(args = ["--inject:$(location //path/in:repo.js)"], ...)
1 parent e056647 commit eb3bd7e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/esbuild/esbuild.bzl

+3-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _esbuild_impl(ctx):
109109
args.add_joined(["--tsconfig", jsconfig_file.path], join_with = "=")
110110
inputs.append(jsconfig_file)
111111

112-
args.add_all(ctx.attr.args)
112+
args.add_all([ctx.expand_location(arg) for arg in ctx.attr.args])
113113

114114
env = {}
115115
if ctx.attr.max_threads > 0:
@@ -138,7 +138,8 @@ esbuild = rule(
138138
attrs = {
139139
"args": attr.string_list(
140140
default = [],
141-
doc = "A list of extra arguments that are included in the call to esbuild",
141+
doc = """A list of extra arguments that are included in the call to esbuild.
142+
$(location ...) can be used to resolve the path to a Bazel target.""",
142143
),
143144
"define": attr.string_list(
144145
default = [],

0 commit comments

Comments
 (0)