Skip to content

Commit

Permalink
fix(builtin): js_library: propagate all default_runfiles (#3183)
Browse files Browse the repository at this point in the history
Fixes #3182
  • Loading branch information
alexeagle committed Jan 8, 2022
1 parent a134b49 commit 0361609
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
22 changes: 16 additions & 6 deletions internal/js_library/js_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,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(
Expand Down
19 changes: 18 additions & 1 deletion internal/js_library/test/transitive/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)

Expand Down
1 change: 1 addition & 0 deletions internal/js_library/test/transitive/b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const a = 1;
1 change: 1 addition & 0 deletions internal/js_library/test/transitive/c.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const c: string;
1 change: 1 addition & 0 deletions internal/js_library/test/transitive/c.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ load("@rules_nodejs//nodejs: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():
Expand Down

0 comments on commit 0361609

Please sign in to comment.