Skip to content

Commit

Permalink
feat: add ts_project(deps) validation ensuring all deps of declarations
Browse files Browse the repository at this point in the history
Fix #30
  • Loading branch information
jbedard committed Oct 27, 2022
1 parent f640256 commit 05ad849
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ts/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def ts_project(
Read more: https://blog.aspect.dev/typescript-speedup
validate: Whether to check that the tsconfig JSON settings match the attributes on this target.
validate: Whether to check that the dependencies are valid and the tsconfig JSON settings match the attributes on this target.
Set this to `False` to skip running our validator, in case you have a legitimate reason for these to differ,
e.g. you have a setting enabled just for the editor but you want different behavior when Bazel runs `tsc`.
Expand Down Expand Up @@ -342,6 +342,7 @@ def ts_project(
allow_js = allow_js,
tsconfig = tsconfig,
extends = extends,
deps = deps,
validator = validator,
**common_kwargs
)
Expand Down
9 changes: 9 additions & 0 deletions ts/private/ts_validate_options.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
load(":ts_config.bzl", "TsConfigInfo")
load(":ts_lib.bzl", "COMPILER_OPTION_ATTRS", "ValidOptionsInfo")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_files_to_bin_actions")
load("@aspect_rules_js//js:providers.bzl", "JsInfo")

def _tsconfig_inputs(ctx):
"""Returns all transitively referenced tsconfig files from "tsconfig" and "extends" attributes."""
Expand All @@ -23,6 +24,13 @@ def _validate_options_impl(ctx):
# We make it a .d.ts file so we can plumb it to the deps of the ts_project compile.
marker = ctx.actions.declare_file("%s.optionsvalid.d.ts" % ctx.label.name)

# Provider validation
if not ctx.attr.allow_js:
for d in ctx.attr.deps:
if not d[JsInfo].declarations:
fail("ts_project '%s' does not contain any declarations" % d)

# External validation
arguments = ctx.actions.args()
config = struct(
allow_js = ctx.attr.allow_js,
Expand Down Expand Up @@ -56,6 +64,7 @@ def _validate_options_impl(ctx):
]

_ATTRS = dict(COMPILER_OPTION_ATTRS, **{
"deps": attr.label_list(mandatory = True, providers = [JsInfo]),
"target": attr.string(),
"ts_build_info_file": attr.string(),
"tsconfig": attr.label(mandatory = True, allow_single_file = [".json"]),
Expand Down

0 comments on commit 05ad849

Please sign in to comment.