From c146934209b148579cf6a6b9263ffd6500acfdf7 Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Wed, 8 Mar 2023 23:10:26 -0800 Subject: [PATCH] Restricts overbroad `//visibility:public` usages. `//visibility:public` actually makes the target available to any target _in any workspace_, meaning they are publicly visible to user workspaces. For most of these they were actually intended as being public _internally to `@rules_prerender`_. This updates as many targets as possible to be as restrictive as possible. Unfortunately a decent number of these are referenced from macros and rules invoked in the user's workspace, so they need to be `//visibility:public` even when they are technically implementation details. --- BUILD.bazel | 14 +++++++------- common/BUILD.bazel | 20 +++++++++++--------- common/models/BUILD.bazel | 10 +++++----- common/testing/BUILD.bazel | 14 +++++++------- tools/browsers/BUILD.bazel | 2 +- tools/jasmine/BUILD.bazel | 2 +- tools/publish/BUILD.bazel | 2 +- tools/stamping/BUILD.bazel | 2 +- 8 files changed, 34 insertions(+), 32 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 100f9473..39c20d27 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -9,18 +9,18 @@ load("//tools/stamping:defs.bzl", "stamp_package") load("//tools/typescript:defs.bzl", "types_only") load("//:index.bzl", "link_prerender_component", "prerender_component") -exports_files([".npmrc"], visibility = ["//visibility:public"]) +exports_files([".npmrc"], visibility = ["//:__subpackages__"]) ts_config( name = "tsconfig", src = "tsconfig.json", - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) ts_config( name = "tsconfig_client", src = "tsconfig.client.json", - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = [":tsconfig"], ) @@ -50,23 +50,23 @@ npm_publish( npm_link_package( name = "node_modules/rules_prerender", src = ":rules_prerender_pkg", - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) types_only( name = "node_modules_types/rules_prerender", dep = "//:node_modules/rules_prerender", - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) npm_link_package( name = "node_modules/@rules_prerender/declarative_shadow_dom", src = "//packages/declarative_shadow_dom:pkg", - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) link_prerender_component( name = "prerender_components/@rules_prerender/declarative_shadow_dom", package = ":node_modules/@rules_prerender/declarative_shadow_dom", - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) bzl_library( diff --git a/common/BUILD.bazel b/common/BUILD.bazel index 0c07f237..1b743927 100644 --- a/common/BUILD.bazel +++ b/common/BUILD.bazel @@ -7,6 +7,8 @@ load(":paths_test.bzl", "paths_test_suite") ts_project( name = "binary", srcs = ["binary.mts"], + # Needs to be public because this gets directly linked in the renderer entry + # point generated in the user's workspace. visibility = ["//visibility:public"], deps = ["//:node_modules/@types/node"], ) @@ -29,7 +31,7 @@ jasmine_node_test( ts_project( name = "collections", srcs = ["collections.mts"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) ts_project( @@ -50,7 +52,7 @@ jasmine_node_test( ts_project( name = "formatters", srcs = ["formatters.mts"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) ts_project( @@ -71,14 +73,14 @@ jasmine_node_test( ts_project( name = "file_system", srcs = ["file_system.mts"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = ["//:node_modules/@types/node"], ) ts_project( name = "file_system_fake", srcs = ["file_system_fake.mts"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], testonly = True, deps = [ ":file_system", @@ -89,7 +91,7 @@ ts_project( ts_project( name = "http", srcs = ["http.mts"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = ["//:node_modules/@types/node"], ) @@ -112,7 +114,7 @@ jasmine_node_test( bzl_library( name = "label", srcs = ["label.bzl"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) bzl_library( @@ -126,7 +128,7 @@ label_test_suite(name = "label_test") bzl_library( name = "paths", srcs = ["paths.bzl"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) bzl_library( @@ -140,7 +142,7 @@ paths_test_suite(name = "paths_test") ts_project( name = "prerender_annotation_walker", srcs = ["prerender_annotation_walker.mts"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = [ "//common/models:prerender_annotation", "//:node_modules/node-html-parser", @@ -168,7 +170,7 @@ jasmine_node_test( ts_project( name = "probably", srcs = ["probably.mts"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) ts_project( diff --git a/common/models/BUILD.bazel b/common/models/BUILD.bazel index 9f9588d7..2204eea9 100644 --- a/common/models/BUILD.bazel +++ b/common/models/BUILD.bazel @@ -4,7 +4,7 @@ load("//tools/typescript:defs.bzl", "ts_project") ts_project( name = "prerender_annotation", srcs = ["prerender_annotation.mts"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) ts_project( @@ -26,14 +26,14 @@ ts_project( name = "prerender_annotation_mock", srcs = ["prerender_annotation_mock.mts"], testonly = True, - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = [":prerender_annotation"], ) ts_project( name = "prerender_metadata", srcs = ["prerender_metadata.mts"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], ) ts_project( @@ -55,14 +55,14 @@ ts_project( name = "prerender_metadata_mock", srcs = ["prerender_metadata_mock.mts"], testonly = True, - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = [":prerender_metadata"], ) ts_project( name = "prerender_resource", srcs = ["prerender_resource.mts"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = [":url_path"], ) diff --git a/common/testing/BUILD.bazel b/common/testing/BUILD.bazel index 89e0a66a..7af77b03 100644 --- a/common/testing/BUILD.bazel +++ b/common/testing/BUILD.bazel @@ -6,7 +6,7 @@ ts_project( name = "binary", srcs = ["binary.mts"], testonly = True, - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = ["//:node_modules/@types/node"], ) @@ -31,7 +31,7 @@ ts_project( name = "devserver", srcs = ["devserver.mts"], testonly = True, - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], data = [ "//:node_modules/http-status-codes", "//:node_modules/tree-kill", @@ -110,7 +110,7 @@ ts_project( name = "effect_fake", srcs = ["effect_fake.mts"], testonly = True, - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = [":effects"], ) @@ -134,7 +134,7 @@ ts_project( name = "effect_tester", srcs = ["effect_tester.mts"], testonly = True, - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = [ ":effects", "//:node_modules/@types/jasmine", @@ -162,7 +162,7 @@ ts_project( name = "mocks", srcs = ["mocks.mts"], testonly = True, - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = ["//:node_modules/@types/jasmine"], ) @@ -185,7 +185,7 @@ ts_project( name = "temp_dir", srcs = ["temp_dir.mts"], testonly = True, - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = [ ":effects", "//:node_modules/@types/node", @@ -234,7 +234,7 @@ ts_project( name = "webdriver", srcs = ["webdriver.mts"], testonly = True, - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], data = ["//:node_modules/webdriverio"], deps = [ ":effects", diff --git a/tools/browsers/BUILD.bazel b/tools/browsers/BUILD.bazel index f6fe5cf3..dd3960f8 100644 --- a/tools/browsers/BUILD.bazel +++ b/tools/browsers/BUILD.bazel @@ -27,7 +27,7 @@ custom_browser( "//conditions:default": "chromium_local.json", ":use_debug_browsers_config": "chromium_local_debug.json", }), - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], tags = ["native"], environment = select({ "//conditions:default": None, diff --git a/tools/jasmine/BUILD.bazel b/tools/jasmine/BUILD.bazel index e93811d8..56a75fb5 100644 --- a/tools/jasmine/BUILD.bazel +++ b/tools/jasmine/BUILD.bazel @@ -3,7 +3,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") bzl_library( name = "defs", srcs = ["defs.bzl"], - visibility = ["//visibility:public"], + visibility = ["//:__subpackages__"], deps = [ ":jasmine_node_test", ":jasmine_web_test_suite", diff --git a/tools/publish/BUILD.bazel b/tools/publish/BUILD.bazel index 0e8229c4..9097fd20 100644 --- a/tools/publish/BUILD.bazel +++ b/tools/publish/BUILD.bazel @@ -1,6 +1,6 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") -exports_files(["npm_publish.sh"], visibility = ["//visibility:public"]) +exports_files(["npm_publish.sh"], visibility = ["//:__subpackages__"]) bzl_library( name = "defs", diff --git a/tools/stamping/BUILD.bazel b/tools/stamping/BUILD.bazel index baa9b78e..41e68386 100644 --- a/tools/stamping/BUILD.bazel +++ b/tools/stamping/BUILD.bazel @@ -2,7 +2,7 @@ load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load(":stamp_package.bzl", "stamp_package") -exports_files(["stamp.jq"], visibility = ["//visibility:public"]) +exports_files(["stamp.jq"], visibility = ["//:__subpackages__"]) bzl_library( name = "defs",