Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide @nodejs repository #3610

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ To run the version of node fetched by Bazel which defined in your WORKSPACE you
can use:

```sh
$ bazel run @nodejs_host//:node -- <arguments passed to node>
$ bazel run @nodejs//:node -- <arguments passed to node>
```

For example,

```
$ bazel run @nodejs_host//:node -- --version
$ bazel run @nodejs//:node -- --version
v16.12.0
```

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

```sh
$ bazel run @yarn//:yarn -- <arguments passed to yarn>
$ bazel run @nodejs_host//:npm -- <arguments passed to npm>
$ bazel run @nodejs//:npm -- <arguments passed to npm>
```

This will run yarn/npm in the current working directory.
Expand Down
14 changes: 8 additions & 6 deletions docs/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@ rules_nodejs produces several repositories for you to reference.
Bazel represents your workspace as one repository, and code fetched or installed from outside your workspace lives in other repositories.
These are referenced with the `@repo//` syntax in your BUILD files.

## @nodejs_host
## @nodejs

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

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

```sh
$ bazel query @nodejs_host//...
@nodejs_host//:node
$ bazel query @nodejs//...
@nodejs//:node
...
```

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.
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.

Some ways you can use this:

- Run the Bazel-managed version of node: `bazel run @nodejs_host//:node path/to/program.js`
- Run the Bazel-managed version of npm: `bazel run @nodejs_host//:npm`
- Run the Bazel-managed version of node: `bazel run @nodejs//:node path/to/program.js`
- Run the Bazel-managed version of npm: `bazel run @nodejs//:npm`

(Note: for backward-compatibility, the `@nodejs` repository can also be referenced as `@nodejs_host`).

## @yarn

Expand Down
13 changes: 7 additions & 6 deletions e2e/nodejs_host/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ nodejs_test(
name = "test_default",
data = [
"index.spec.js",
"@nodejs_host//:node",
"@nodejs_host//:node_bin",
"@nodejs_host//:node_files",
"@nodejs_host//:npm",
"@nodejs_host//:npm_bin",
"@nodejs_host//:npm_files",
"@nodejs//:node",
"@nodejs//:node_bin",
"@nodejs//:node_files",
"@nodejs//:npm",
"@nodejs//:npm_bin",
"@nodejs//:npm_files",
# Use the old name for one of the labels, as a test that it still works
"@nodejs_host//:npx_bin",
"@npm//:node_modules",
"@yarn",
Expand Down
6 changes: 6 additions & 0 deletions nodejs/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ def nodejs_register_toolchains(name, register = True, **kwargs):
"@%s_toolchains//:%s_toolchain" % (name, platform),
)

nodejs_repo_host_os_alias(
name = name,
user_node_repository_name = name,
)

# For backwards compatibility, also provide it under the name with _host suffix.
nodejs_repo_host_os_alias(
name = name + "_host",
user_node_repository_name = name,
Expand Down