Skip to content

Commit

Permalink
refactor: change default linked target name to 'pkg' (#1684)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed May 7, 2024
1 parent f825d3c commit 640b728
Show file tree
Hide file tree
Showing 27 changed files with 48 additions and 51 deletions.
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ diff_test(
# the `npm_package` target depends on.
npm_link_package(
name = "node_modules/@mycorp/pkg-b",
src = "//examples/npm_package/packages/pkg_b",
src = "//examples/npm_package/packages/pkg_b:pkg",
)

# Manually linked pkg-c with additional use cases.
Expand Down
2 changes: 1 addition & 1 deletion docs/npm_translate_lock.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/pnpm_workspace/lib/a/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages(name = "node_modules")

npm_package(
name = "a",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/pnpm_workspace/lib/b/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages(name = "node_modules")

npm_package(
name = "b",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/pnpm_workspace/lib/c/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages(name = "node_modules")

npm_package(
name = "c",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/pnpm_workspace/vendored/a/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

npm_package(
name = "a",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/pnpm_workspace/vendored/b/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

npm_package(
name = "b",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
6 changes: 3 additions & 3 deletions e2e/pnpm_workspace_deps/lib-dupes/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ npm_link_all_packages(name = "node_modules")

# A library with 2 aliases to one simple dependency (package with no dependencies)
js_library(
name = "js_lib_dupes",
name = "lib-dupes",
srcs = ["index.js"],
data = [
# Two versions of the same package (via aliases), see https://github.com/aspect-build/rules_js/issues/1110
Expand All @@ -18,10 +18,10 @@ js_library(

# Exposed via npm_package()
npm_package(
name = "lib-dupes",
name = "pkg",
srcs = [
"package.json",
":js_lib_dupes",
":lib-dupes",
],
visibility = ["//visibility:public"],
)
6 changes: 3 additions & 3 deletions e2e/pnpm_workspace_deps/lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ npm_link_all_packages(name = "node_modules")

# A basic library with 2 simple dependencies (packages with no dependencies))
js_library(
name = "js_lib",
name = "lib",
srcs = ["index.js"],
data = [
":node_modules/@aspect-test/e",
Expand All @@ -17,10 +17,10 @@ js_library(

# Exposed via npm_package()
npm_package(
name = "lib",
name = "pkg",
srcs = [
"package.json",
":js_lib",
":lib",
],
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion e2e/pnpm_workspace_deps/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ npm_link_all_packages(name = "node_modules")
js_test(
name = "direct",
data = [
"//lib:js_lib",
"//lib",
],
entry_point = "test_file_all_linked.js",
)
Expand Down
2 changes: 1 addition & 1 deletion e2e/pnpm_workspace_rerooted/lib/a/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages(name = "node_modules")

npm_package(
name = "a",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/pnpm_workspace_rerooted/lib/b/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages(name = "node_modules")

npm_package(
name = "b",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/pnpm_workspace_rerooted/lib/c/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages(name = "node_modules")

npm_package(
name = "c",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/pnpm_workspace_rerooted/vendored/a/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

npm_package(
name = "a",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/webpack_devserver/mylib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

npm_package(
name = "mylib",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion e2e/webpack_devserver_esm/mylib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

npm_package(
name = "mylib",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
8 changes: 4 additions & 4 deletions examples/linked_empty_node_modules/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/npm_package/packages/pkg_a/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ js_library(
# rule encodes the linking logic for this dependency into the generated 'npm_link_all_packages'
# marco.
npm_package(
name = "pkg_a",
name = "pkg",
srcs = [":lib"],
# The package name does not need to be specified in this target since the name
# that this package is linked as is set by the pnpm lockfile. If it is
Expand Down
2 changes: 1 addition & 1 deletion examples/npm_package/packages/pkg_b/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ npm_link_all_packages(name = "node_modules")
# The terminal npm_package target for this package. This target is linked
# manually in the root of the pnpm workspace with `npm_link_package`.
npm_package(
name = "pkg_b",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion examples/npm_package/packages/pkg_d/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@npm//:defs.bzl", "npm_link_all_packages")
npm_link_all_packages(name = "node_modules")

js_library(
name = "pkg_d",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion npm/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _npm_translate_lock_attrs():
attrs["run_lifecycle_hooks"] = attr.bool(default = True)

# Args defaulted differently by the macro
attrs["npm_package_target_name"] = attr.string(default = "{dirname}")
attrs["npm_package_target_name"] = attr.string(default = "pkg")
attrs["patch_args"] = attr.string_list_dict(default = {"*": ["-p0"]})

attrs.pop("repositories_bzl_filename")
Expand Down
11 changes: 4 additions & 7 deletions npm/private/npm_translate_lock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def npm_translate_lock(
link_workspace = None,
pnpm_version = LATEST_PNPM_VERSION,
use_pnpm = None,
npm_package_target_name = "{dirname}",
npm_package_target_name = "pkg",
**kwargs):
"""Repository macro to generate starlark code from a lock file.
Expand Down Expand Up @@ -503,14 +503,11 @@ def npm_translate_lock(
Use `pnpm_version` for non-bzlmod.
npm_package_target_name: The name of linked `npm_package` targets. When `npm_package` targets are linked as pnpm workspace
packages, the name of the target must align with this value.
npm_package_target_name: The name of linked `npm_package`, `js_library` or `JsInfo` producing targets.
The `{dirname}` placeholder is replaced with the directory name of the target.
By default the directory name of the target is used.
When targets are linked as pnpm workspace packages, the name of the target must align with this value.
Default: `{dirname}`
The `{dirname}` placeholder is replaced with the directory name of the target.
**kwargs: Internal use only
"""
Expand Down
8 changes: 4 additions & 4 deletions npm/private/test/npm_package/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ js_library(
)

npm_package(
name = "npm_package",
name = "pkg",
srcs = [":lib_a"],
visibility = ["//visibility:public"],
)

copy_to_directory(
name = "expected_npm_package",
name = "expected_pkg",
srcs = [
"index.js",
":package.json",
Expand All @@ -36,6 +36,6 @@ copy_to_directory(

diff_test(
name = "test",
file1 = ":npm_package",
file2 = ":expected_npm_package",
file1 = ":pkg",
file2 = ":expected_pkg",
)
10 changes: 5 additions & 5 deletions npm/private/test/snapshots/bzlmod/npm_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions npm/private/test/snapshots/wksp/npm_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion npm/private/test/vendored/is-odd/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

npm_package(
name = "is-odd",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down
2 changes: 1 addition & 1 deletion npm/private/test/vendored/semver-max/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

npm_package(
name = "semver-max",
name = "pkg",
srcs = [
"index.js",
"package.json",
Expand Down

0 comments on commit 640b728

Please sign in to comment.