Skip to content

Commit

Permalink
feat(cli): set generated BUILD npm package target visibility to publi…
Browse files Browse the repository at this point in the history
…c (#7095)

Package targets must be visible when linked by rules_js so public
visibility is a good default.

Close #758

---

### Changes are visible to end-users: yes

- Searched for relevant documentation and updated as needed: yes
- Breaking change (forces users to change their own code or config): no
- Suggested release notes appear below: yes

`configure` generated package targets (`npm_package` or `js_library`)
visibility is now set to public by default.

### Test plan

- Covered by existing test cases

GitOrigin-RevId: 0e6112b2af952a98de0dd6e80339e31bb98089e9
  • Loading branch information
jbedard committed Oct 23, 2024
1 parent 5714815 commit 4e8a610
Show file tree
Hide file tree
Showing 51 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions gazelle/js/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (ts *typeScriptLang) addPackageRule(cfg *JsGazelleConfig, args language.Gen

npmPackage := rule.NewRule(packageTargetKind, packageTargetName)
npmPackage.SetAttr("srcs", npmPackageInfo.sources.Values())
npmPackage.SetAttr("visibility", []string{rule.CheckInternalVisibility(cfg.rel, "//visibility:public")})

result.Gen = append(result.Gen, npmPackage)
result.Imports = append(result.Imports, npmPackageInfo)
Expand Down
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ npm_link_all_packages(name = "node_modules")
npm_package(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps/exports-gen/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ npm_package(
"package.json",
":start.js",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps/exports-ignore/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ npm_package(
"package.json",
":tsc",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps/exports-js/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ npm_package(
"//exports-js/lib:tsc",
"//exports-js/lib2:tsc",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps/exports-single/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ npm_package(
"package.json",
"//exports-single/bin:tsc",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps/exports-ts/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ npm_package(
"package.json",
"//exports-ts/src:tsc",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps/main-custom_ts/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ npm_package(
"package.json",
":m",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps/main-js-gen/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ npm_package(
"package.json",
":start.js",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps/main-js/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ npm_package(
"package.json",
":tsc",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps/main-ts/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ npm_package(
"package.json",
":tsc",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps_lib/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ npm_link_all_packages(name = "node_modules")
js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ npm_link_all_packages(name = "node_modules")
js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
deps = [":start.js"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ js_library(
js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
deps = [":tsc"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps_lib/exports-js/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ npm_link_all_packages(name = "node_modules")
js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
deps = [
"//exports-js/bin:tsc",
"//exports-js/lib:tsc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ npm_link_all_packages(name = "node_modules")
js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
deps = ["//exports-single/bin:tsc"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps_lib/exports-ts/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ npm_link_all_packages(name = "node_modules")
js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
deps = ["//exports-ts/src:tsc"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ ts_project(
js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
deps = [":m"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ npm_link_all_packages(name = "node_modules")
js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
deps = [":start.js"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps_lib/main-js/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ js_library(
js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
deps = [":tsc"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps_lib/main-ts/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ ts_project(
js_library(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
deps = [":tsc"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps_tsconfig/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ npm_link_all_packages(name = "node_modules")
npm_package(
name = "pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
)

ts_config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ npm_package(
"package.json",
":tsc",
],
visibility = ["//visibility:public"],
)

ts_config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ npm_package(
"package.json",
":m",
],
visibility = ["//visibility:public"],
)

ts_config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ npm_package(
"package.json",
":tsc",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_deps_tsconfig/main/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ npm_package(
"package.json",
":tsc",
],
visibility = ["//visibility:public"],
)

ts_config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ npm_package(
"package.json",
":tsc",
],
visibility = ["//visibility:public"],
)

ts_config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ ts_project(
npm_package(
name = "pkg",
srcs = [":tsc"],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ ts_project(
npm_package(
name = "pkg",
srcs = [":tsc"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_target_enabled/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ npm_link_all_packages(name = "node_modules")
npm_package(
name = "npm_package_target_enabled_pkg",
srcs = ["package.json"],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ ts_project(
npm_package(
name = "a_pkg",
srcs = [":a"],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ ts_project(
js_library(
name = "b_pkg",
srcs = [],
visibility = ["//visibility:public"],
deps = [":b"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ ts_project(
npm_package(
name = "c_pkg",
srcs = [":c"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_target_name/lib/b/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ ts_project(
js_library(
name = "b_pkg",
srcs = [],
visibility = ["//visibility:public"],
deps = [":b"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/npm_package_target_name/lib/c/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ ts_project(
npm_package(
name = "c_pkg",
srcs = [":c"],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ ts_project(
js_library(
name = "b_pkg",
srcs = [],
visibility = ["//visibility:public"],
deps = [":b"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ ts_project(
npm_package(
name = "c_pkg",
srcs = [":c"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_project_refs_lock5/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ npm_link_all_packages(name = "node_modules")
npm_package(
name = "pnpm_project_refs",
srcs = ["package.json"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_project_refs_lock5/lib/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ npm_package(
"package.json",
":lib_lib",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_project_refs_lock6/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ npm_link_all_packages(name = "node_modules")
npm_package(
name = "pnpm_project_refs",
srcs = ["package.json"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_project_refs_lock6/lib/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ npm_package(
"package.json",
":lib_lib",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_project_refs_lock9/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ npm_link_all_packages(name = "node_modules")
npm_package(
name = "pnpm_project_refs",
srcs = ["package.json"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_project_refs_lock9/lib/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ npm_package(
"package.json",
":lib_lib",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_workspace/lib/a/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ ts_project(
npm_package(
name = "a",
srcs = [":a_lib"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_workspace/lib/b/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ ts_project(
npm_package(
name = "b",
srcs = [":b_lib"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_workspace/lib/c/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ ts_project(
js_library(
name = "c",
srcs = [],
visibility = ["//visibility:public"],
deps = [":c_lib"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_workspace_rerooted/lib/a/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ ts_project(
npm_package(
name = "a",
srcs = [":a_lib"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_workspace_rerooted/lib/b/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ ts_project(
npm_package(
name = "b",
srcs = [":b_lib"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/pnpm_workspace_rerooted/lib/c/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ ts_project(
npm_package(
name = "c",
srcs = [":c_lib"],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions gazelle/js/tests/tsconfig_pnpm_ref/tools/BUILD.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ npm_link_all_packages(name = "node_modules")
npm_package(
name = "tools",
srcs = ["package.json"],
visibility = ["//visibility:public"],
)

ts_config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ npm_link_all_packages(name = "node_modules")
npm_package(
name = "tools",
srcs = ["package.json"],
visibility = ["//visibility:public"],
)

ts_config(
Expand Down

0 comments on commit 4e8a610

Please sign in to comment.