Skip to content

Commit

Permalink
fix(npm): use canonical repo name for cross-repo npm_translate_lock (
Browse files Browse the repository at this point in the history
…#1876)

This prevents an error such as the following when trying to run a `js_binary` defined in another module with Bzlmod:

```
ERROR: .../external/rules_pyright~/BUILD:6:23: no such package '@@[unknown repo 'rules_pyright~' requested from @@rules_pyright~]//': The repository '@@[unknown repo 'rules_pyright~' requested from @@rules_pyright~]' could not be resolved: No repository visible as '@rules_pyright~' from repository '@@rules_pyright~' and referenced by '@@rules_pyright~//:pyright__entry_point'
```
  • Loading branch information
fmeum authored Aug 4, 2024
1 parent e306629 commit 521914e
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 61 deletions.
1 change: 1 addition & 0 deletions e2e/bzlmod/.bazelignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
other_module
6 changes: 6 additions & 0 deletions e2e/bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ build_test(
name = "node_modules_test",
targets = ["//:node_modules"],
)

# Verifies that a `js_binary` target from another module can be built
build_test(
name = "other_module_binary_test",
targets = ["@other_module//:pyright"],
)
6 changes: 6 additions & 0 deletions e2e/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ local_path_override(
path = "../..",
)

bazel_dep(name = "other_module")
local_path_override(
module_name = "other_module",
path = "other_module",
)

bazel_dep(name = "aspect_bazel_lib", version = "2.7.7", dev_dependency = True)
bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True)

Expand Down
1 change: 1 addition & 0 deletions e2e/bzlmod/other_module/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions e2e/bzlmod/other_module/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules)
hoist=false
10 changes: 10 additions & 0 deletions e2e/bzlmod/other_module/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@npm_other_module//:defs.bzl", "npm_link_all_packages")
load("@npm_other_module//:pyright/package_json.bzl", pyright = "bin")

npm_link_all_packages(name = "node_modules")

pyright.pyright_binary(
name = "pyright",
env = {"BAZEL_BINDIR": "."}, # Allow the binary to be run outside bazel
visibility = ["//visibility:public"],
)
12 changes: 12 additions & 0 deletions e2e/bzlmod/other_module/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module(name = "other_module")

bazel_dep(name = "aspect_rules_js", version = "0.0.0")

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")
npm.npm_translate_lock(
name = "npm_other_module",
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm_other_module")
2 changes: 2 additions & 0 deletions e2e/bzlmod/other_module/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file that this folder is the root of a Bazel workspace.
# See MODULE.bazel for dependencies and setup.
5 changes: 5 additions & 0 deletions e2e/bzlmod/other_module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"pyright": "1.1.373"
}
}
37 changes: 37 additions & 0 deletions e2e/bzlmod/other_module/pnpm-lock.yaml

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

12 changes: 6 additions & 6 deletions e2e/pnpm_lockfiles/v54/snapshots/rollup3_package_json.bzl

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

12 changes: 6 additions & 6 deletions e2e/pnpm_lockfiles/v54/snapshots/rollup_package_json.bzl

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

12 changes: 6 additions & 6 deletions e2e/pnpm_lockfiles/v60/snapshots/rollup3_package_json.bzl

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

12 changes: 6 additions & 6 deletions e2e/pnpm_lockfiles/v60/snapshots/rollup_package_json.bzl

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

12 changes: 6 additions & 6 deletions e2e/pnpm_lockfiles/v61/snapshots/rollup3_package_json.bzl

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

Loading

0 comments on commit 521914e

Please sign in to comment.