Skip to content

Commit

Permalink
feat: simplify public API link_js_package and package label helpers (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored May 31, 2022
1 parent fab8f7e commit ef86fcc
Show file tree
Hide file tree
Showing 33 changed files with 1,192 additions and 934 deletions.
37 changes: 34 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@npm//:defs.bzl", "link_js_packages")
load("@acorn__8.4.0__links//:link_js_package.bzl", link_acorn = "link_js_package")
load("//js:defs.bzl", "link_js_package", "link_js_package_dep")

# Link all packages from the /WORKSPACE translate_pnpm_lock in the package.json to
# bazel-bin/examples/node_modules as well as the virtual store since this package.json
# is the root of the pnpm workspace
# Link all packages from the /WORKSPACE translate_pnpm_lock in /package.json to
# bazel-bin/node_modules as well as the virtual store bazel-bin/node_modules/.aspect_rules_js
# since /package.json is the root of the pnpm workspace
link_js_packages()

# Link the acorn package, which was fetched separately with npm_import from /WORKSPACE, to the
# virtual store in bazel-bin/node_modules/.aspect_rules_js
link_acorn(
name = "acorn_link",
# `direct` set to False as an example of *not* also linking this 3rd dependency as a
# direct dependency in the package at bazel-bin/node_modules/@mycorp/mylib. Alternately,
# you may specify link_packages in the npm_import of this package and direct is then
# automatically set to True when this is called in the packages listed.
direct = False,
)

# Linking a first-party dependency to the virtual store in bazel-bin/node_modules/.aspect_rules_js
link_js_package(
name = "mycorp_mylib_link",
src = "//examples/lib",
# `direct` set to False as an example of *not* also linking this first-party dependency as a
# direct dependency in the package at bazel-bin/node_modules/@mycorp/mylib.
direct = False,
deps = [
# For a 3rd party deps fetched with an npm_import or via a translate_pnpm_lock repository rule,
# you must specify both the name and version to qualify the dependency. These should match the
# `package` and `version` attributes of the corresponding `npm_import`.
link_js_package_dep(
"acorn",
version = "8.4.0",
),
],
)

gazelle_binary(
name = "gazelle_bin",
languages = ["@bazel_skylib//gazelle/bzl"],
Expand Down
7 changes: 4 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ translate_pnpm_lock(
"@gregmagolan/test-a": ["-p1"],
},
patches = {
"@gregmagolan/test-a": ["//examples:patches/test-a.patch"],
"@gregmagolan/[email protected]": ["//examples:patches/[email protected]"],
"@gregmagolan/test-a": ["//examples/npm_deps:patches/test-a.patch"],
"@gregmagolan/[email protected]": ["//examples/npm_deps:patches/[email protected]"],
},
pnpm_lock = "//:pnpm-lock.yaml",
)
Expand All @@ -70,6 +70,7 @@ npm_import(
name = "acorn__8.4.0",
integrity = "sha512-ULr0LDaEqQrMFGyQ3bhJkLsbtrQ8QibAseGZeaSUiT/6zb9IvIkomWHJIvgvwad+hinRAgsI51JcWk2yvwyL+w==",
package = "acorn",
root_path = "examples",
# Root package where to link the virtual store
root_package = "",
version = "8.4.0",
)
97 changes: 94 additions & 3 deletions docs/link_js_package.md

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

8 changes: 4 additions & 4 deletions docs/npm_import.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/link_js_package/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@npm//:defs.bzl", "link_js_packages")
load("@aspect_rules_js//js:defs.bzl", "link_js_package")
load("@rules_foo_npm//@aspect-test/a:package_json.bzl", aspect_test_a_bin = "bin")
load("@rules_foo_npm//foo/@aspect-test/a:package_json.bzl", aspect_test_a_bin = "bin")

link_js_packages()

Expand Down
4 changes: 2 additions & 2 deletions e2e/link_js_package/src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ js_binary(
"@npm//@aspect-test/a",
"@npm//@aspect-test/b",
"@npm//@aspect-test/c",
"@rules_foo_npm//@aspect-test/a",
"@rules_foo_npm//foo/@aspect-test/a",
],
entry_point = "main.js",
)
Expand All @@ -21,7 +21,7 @@ js_test(
"@npm//@aspect-test/a",
"@npm//@aspect-test/b",
"@npm//@aspect-test/c",
"@rules_foo_npm//@aspect-test/a",
"@rules_foo_npm//foo/@aspect-test/a",
],
entry_point = "main.js",
log_level = "info",
Expand Down
14 changes: 7 additions & 7 deletions e2e/pnpm_workspace_dot_dot/app/a/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_test")
load("@npm//:defs.bzl", "link_js_packages")
load("@npm//dot_dot/app/a/@aspect-test/a:package_json.bzl", aspect_test_a_bin = "bin")
load("@npm//app/a/@aspect-test/a:package_json.bzl", aspect_test_a_bin = "bin")

