Skip to content

Commit 39c70c3

Browse files
committed
feat(bazel): extract types from ts_project targets (#2912)
Look for types and transitive types in JsInfo provider. PR Close #2912
1 parent 124003d commit 39c70c3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

bazel/extract_types_rjs.bzl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
load("@aspect_rules_js//js:providers.bzl", "JsInfo")
2+
3+
def _extract_types_impl(ctx):
4+
"""Implementation of the `extract_types` rule."""
5+
depsets = []
6+
7+
for dep in ctx.attr.deps:
8+
if JsInfo in dep:
9+
depsets.append(dep[JsInfo].transitive_types)
10+
depsets.append(dep[JsInfo].types)
11+
12+
types = depset(transitive = depsets)
13+
14+
return [
15+
DefaultInfo(files = types),
16+
]
17+
18+
extract_types = rule(
19+
implementation = _extract_types_impl,
20+
doc = """
21+
Rule that collects all direct and transitive type definitions of specified targets. The
22+
definitons are then exposed through the `DefaultInfo` provider, allowing for easy
23+
consumption in other rules.
24+
25+
This rule can be helpful if TypeScript typings are shipped along with bundled runtime code.
26+
""",
27+
attrs = {
28+
"deps": attr.label_list(
29+
doc = """List of targets for which all direct and transitive type definitions
30+
should be collected.""",
31+
allow_files = True,
32+
mandatory = True,
33+
),
34+
},
35+
)

0 commit comments

Comments
 (0)