From 4923fbfcd13163f82e1c09cc5cfd76b306327a87 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Tue, 28 May 2024 02:41:26 -0700 Subject: [PATCH] fix: include package store directory in default output of npm_link_package_store --- examples/genrule/BUILD.bazel | 4 +--- npm/private/npm_link_package_store.bzl | 2 +- npm/private/test/npm_package/BUILD.bazel | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/genrule/BUILD.bazel b/examples/genrule/BUILD.bazel index dd176bb96..24b922a95 100644 --- a/examples/genrule/BUILD.bazel +++ b/examples/genrule/BUILD.bazel @@ -31,13 +31,12 @@ genrule( name = "call_acorn", srcs = [ ":one.js", - # reference the location where the "acorn" npm package was linked in our root Bazel package. - "//:node_modules/acorn", "//:node_modules/acorn/dir", ], outs = ["out1"], cmd = " ".join([ "$(NODE_PATH)", + # reference the location where the "acorn" npm package was linked in the rules_js npm package store. "./$(execpath //:node_modules/acorn/dir)/bin/acorn", "--compact", "$(execpath :one.js)", @@ -69,7 +68,6 @@ genrule( ":require_acorn_js", # reference the location where the "acorn" npm package was linked in our root Bazel package. "//:node_modules/acorn", - "//:node_modules/acorn/dir", ], outs = ["out2"], cmd = """ diff --git a/npm/private/npm_link_package_store.bzl b/npm/private/npm_link_package_store.bzl index f523bca70..2af66d9b0 100644 --- a/npm/private/npm_link_package_store.bzl +++ b/npm/private/npm_link_package_store.bzl @@ -92,7 +92,7 @@ def _npm_link_package_store_impl(ctx): ) files.append(bin_file) - files_depset = depset(files) + files_depset = depset(files, transitive = [store_info.files]) transitive_files_depset = depset(files, transitive = [store_info.transitive_files]) diff --git a/npm/private/test/npm_package/BUILD.bazel b/npm/private/test/npm_package/BUILD.bazel index c671cc78a..cb697e6df 100644 --- a/npm/private/test/npm_package/BUILD.bazel +++ b/npm/private/test/npm_package/BUILD.bazel @@ -26,6 +26,16 @@ npm_package( visibility = ["//visibility:public"], ) +npm_package( + name = "pkg_2", + srcs = [ + ":lib_a", + ":node_modules/chalk", # should be excluded + "//:node_modules/chalk", # should be excluded + ], + visibility = ["//visibility:public"], +) + copy_to_directory( name = "expected_pkg", srcs = [ @@ -40,6 +50,12 @@ diff_test( file2 = ":expected_pkg", ) +diff_test( + name = "test_pkg_2", + file1 = ":pkg_2", + file2 = ":expected_pkg", +) + npm_package( name = "pkg_with_node_modules", srcs = [":lib_a"], @@ -53,7 +69,6 @@ copy_to_directory( srcs = [ "index.js", ":node_modules/chalk", - ":node_modules/chalk/dir", ":package.json", ], )