Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add transitive typecheck output group #714

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ts/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ def ts_project(
if not emit_tsc_js or not emit_tsc_dts:
types_target_name = "%s_types" % name
typecheck_target_name = "%s_typecheck" % name
transitive_typecheck_target_name = "%s_transitive_typecheck" % name
test_target_name = "%s_typecheck_test" % name
transitive_typecheck_test_target_name = "%s_transitive_typecheck_test" % name

# Users should build this target to get typing files
if not no_emit:
Expand All @@ -397,6 +399,16 @@ def ts_project(
**common_kwargs
)

# Users should build this target to get a failed build when typechecking fails
native.filegroup(
name = transitive_typecheck_target_name,
srcs = [name],
output_group = "transitive_typecheck",
tags = ["manual"] + common_kwargs.get("tags", []),
visibility = common_kwargs.get("visibility"),
testonly = common_kwargs.get("testonly"),
)

# Ensures the typecheck target gets built under `bazel test --build_tests_only`
build_test(
name = test_target_name,
Expand All @@ -406,6 +418,14 @@ def ts_project(
visibility = common_kwargs.get("visibility"),
)

build_test(
jbedard marked this conversation as resolved.
Show resolved Hide resolved
name = transitive_typecheck_test_target_name,
targets = [transitive_typecheck_target_name],
tags = ["manual"] + common_kwargs.get("tags", []),
size = "small",
visibility = common_kwargs.get("visibility"),
)

# Disable workers if a custom tsc was provided but not a custom tsc_worker.
if tsc != _tsc and tsc_worker == _tsc_worker:
supports_workers = 0
Expand Down
11 changes: 11 additions & 0 deletions ts/private/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def _gather_types_from_js_infos(targets):
])
return depset([], transitive = files_depsets)

def _gather_transitive_typecheck_from_output_group_infos(typecheck_outs, targets):
files_depsets = [
target[OutputGroupInfo].transitive_typecheck
for target in targets
if OutputGroupInfo in target and "transitive_typecheck" in target[OutputGroupInfo]
]
return depset(typecheck_outs, transitive = files_depsets)

def _ts_project_impl(ctx):
"""Creates the action which spawns `tsc`.

Expand Down Expand Up @@ -308,6 +316,8 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.

transitive_types = js_lib_helpers.gather_transitive_types(output_types, srcs_tsconfig_deps)

transitive_typecheck = _gather_transitive_typecheck_from_output_group_infos(typecheck_outs, ctx.attr.deps)

npm_sources = js_lib_helpers.gather_npm_sources(
srcs = ctx.attr.srcs + [ctx.attr.tsconfig],
deps = ctx.attr.deps,
Expand Down Expand Up @@ -345,6 +355,7 @@ See https://github.com/aspect-build/rules_ts/issues/361 for more details.
OutputGroupInfo(
types = output_types_depset,
typecheck = depset(typecheck_outs),
transitive_typecheck = transitive_typecheck,
# make the inputs to the tsc action available for analysis testing
_action_inputs = transitive_inputs_depset,
# https://bazel.build/extending/rules#validations_output_group
Expand Down
Loading