Skip to content

Commit

Permalink
fix(npm): respect npm_package include_transitive_sources attribute (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Sep 3, 2024
1 parent ccc4210 commit cc3cfed
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion npm/private/npm_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _npm_package_files_impl(ctx):
ctx.attr.srcs,
include_sources = ctx.attr.include_sources,
include_types = ctx.attr.include_types,
include_transitive_sources = ctx.attr.include_types,
include_transitive_sources = ctx.attr.include_transitive_sources,
include_transitive_types = ctx.attr.include_transitive_types,
include_npm_sources = ctx.attr.include_npm_sources,
))
Expand Down
88 changes: 88 additions & 0 deletions npm/private/test/npm_package/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ npm_link_all_packages(name = "node_modules")
js_library(
name = "lib_a",
srcs = [
":index.d.ts",
":index.js",
":package.json",
],
Expand All @@ -20,6 +21,12 @@ js_library(
],
)

# Wrap lib_a in another library to test transitive dependencies
js_library(
name = "lib_a_a",
deps = [":lib_a"],
)

npm_package(
name = "pkg",
srcs = [":lib_a"],
Expand All @@ -39,6 +46,7 @@ npm_package(
copy_to_directory(
name = "expected_pkg",
srcs = [
"index.d.ts",
"index.js",
":package.json",
],
Expand All @@ -56,6 +64,86 @@ diff_test(
file2 = ":expected_pkg",
)

npm_package(
name = "pkg_3",
srcs = [
":lib_a",
],
include_transitive_types = False,
include_types = False,
visibility = ["//visibility:public"],
)

npm_package(
name = "pkg_4",
srcs = [
":lib_a_a",
],
include_transitive_types = False,
include_types = True, # should not include transitive
visibility = ["//visibility:public"],
)

copy_to_directory(
name = "expected_no-types_pkg",
srcs = [
"index.js",
":package.json",
],
)

diff_test(
name = "test_pkg_3",
file1 = ":pkg_3",
file2 = ":expected_no-types_pkg",
)

diff_test(
name = "test_pkg_4",
file1 = ":pkg_4",
file2 = ":expected_no-types_pkg",
)

npm_package(
name = "pkg_5",
srcs = [
":lib_a",
],
include_sources = False,
include_transitive_sources = False,
visibility = ["//visibility:public"],
)

npm_package(
name = "pkg_6",
srcs = [
":lib_a_a",
],
include_sources = True, # should not include transitive
include_transitive_sources = False,
visibility = ["//visibility:public"],
)

copy_to_directory(
name = "expected_no-sources_pkg",
srcs = [
"index.d.ts",
":package.json",
],
)

diff_test(
name = "test_pkg_5",
file1 = ":pkg_5",
file2 = ":expected_pkg", # NOTE: includes everything because .js is in the DefaultInfo
)

diff_test(
name = "test_pkg_6",
file1 = ":pkg_6",
file2 = ":expected_no-sources_pkg",
)

npm_package(
name = "pkg_with_node_modules",
srcs = [":lib_a"],
Expand Down

0 comments on commit cc3cfed

Please sign in to comment.