From cc3cfed79e306e764bd3621b121480316a592441 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Tue, 3 Sep 2024 08:42:03 -0700 Subject: [PATCH] fix(npm): respect npm_package include_transitive_sources attribute (#1912) --- npm/private/npm_package.bzl | 2 +- npm/private/test/npm_package/BUILD.bazel | 88 ++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/npm/private/npm_package.bzl b/npm/private/npm_package.bzl index 4620478b4..2674da275 100644 --- a/npm/private/npm_package.bzl +++ b/npm/private/npm_package.bzl @@ -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, )) diff --git a/npm/private/test/npm_package/BUILD.bazel b/npm/private/test/npm_package/BUILD.bazel index cb697e6df..186906f2b 100644 --- a/npm/private/test/npm_package/BUILD.bazel +++ b/npm/private/test/npm_package/BUILD.bazel @@ -9,6 +9,7 @@ npm_link_all_packages(name = "node_modules") js_library( name = "lib_a", srcs = [ + ":index.d.ts", ":index.js", ":package.json", ], @@ -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"], @@ -39,6 +46,7 @@ npm_package( copy_to_directory( name = "expected_pkg", srcs = [ + "index.d.ts", "index.js", ":package.json", ], @@ -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"],