link_js_packages()

js_binary(
name = "main",
args = ["foo"],
data = [
"@npm//@aspect-test",
"@npm//dot_dot/app/a/@aspect-test",
"@npm//dot_dot/app/a/@lib",
"@npm//app/a/@aspect-test",
"@npm//app/a/@lib",
"@npm//root/@aspect-test",
],
entry_point = "main.js",
)
Expand All @@ -19,9 +19,9 @@ js_test(
name = "test",
args = ["foo"],
data = [
"@npm//@aspect-test",
"@npm//dot_dot/app/a/@aspect-test",
"@npm//dot_dot/app/a/@lib",
"@npm//app/a/@aspect-test",
"@npm//app/a/@lib",
"@npm//root/@aspect-test",
],
entry_point = "main.js",
log_level = "info",
Expand Down
24 changes: 12 additions & 12 deletions e2e/pnpm_workspace_dot_dot/app/b/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ js_binary(
name = "main",
args = ["foo"],
data = [
"@npm//@aspect-test/a",
"@npm//@aspect-test/b",
"@npm//@aspect-test/c",
"@npm//dot_dot/app/b/@aspect-test/h",
"@npm//dot_dot/app/b/@lib/b",
"@npm//dot_dot/app/b/@lib/b_alias",
"@npm//app/b/@aspect-test/h",
"@npm//app/b/@lib/b",
"@npm//app/b/@lib/b_alias",
"@npm//root/@aspect-test/a",
"@npm//root/@aspect-test/b",
"@npm//root/@aspect-test/c",
],
entry_point = "main.js",
)
Expand All @@ -21,12 +21,12 @@ js_test(
name = "test",
args = ["foo"],
data = [
"@npm//@aspect-test/a",
"@npm//@aspect-test/b",
"@npm//@aspect-test/c",
"@npm//dot_dot/app/b/@aspect-test/h",
"@npm//dot_dot/app/b/@lib/b",
"@npm//dot_dot/app/b/@lib/b_alias",
"@npm//app/b/@aspect-test/h",
"@npm//app/b/@lib/b",
"@npm//app/b/@lib/b_alias",
"@npm//root/@aspect-test/a",
"@npm//root/@aspect-test/b",
"@npm//root/@aspect-test/c",
],
entry_point = "main.js",
log_level = "info",
Expand Down
4 changes: 2 additions & 2 deletions e2e/rules_foo/foo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ link_js_packages()
js_binary(
name = "main",
data = [
"@rules_foo_npm//@aspect-test/a",
"@rules_foo_npm//foo/@aspect-test/a",
],
entry_point = "main.js",
)

js_test(
name = "test",
data = [
"@rules_foo_npm//@aspect-test/a",
"@rules_foo_npm//foo/@aspect-test/a",
],
entry_point = "main.js",
log_level = "info",
Expand Down
Loading

0 comments on commit ef86fcc

Please sign in to comment.