Skip to content

Commit

Permalink
fix(builtin): js_library: correctly propagate DeclarationInfos
Browse files Browse the repository at this point in the history
Transitive typings are added to typings_depsets, but we were checking
the typings array instead.

Signed-off-by: Duarte Nunes <[email protected]>
  • Loading branch information
duarten authored and alexeagle committed Sep 24, 2020
1 parent 5a58030 commit 41f8719
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/js_library/js_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _impl(ctx):

# Don't provide DeclarationInfo if there are no typings to provide.
# Improves error messaging downstream if DeclarationInfo is required.
if len(typings):
if len(typings) or len(typings_depsets) > 1:
providers.append(declaration_info(
declarations = depset(transitive = typings_depsets),
deps = ctx.attr.deps,
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions internal/js_library/test/transitive/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("//:index.bzl", "js_library")
load(":transitive_declarations_test.bzl", "transitive_declarations_test_suite")

js_library(
name = "a",
srcs = ["a.d.ts"],
)

js_library(
name = "b",
deps = ["a"],
)

transitive_declarations_test_suite()
1 change: 1 addition & 0 deletions internal/js_library/test/transitive/a.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const a: string;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"Unit tests for js_library rule"

load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
load("//:providers.bzl", "DeclarationInfo")

def _impl(ctx):
env = unittest.begin(ctx)
decls = []
for decl in ctx.attr.lib[DeclarationInfo].declarations.to_list():
decls.append(decl.basename)
asserts.equals(env, ctx.attr.declarations, decls)
return unittest.end(env)

transitive_declarations_test = unittest.make(_impl, attrs = {
"declarations": attr.string_list(default = ["a.d.ts"]),
"lib": attr.label(default = ":b"),
})

def transitive_declarations_test_suite():
unittest.suite("transitive_declarations_tests", transitive_declarations_test)

0 comments on commit 41f8719

Please sign in to comment.