Allow ts_library to contain only .d.ts files
Previously having such a ts_library would error out because the es5 compilation step would not have any outputs (which makes sense since only the es6 compilation step produces the .externs file)
Fixes #24
Closes #115
PiperOrigin-RevId: 180936829
diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel
index b72b530..3d1bcbc 100644
--- a/examples/BUILD.bazel
+++ b/examples/BUILD.bazel
@@ -17,10 +17,15 @@
load("//:defs.bzl", "ts_library")
ts_library(
+ name = "types",
+ srcs = ["types.d.ts"],
+)
+
+ts_library(
name = "foo_ts_library",
srcs = [
+ ":types",
"foo.ts",
- "types.d.ts",
],
tsconfig = ":tsconfig.json",
deps = ["//examples/generated_ts"],
diff --git a/internal/build_defs.bzl b/internal/build_defs.bzl
index 41a0b5c..fc67c45 100644
--- a/internal/build_defs.bzl
+++ b/internal/build_defs.bzl
@@ -25,19 +25,24 @@
def _compile_action(ctx, inputs, outputs, config_file_path):
externs_files = []
- non_externs_files = []
+ action_outputs = []
for output in outputs:
if output.basename.endswith(".externs.js"):
externs_files.append(output)
elif output.basename.endswith(".es5.MF"):
ctx.file_action(output, content="")
else:
- non_externs_files.append(output)
+ action_outputs.append(output)
# TODO(plf): For now we mock creation of files other than {name}.js.
for externs_file in externs_files:
ctx.file_action(output=externs_file, content="")
+ # A ts_library that has only .d.ts inputs will have no outputs,
+ # therefore there are no actions to execute
+ if not action_outputs:
+ return
+
action_inputs = inputs + [f for f in ctx.files.node_modules + ctx.files._tsc_wrapped_deps
if f.path.endswith(".ts") or f.path.endswith(".json")]
if ctx.file.tsconfig:
@@ -59,7 +64,7 @@
progress_message = "Compiling TypeScript (devmode) %s" % ctx.label,
mnemonic = mnemonic,
inputs = action_inputs,
- outputs = non_externs_files,
+ outputs = action_outputs,
arguments = arguments,
executable = ctx.executable.compiler,
execution_requirements = {