Skip to content

Commit a3a343f

Browse files
MichaelMitchell-atjbedard
authored andcommitted
Add transitive typecheck output group
1 parent 6d4e575 commit a3a343f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ts/defs.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,9 @@ def ts_project(
387387
# If the primary target does not output dts files then type-checking has a separate target.
388388
if not emit_tsc_js or not emit_tsc_dts:
389389
typecheck_target_name = "%s_typecheck" % name
390+
transitive_typecheck_target_name = "%s_transitive_typecheck" % name
390391
test_target_name = "%s_typecheck_test" % name
392+
transitive_typecheck_test_target_name = "%s_transitive_typecheck_test" % name
391393

392394
# Users should build this target to get a failed build when typechecking fails
393395
native.filegroup(
@@ -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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ 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+
target[OutputGroupInfo].transitive_typecheck
35+
for target in targets
36+
if OutputGroupInfo in target and "transitive_typecheck" in target[OutputGroupInfo]
37+
]
38+
return depset(typecheck_outs, transitive = files_depsets)
39+
3240
def _ts_project_impl(ctx):
3341
"""Creates the action which spawns `tsc`.
3442
@@ -315,6 +323,8 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
315323

316324
transitive_types = js_lib_helpers.gather_transitive_types(output_types, srcs_tsconfig_deps)
317325

326+
transitive_typecheck = _gather_transitive_typecheck_from_output_group_infos(typecheck_outs, ctx.attr.deps)
327+
318328
npm_sources = js_lib_helpers.gather_npm_sources(
319329
srcs = ctx.attr.srcs + [ctx.attr.tsconfig],
320330
deps = ctx.attr.deps,
@@ -362,6 +372,7 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
362372
OutputGroupInfo(
363373
types = output_types_depset,
364374
typecheck = depset(typecheck_outs),
375+
transitive_typecheck = transitive_typecheck,
365376
# make the inputs to the tsc action available for analysis testing
366377
_action_inputs = transitive_inputs_depset,
367378
# https://bazel.build/extending/rules#validations_output_group

0 commit comments

Comments
 (0)