Skip to content

Commit a5755eb

Browse files
committed
feat: provide @nodejs repository
Generally it's a bad practice that the user calls a repository rule (nodejs_register_toolchains) with a name, and this doesn't result in a repository with that name. Leave the old _host variant around to make this a non-breaking change. We did the same fix in python: bazel-contrib/rules_python#656 Fixes #3375
1 parent 916ae55 commit a5755eb

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

docs/dependencies.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ To run the version of node fetched by Bazel which defined in your WORKSPACE you
232232
can use:
233233

234234
```sh
235-
$ bazel run @nodejs_host//:node -- <arguments passed to node>
235+
$ bazel run @nodejs//:node -- <arguments passed to node>
236236
```
237237

238238
For example,
239239

240240
```
241-
$ bazel run @nodejs_host//:node -- --version
241+
$ bazel run @nodejs//:node -- --version
242242
v16.12.0
243243
```
244244

@@ -248,7 +248,7 @@ To run the Bazel fetched npm and/or yarn you can use:
248248

249249
```sh
250250
$ bazel run @yarn//:yarn -- <arguments passed to yarn>
251-
$ bazel run @nodejs_host//:npm -- <arguments passed to npm>
251+
$ bazel run @nodejs//:npm -- <arguments passed to npm>
252252
```
253253

254254
This will run yarn/npm in the current working directory.

docs/repositories.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@ rules_nodejs produces several repositories for you to reference.
44
Bazel represents your workspace as one repository, and code fetched or installed from outside your workspace lives in other repositories.
55
These are referenced with the `@repo//` syntax in your BUILD files.
66

7-
## @nodejs_host
7+
## @nodejs
88

99
This repository is created by calling the `node_repositories` function in your `WORKSPACE` file.
1010
It contains the node, npm, and npx programs.
1111

1212
As always, `bazel query` is useful for learning about what targets are available.
1313

1414
```sh
15-
$ bazel query @nodejs_host//...
16-
@nodejs_host//:node
15+
$ bazel query @nodejs//...
16+
@nodejs//:node
1717
...
1818
```
1919

20-
You don't typically need to reference the `@nodejs_host` repository from your BUILD files because it's used behind the scenes to run node and fetch dependencies.
20+
You don't typically need to reference the `@nodejs` repository from your BUILD files because it's used behind the scenes to run node and fetch dependencies.
2121

2222
Some ways you can use this:
2323

24-
- Run the Bazel-managed version of node: `bazel run @nodejs_host//:node path/to/program.js`
25-
- Run the Bazel-managed version of npm: `bazel run @nodejs_host//:npm`
24+
- Run the Bazel-managed version of node: `bazel run @nodejs//:node path/to/program.js`
25+
- Run the Bazel-managed version of npm: `bazel run @nodejs//:npm`
26+
27+
(Note: for backward-compatibility, the `@nodejs` repository can also be referenced as `@nodejs_host`).
2628

2729
## @yarn
2830

e2e/nodejs_host/BUILD.bazel

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ nodejs_test(
77
name = "test_default",
88
data = [
99
"index.spec.js",
10-
"@nodejs_host//:node",
11-
"@nodejs_host//:node_bin",
12-
"@nodejs_host//:node_files",
13-
"@nodejs_host//:npm",
14-
"@nodejs_host//:npm_bin",
15-
"@nodejs_host//:npm_files",
10+
"@nodejs//:node",
11+
"@nodejs//:node_bin",
12+
"@nodejs//:node_files",
13+
"@nodejs//:npm",
14+
"@nodejs//:npm_bin",
15+
"@nodejs//:npm_files",
16+
# Use the old name for one of the labels, as a test that it still works
1617
"@nodejs_host//:npx_bin",
1718
"@npm//:node_modules",
1819
"@yarn",

nodejs/repositories.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ def nodejs_register_toolchains(name, register = True, **kwargs):
404404
"@%s_toolchains//:%s_toolchain" % (name, platform),
405405
)
406406

407+
nodejs_repo_host_os_alias(
408+
name = name,
409+
user_node_repository_name = name,
410+
)
411+
412+
# For backwards compatibility, also provide it under the name with _host suffix.
407413
nodejs_repo_host_os_alias(
408414
name = name + "_host",
409415
user_node_repository_name = name,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy