Skip to content

Commit

Permalink
feat(esbuild): support location expansion in esbuild args (#2564)
Browse files Browse the repository at this point in the history
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)"], ...)
  • Loading branch information
dae authored Mar 30, 2021
1 parent e056647 commit eb3bd7e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/esbuild/esbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _esbuild_impl(ctx):
args.add_joined(["--tsconfig", jsconfig_file.path], join_with = "=")
inputs.append(jsconfig_file)

args.add_all(ctx.attr.args)
args.add_all([ctx.expand_location(arg) for arg in ctx.attr.args])

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

0 comments on commit eb3bd7e

Please sign in to comment.