Skip to content

Commit 1bd06dd

Browse files
Add transitive typecheck output group
1 parent 5e25e91 commit 1bd06dd

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

ts/defs.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ def ts_project(
370370
if not emit_tsc_js or not emit_tsc_dts:
371371
types_target_name = "%s_types" % name
372372
typecheck_target_name = "%s_typecheck" % name
373+
transitive_typecheck_target_name = "%s_transitive_typecheck" % name
373374
test_target_name = "%s_typecheck_test" % name
375+
transitive_typecheck_test_target_name = "%s_transitive_typecheck_test" % name
374376

375377
# Users should build this target to get typing files
376378
if not no_emit:
@@ -397,6 +399,14 @@ def ts_project(
397399
**common_kwargs
398400
)
399401

402+
# Users should build this target to get a failed build when typechecking fails
403+
native.filegroup(
404+
name = transitive_typecheck_target_name,
405+
srcs = [name],
406+
output_group = "transitive_typecheck",
407+
**common_kwargs
408+
)
409+
400410
# Ensures the typecheck target gets built under `bazel test --build_tests_only`
401411
build_test(
402412
name = test_target_name,
@@ -406,6 +416,14 @@ def ts_project(
406416
visibility = common_kwargs.get("visibility"),
407417
)
408418

419+
build_test(
420+
name = transitive_typecheck_test_target_name,
421+
targets = [transitive_typecheck_target_name],
422+
tags = common_kwargs.get("tags"),
423+
size = "small",
424+
visibility = common_kwargs.get("visibility"),
425+
)
426+
409427
# Disable workers if a custom tsc was provided but not a custom tsc_worker.
410428
if tsc != _tsc and tsc_worker == _tsc_worker:
411429
supports_workers = 0

ts/private/ts_project.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ def _gather_types_from_js_infos(targets):
2929
])
3030
return depset([], transitive = files_depsets)
3131

32+
def _gather_transitive_typecheck_from_output_group_infos(typecheck_outs, targets):
33+
files_depsets = []
34+
files_depsets.extend([
35+
target[OutputGroupInfo].transitive_typecheck
36+
for target in targets
37+
if OutputGroupInfo in target and "transitive_typecheck" in target[OutputGroupInfo]
38+
])
39+
return depset(typecheck_outs, transitive = files_depsets)
40+
3241
def _ts_project_impl(ctx):
3342
"""Creates the action which spawns `tsc`.
3443
@@ -308,6 +317,8 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
308317

309318
transitive_types = js_lib_helpers.gather_transitive_types(output_types, srcs_tsconfig_deps)
310319

320+
transitive_typecheck = _gather_transitive_typecheck_from_output_group_infos(typecheck_outs, ctx.attr.deps)
321+
311322
npm_sources = js_lib_helpers.gather_npm_sources(
312323
srcs = ctx.attr.srcs + [ctx.attr.tsconfig],
313324
deps = ctx.attr.deps,
@@ -345,6 +356,7 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
345356
OutputGroupInfo(
346357
types = output_types_depset,
347358
typecheck = depset(typecheck_outs),
359+
transitive_typecheck = transitive_typecheck,
348360
# make the inputs to the tsc action available for analysis testing
349361
_action_inputs = transitive_inputs_depset,
350362
# https://bazel.build/extending/rules#validations_output_group

0 commit comments

Comments
 (0)