Skip to content

Commit

Permalink
fix(builtin): npm_package_bin include runfiles in DefaultInfo (#3261)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Jan 20, 2022
1 parent 4889a1a commit e915877
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/node/npm_package_bin.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ def _impl(ctx):
exit_code_out = ctx.outputs.exit_code_out,
link_workspace_root = ctx.attr.link_workspace_root,
)

return [DefaultInfo(files = depset(outputs + tool_outputs))]
files = outputs + tool_outputs
return [DefaultInfo(
files = depset(files),
runfiles = ctx.runfiles(files = files),
)]

_npm_package_bin = rule(
_impl,
Expand Down
3 changes: 3 additions & 0 deletions internal/node/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load("//:index.bzl", "js_library")
load("//packages/jasmine:index.bzl", "jasmine_node_test")
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load(":npm_package_bin_test.bzl", "npm_package_bin_test_suite")

# You can have a nodejs_binary with no node_modules attribute
# and no fine grained deps
Expand Down Expand Up @@ -258,6 +259,8 @@ npm_package_bin(
stdout = "minified.stdout.js",
)

npm_package_bin_test_suite()

generated_file_test(
name = "stdout_output_test",
src = "stdout_output_test.golden",
Expand Down
21 changes: 21 additions & 0 deletions internal/node/test/npm_package_bin_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"Unit tests for js_library rule"

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

def _impl(ctx):
env = unittest.begin(ctx)

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)

runfiles_test = unittest.make(_impl, attrs = {
"lib": attr.label(default = ":run_terser"),
"expected_runfiles": attr.string_list(default = ["minified.js"]),
})

def npm_package_bin_test_suite():
unittest.suite("runfiles", runfiles_test)

0 comments on commit e915877

Please sign in to comment.