diff --git a/internal/js_library/js_library.bzl b/internal/js_library/js_library.bzl index 0a296c04cf..4066d1b70c 100644 --- a/internal/js_library/js_library.bzl +++ b/internal/js_library/js_library.bzl @@ -223,15 +223,25 @@ def _impl(ctx): if DefaultInfo in dep: files_depsets.append(dep[DefaultInfo].files) + runfiles = ctx.runfiles( + files = all_files, + transitive_files = depset( + transitive = files_depsets + typings_depsets, + ), + ) + deps_runfiles = [d[DefaultInfo].default_runfiles for d in ctx.attr.deps] + + # Perf optimization available in newer Bazel releases + if "merge_all" in dir(runfiles): + runfiles = runfiles.merge_all(deps_runfiles) + else: + for d in deps_runfiles: + runfiles = runfiles.merge(d) + providers = [ DefaultInfo( files = depset(transitive = files_depsets), - runfiles = ctx.runfiles( - files = all_files, - transitive_files = depset( - transitive = files_depsets + typings_depsets, - ), - ), + runfiles = runfiles, ), AmdNamesInfo(names = ctx.attr.amd_names), js_ecma_script_module_info( diff --git a/internal/js_library/test/transitive/BUILD.bazel b/internal/js_library/test/transitive/BUILD.bazel index 917a518163..43ecbd803f 100644 --- a/internal/js_library/test/transitive/BUILD.bazel +++ b/internal/js_library/test/transitive/BUILD.bazel @@ -1,13 +1,30 @@ load("//:index.bzl", "js_library") load(":transitive_declarations_test.bzl", "transitive_declarations_test_suite") +load("//packages/typescript:index.bzl", "ts_project") + +js_library( + name = "c", + srcs = [ + "c.d.ts", + "c.txt", + ], +) + +ts_project( + name = "b", + srcs = ["b.ts"], + tsconfig = {}, + deps = ["c"], +) js_library( name = "a", srcs = ["a.d.ts"], + deps = ["b"], ) js_library( - name = "b", + name = "terminal", deps = ["a"], ) diff --git a/internal/js_library/test/transitive/b.ts b/internal/js_library/test/transitive/b.ts new file mode 100644 index 0000000000..54b82a09ad --- /dev/null +++ b/internal/js_library/test/transitive/b.ts @@ -0,0 +1 @@ +const a = 1; diff --git a/internal/js_library/test/transitive/c.d.ts b/internal/js_library/test/transitive/c.d.ts new file mode 100644 index 0000000000..140818bf08 --- /dev/null +++ b/internal/js_library/test/transitive/c.d.ts @@ -0,0 +1 @@ +export declare const c: string; diff --git a/internal/js_library/test/transitive/c.txt b/internal/js_library/test/transitive/c.txt new file mode 100644 index 0000000000..d4ba854782 --- /dev/null +++ b/internal/js_library/test/transitive/c.txt @@ -0,0 +1 @@ +this is a \ No newline at end of file diff --git a/internal/js_library/test/transitive/transitive_declarations_test.bzl b/internal/js_library/test/transitive/transitive_declarations_test.bzl index eea4d944ae..5e0a14e274 100644 --- a/internal/js_library/test/transitive/transitive_declarations_test.bzl +++ b/internal/js_library/test/transitive/transitive_declarations_test.bzl @@ -5,15 +5,23 @@ 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) + asserts.equals(env, ctx.attr.expected_declarations, sorted(decls)) + + runfiles = [] + for r in ctx.attr.lib[DefaultInfo].default_runfiles.files.to_list(): + runfiles.append(r.basename) + asserts.equals(env, ctx.attr.expected_runfiles, sorted(runfiles)) + return unittest.end(env) transitive_declarations_test = unittest.make(_impl, attrs = { - "declarations": attr.string_list(default = ["a.d.ts"]), - "lib": attr.label(default = ":b"), + "expected_declarations": attr.string_list(default = ["a.d.ts"]), + "lib": attr.label(default = ":terminal"), + "expected_runfiles": attr.string_list(default = ["a.d.ts", "b.js", "c.d.ts", "c.txt"]), }) def transitive_declarations_test_suite():