-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bazel): add rule for extracting type definitions from targets (#430
) Adds a rule that collects all direct and transitive type definitions of specified targets. The definitons are then exposed through the `DefaultInfo` provider, allowing for easy consumption in other rules. This rule can be helpful if TypeScript typings are shipped along with bundled runtime code. PR Close #430
- Loading branch information
1 parent
b710e5b
commit 53786a3
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo") | ||
|
||
def _extract_types_impl(ctx): | ||
"""Implementation of the `extract_types` rule.""" | ||
depsets = [] | ||
|
||
for dep in ctx.attr.deps: | ||
if DeclarationInfo in dep: | ||
depsets.append(dep[DeclarationInfo].transitive_declarations) | ||
|
||
types = depset(transitive = depsets) | ||
|
||
return [ | ||
DefaultInfo(files = types), | ||
] | ||
|
||
extract_types = rule( | ||
implementation = _extract_types_impl, | ||
doc = """ | ||
Rule that collects all direct and transitive type definitions of specified targets. The | ||
definitons are then exposed through the `DefaultInfo` provider, allowing for easy | ||
consumption in other rules. | ||
This rule can be helpful if TypeScript typings are shipped along with bundled runtime code. | ||
""", | ||
attrs = { | ||
"deps": attr.label_list( | ||
doc = """List of targets for which all direct and transitive type definitions | ||
should be collected.""", | ||
mandatory = True, | ||
), | ||
}, | ||
) |