Skip to content

Commit e915877

Browse files
committed
fix(builtin): npm_package_bin include runfiles in DefaultInfo (#3261)
1 parent 4889a1a commit e915877

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

internal/node/npm_package_bin.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ def _impl(ctx):
8989
exit_code_out = ctx.outputs.exit_code_out,
9090
link_workspace_root = ctx.attr.link_workspace_root,
9191
)
92-
93-
return [DefaultInfo(files = depset(outputs + tool_outputs))]
92+
files = outputs + tool_outputs
93+
return [DefaultInfo(
94+
files = depset(files),
95+
runfiles = ctx.runfiles(files = files),
96+
)]
9497

9598
_npm_package_bin = rule(
9699
_impl,

internal/node/test/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load("//:index.bzl", "js_library")
44
load("//packages/jasmine:index.bzl", "jasmine_node_test")
55
load("//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file")
66
load("@bazel_skylib//rules:write_file.bzl", "write_file")
7+
load(":npm_package_bin_test.bzl", "npm_package_bin_test_suite")
78

89
# You can have a nodejs_binary with no node_modules attribute
910
# and no fine grained deps
@@ -258,6 +259,8 @@ npm_package_bin(
258259
stdout = "minified.stdout.js",
259260
)
260261

262+
npm_package_bin_test_suite()
263+
261264
generated_file_test(
262265
name = "stdout_output_test",
263266
src = "stdout_output_test.golden",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"Unit tests for js_library rule"
2+
3+
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
4+
5+
def _impl(ctx):
6+
env = unittest.begin(ctx)
7+
8+
runfiles = []
9+
for r in ctx.attr.lib[DefaultInfo].default_runfiles.files.to_list():
10+
runfiles.append(r.basename)
11+
asserts.equals(env, ctx.attr.expected_runfiles, sorted(runfiles))
12+
13+
return unittest.end(env)
14+
15+
runfiles_test = unittest.make(_impl, attrs = {
16+
"lib": attr.label(default = ":run_terser"),
17+
"expected_runfiles": attr.string_list(default = ["minified.js"]),
18+
})
19+
20+
def npm_package_bin_test_suite():
21+
unittest.suite("runfiles", runfiles_test)

0 commit comments

Comments
 (0)