diff --git a/internal/js_library/js_library.bzl b/internal/js_library/js_library.bzl index 8e50304ae9..67096a5893 100644 --- a/internal/js_library/js_library.bzl +++ b/internal/js_library/js_library.bzl @@ -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, diff --git a/internal/js_library/test/BUILD.bazel b/internal/js_library/test/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/js_library/test/transitive/BUILD.bazel b/internal/js_library/test/transitive/BUILD.bazel new file mode 100644 index 0000000000..917a518163 --- /dev/null +++ b/internal/js_library/test/transitive/BUILD.bazel @@ -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() diff --git a/internal/js_library/test/transitive/a.d.ts b/internal/js_library/test/transitive/a.d.ts new file mode 100644 index 0000000000..106d610ab9 --- /dev/null +++ b/internal/js_library/test/transitive/a.d.ts @@ -0,0 +1 @@ +export declare const a: string; diff --git a/internal/js_library/test/transitive/transitive_declarations_test.bzl b/internal/js_library/test/transitive/transitive_declarations_test.bzl new file mode 100644 index 0000000000..eea4d944ae --- /dev/null +++ b/internal/js_library/test/transitive/transitive_declarations_test.bzl @@ -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)