Skip to content

Commit 41f8719

Browse files
duartenalexeagle
authored andcommitted
fix(builtin): js_library: correctly propagate DeclarationInfos
Transitive typings are added to typings_depsets, but we were checking the typings array instead. Signed-off-by: Duarte Nunes <duarte@hey.com>
1 parent 5a58030 commit 41f8719

5 files changed

Lines changed: 36 additions & 1 deletion

File tree

internal/js_library/js_library.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def _impl(ctx):
214214

215215
# Don't provide DeclarationInfo if there are no typings to provide.
216216
# Improves error messaging downstream if DeclarationInfo is required.
217-
if len(typings):
217+
if len(typings) or len(typings_depsets) > 1:
218218
providers.append(declaration_info(
219219
declarations = depset(transitive = typings_depsets),
220220
deps = ctx.attr.deps,

internal/js_library/test/BUILD.bazel

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
load("//:index.bzl", "js_library")
2+
load(":transitive_declarations_test.bzl", "transitive_declarations_test_suite")
3+
4+
js_library(
5+
name = "a",
6+
srcs = ["a.d.ts"],
7+
)
8+
9+
js_library(
10+
name = "b",
11+
deps = ["a"],
12+
)
13+
14+
transitive_declarations_test_suite()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare const a: string;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"Unit tests for js_library rule"
2+
3+
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
4+
load("//:providers.bzl", "DeclarationInfo")
5+
6+
def _impl(ctx):
7+
env = unittest.begin(ctx)
8+
decls = []
9+
for decl in ctx.attr.lib[DeclarationInfo].declarations.to_list():
10+
decls.append(decl.basename)
11+
asserts.equals(env, ctx.attr.declarations, decls)
12+
return unittest.end(env)
13+
14+
transitive_declarations_test = unittest.make(_impl, attrs = {
15+
"declarations": attr.string_list(default = ["a.d.ts"]),
16+
"lib": attr.label(default = ":b"),
17+
})
18+
19+
def transitive_declarations_test_suite():
20+
unittest.suite("transitive_declarations_tests", transitive_declarations_test)

0 commit comments

Comments
 (0)