Skip to content

Commit

Permalink
fix: give better error when ts_project should be js_library
Browse files Browse the repository at this point in the history
Fixes #72
  • Loading branch information
alexeagle committed Jul 11, 2022
1 parent 374174f commit 9daa456
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions ts/private/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,25 @@ def _ts_project_impl(ctx):
])
outputs.append(ctx.outputs.buildinfo_out)
runtime_outputs = json_outs + js_outs + map_outs
typings_outputs = typings_outs + typing_maps_outs + [s for s in ctx.files.srcs if s.path.endswith(".d.ts")]
typings_srcs = [s for s in ctx.files.srcs if s.path.endswith(".d.ts")]

if len(js_outs) + len(typings_outputs) < 1:
if len(js_outs) + len(typings_outs) < 1:
label = "//{}:{}".format(ctx.label.package, ctx.label.name)
if ctx.attr.transpile:
if len(typings_srcs) > 0:
no_outs_msg = """ts_project target {target} has no outputs, but it has typings in srcs.
Since there is no `tsc` action to perform, this should use a js_library target instead.
You can run the following to change it:
buildozer 'new_load @aspect_rules_js//js:defs.bzl js_library' //{pkg}:__pkg__
buildozer 'set kind js_library' {target}
buildozer 'remove declaration' {target}
""".format(
target = label,
pkg = ctx.label.package,
)
elif ctx.attr.transpile:
no_outs_msg = """ts_project target %s is configured to produce no outputs.
This might be because
Expand All @@ -141,6 +155,7 @@ This might be because
This is an error because Bazel does not run actions unless their outputs are needed for the requested targets to build.
""")

typings_outputs = typings_outs + typing_maps_outs + typings_srcs
if ctx.attr.transpile:
default_outputs_depset = depset(runtime_outputs) if len(runtime_outputs) else depset(typings_outputs)
else:
Expand Down

0 comments on commit 9daa456

Please sign in to comment.