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

refactor: all public rules and macros should be prefixed with 'nodejs_' to match convention #3739

Merged
merged 1 commit into from
Apr 3, 2024
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
54 changes: 27 additions & 27 deletions docs/Core.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ UserBuildSettingInfo(<a href="#UserBuildSettingInfo-value">value</a>)
(Undocumented)


## node_repositories
## nodejs_repositories

**USAGE**

<pre>
node_repositories(<a href="#node_repositories-name">name</a>, <a href="#node_repositories-node_download_auth">node_download_auth</a>, <a href="#node_repositories-node_repositories">node_repositories</a>, <a href="#node_repositories-node_urls">node_urls</a>, <a href="#node_repositories-node_version">node_version</a>,
<a href="#node_repositories-node_version_from_nvmrc">node_version_from_nvmrc</a>, <a href="#node_repositories-kwargs">kwargs</a>)
nodejs_repositories(<a href="#nodejs_repositories-name">name</a>, <a href="#nodejs_repositories-node_download_auth">node_download_auth</a>, <a href="#nodejs_repositories-node_repositories">node_repositories</a>, <a href="#nodejs_repositories-node_urls">node_urls</a>, <a href="#nodejs_repositories-node_version">node_version</a>,
<a href="#nodejs_repositories-node_version_from_nvmrc">node_version_from_nvmrc</a>, <a href="#nodejs_repositories-kwargs">kwargs</a>)
</pre>

To be run in user's WORKSPACE to install rules_nodejs dependencies.
Expand All @@ -61,7 +61,7 @@ You can pass in a custom list of Node.js repositories and URLs for node_reposito
To specify custom Node.js versions, use the `node_repositories` attribute

```python
node_repositories(
nodejs_repositories(
node_repositories = {
"10.10.0-darwin_amd64": ("node-v10.10.0-darwin-x64.tar.gz", "node-v10.10.0-darwin-x64", "00b7a8426e076e9bf9d12ba2d571312e833fe962c70afafd10ad3682fdeeaa5e"),
"10.10.0-linux_amd64": ("node-v10.10.0-linux-x64.tar.xz", "node-v10.10.0-linux-x64", "686d2c7b7698097e67bcd68edc3d6b5d28d81f62436c7cf9e7779d134ec262a9"),
Expand All @@ -73,7 +73,7 @@ node_repositories(
These can be mapped to a custom download URL, using `node_urls`

```python
node_repositories(
nodejs_repositories(
node_version = "10.10.0",
node_repositories = {"10.10.0-darwin_amd64": ("node-v10.10.0-darwin-x64.tar.gz", "node-v10.10.0-darwin-x64", "00b7a8426e076e9bf9d12ba2d571312e833fe962c70afafd10ad3682fdeeaa5e")},
node_urls = ["https://mycorpproxy/mirror/node/v{version}/{filename}"],
Expand All @@ -94,21 +94,21 @@ See [toolchains](./toolchains.md).
**PARAMETERS**


<h4 id="node_repositories-name">name</h4>
<h4 id="nodejs_repositories-name">name</h4>

Unique name for the repository rule



<h4 id="node_repositories-node_download_auth">node_download_auth</h4>
<h4 id="nodejs_repositories-node_download_auth">node_download_auth</h4>

Auth to use for all url requests.

Example: { "type": "basic", "login": "&lt;UserName&gt;", "password": "&lt;Password&gt;" }

Defaults to `{}`

<h4 id="node_repositories-node_repositories">node_repositories</h4>
<h4 id="nodejs_repositories-node_repositories">node_repositories</h4>

Custom list of node repositories to use

Expand All @@ -119,7 +119,7 @@ By default, if this attribute has no items, we'll use a list of all public Node.

Defaults to `{}`

<h4 id="node_repositories-node_urls">node_urls</h4>
<h4 id="nodejs_repositories-node_urls">node_urls</h4>

List of URLs to use to download Node.js.

Expand All @@ -130,47 +130,47 @@ and `{filename}` with the matching entry from the `node_repositories` attribute.

Defaults to `["https://nodejs.org/dist/v{version}/{filename}"]`

<h4 id="node_repositories-node_version">node_version</h4>
<h4 id="nodejs_repositories-node_version">node_version</h4>

The specific version of Node.js to install

Defaults to `"18.20.0"`

<h4 id="node_repositories-node_version_from_nvmrc">node_version_from_nvmrc</h4>
<h4 id="nodejs_repositories-node_version_from_nvmrc">node_version_from_nvmrc</h4>

The .nvmrc file containing the version of Node.js to use.

If set then the version found in the .nvmrc file is used instead of the one specified by node_version.

Defaults to `None`

<h4 id="node_repositories-kwargs">kwargs</h4>
<h4 id="nodejs_repositories-kwargs">kwargs</h4>

Additional parameters




## node_toolchain
## nodejs_toolchain

**USAGE**

<pre>
node_toolchain(<a href="#node_toolchain-name">name</a>, <a href="#node_toolchain-node">node</a>, <a href="#node_toolchain-node_path">node_path</a>, <a href="#node_toolchain-npm">npm</a>, <a href="#node_toolchain-npm_path">npm_path</a>, <a href="#node_toolchain-npm_srcs">npm_srcs</a>, <a href="#node_toolchain-headers">headers</a>, <a href="#node_toolchain-kwargs">kwargs</a>)
nodejs_toolchain(<a href="#nodejs_toolchain-name">name</a>, <a href="#nodejs_toolchain-node">node</a>, <a href="#nodejs_toolchain-node_path">node_path</a>, <a href="#nodejs_toolchain-npm">npm</a>, <a href="#nodejs_toolchain-npm_path">npm_path</a>, <a href="#nodejs_toolchain-npm_srcs">npm_srcs</a>, <a href="#nodejs_toolchain-headers">headers</a>, <a href="#nodejs_toolchain-kwargs">kwargs</a>)
</pre>

Defines a node toolchain for a platform.

You can use this to refer to a vendored nodejs binary in your repository,
or even to compile nodejs from sources using rules_foreign_cc or other rules.

First, in a BUILD.bazel file, create a node_toolchain definition:
First, in a BUILD.bazel file, create a nodejs_toolchain definition:

```starlark
load("@rules_nodejs//nodejs:toolchain.bzl", "node_toolchain")
load("@rules_nodejs//nodejs:toolchain.bzl", "nodejs_toolchain")

node_toolchain(
name = "node_toolchain",
nodejs_toolchain(
name = "toolchain",
node = "//some/path/bin/node",
)
```
Expand All @@ -185,7 +185,7 @@ toolchain(
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
toolchain = ":node_toolchain",
toolchain = ":toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)
```
Expand All @@ -202,19 +202,19 @@ You can use the `--toolchain_resolution_debug` flag to `bazel` to help diagnose
**PARAMETERS**


<h4 id="node_toolchain-name">name</h4>
<h4 id="nodejs_toolchain-name">name</h4>

Unique name for this target



<h4 id="node_toolchain-node">node</h4>
<h4 id="nodejs_toolchain-node">node</h4>

Node.js executable

Defaults to `None`

<h4 id="node_toolchain-node_path">node_path</h4>
<h4 id="nodejs_toolchain-node_path">node_path</h4>

Path to Node.js executable file

Expand All @@ -224,13 +224,13 @@ Only one of `node` and `node_path` may be set.

Defaults to `""`

<h4 id="node_toolchain-npm">npm</h4>
<h4 id="nodejs_toolchain-npm">npm</h4>

Npm JavaScript entry point

Defaults to `None`

<h4 id="node_toolchain-npm_path">npm_path</h4>
<h4 id="nodejs_toolchain-npm_path">npm_path</h4>

Path to npm JavaScript entry point.

Expand All @@ -240,21 +240,21 @@ Only one of `npm` and `npm_path` may be set.

Defaults to `""`

<h4 id="node_toolchain-npm_srcs">npm_srcs</h4>
<h4 id="nodejs_toolchain-npm_srcs">npm_srcs</h4>

Additional source files required to run npm.

Not necessary if specifying `npm_path` to a non-hermetic npm installation.

Defaults to `[]`

<h4 id="node_toolchain-headers">headers</h4>
<h4 id="nodejs_toolchain-headers">headers</h4>

cc_library that contains the Node/v8 header files

Defaults to `None`

<h4 id="node_toolchain-kwargs">kwargs</h4>
<h4 id="nodejs_toolchain-kwargs">kwargs</h4>

Additional parameters

Expand Down
8 changes: 4 additions & 4 deletions docs/Toolchains.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ To run a custom toolchain (i.e., to run a node binary not supported by the built

1) A rule which can build or load a node binary from your repository
(a checked-in binary or a build using a relevant [`rules_foreign_cc` build rule](https://bazelbuild.github.io/rules_foreign_cc/) will do nicely).
2) A [`node_toolchain` rule](Core.html#node_toolchain) which depends on your binary defined in step 1 as its `target_tool`.
3) A [`toolchain` rule](https://bazel.build/reference/be/platform#toolchain) that depends on your `node_toolchain` rule defined in step 2 as its `toolchain`
2) A [`nodejs_toolchain` rule](Core.html#nodejs_toolchain) which depends on your binary defined in step 1 as its `node`.
3) A [`toolchain` rule](https://bazel.build/reference/be/platform#toolchain) that depends on your `nodejs_toolchain` rule defined in step 2 as its `toolchain`
and on `@rules_nodejs//nodejs:toolchain_type` as its `toolchain_type`. Make sure to define appropriate platform restrictions as described in the
documentation for the `toolchain` rule.
4) A call to [the `register_toolchains` function](https://bazel.build/rules/lib/globals#register_toolchains) in your `WORKSPACE`
that refers to the `toolchain` rule defined in step 3.

Examples of steps 2-4 can be found in the [documentation for `node_toolchain`](Core.html#node_toolchain).
Examples of steps 2-4 can be found in the [documentation for `nodejs_toolchain`](Core.html#nodejs_toolchain).

If necessary, you can substitute building the node binary as part of the build with using a locally installed version by skipping step 1 and replacing step 2 with:

2) A `node_toolchain` rule which has the path of the system binary as its `target_tool_path`
2) A `nodejs_toolchain` rule which has the path of the system binary as its `node_path`
6 changes: 3 additions & 3 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can choose a specific version of Node.js. We mirror all published versions,
Add to `WORKSPACE`:

```python
node_repositories(
nodejs_repositories(
node_version = "8.11.1",
)
```
Expand All @@ -29,7 +29,7 @@ for example one that you host within your org, you can manually specify those in
```python
load("@rules_nodejs//nodejs:repositories.bzl", "node_repositories")

node_repositories(
nodejs_repositories(
node_version = "8.10.0",
node_repositories = {
"8.10.0-darwin_amd64": ("node-v8.10.0-darwin-x64.tar.gz", "node-v8.10.0-darwin-x64", "7d77bd35bc781f02ba7383779da30bd529f21849b86f14d87e097497671b0271"),
Expand All @@ -45,4 +45,4 @@ Specifying `node_urls` is optional. If omitted, the default values will be used.

You can use your own Node.js binary rather than fetching from the internet.
You could check in a binary file, or build Node.js from sources.
To use See [`node_toolchain`](./Core.md#node_toolchain) for docs.
To use See [`nodejs_toolchain`](./Core.md#nodejs_toolchain) for docs.
2 changes: 1 addition & 1 deletion docs/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ These are referenced with the `@repo//` syntax in your BUILD files.

## @nodejs

This repository is created by calling the `node_repositories` function in your `WORKSPACE` file.
This repository is created by calling the `nodejs_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.
Expand Down
12 changes: 6 additions & 6 deletions e2e/smoke/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ my_nodejs(
# using the select statement will download toolchains for all three platforms
# you can also just provide an individual toolchain if you don't want to download them all
toolchain = select({
"@bazel_tools//src/conditions:linux_x86_64": "@node17_linux_amd64//:node_toolchain",
"@bazel_tools//src/conditions:darwin": "@node17_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@node17_windows_amd64//:node_toolchain",
"@bazel_tools//src/conditions:linux_x86_64": "@node17_linux_amd64//:toolchain",
"@bazel_tools//src/conditions:darwin": "@node17_darwin_amd64//:toolchain",
"@bazel_tools//src/conditions:windows": "@node17_windows_amd64//:toolchain",
}),
)

Expand All @@ -263,9 +263,9 @@ my_nodejs(
# using the select statement will download toolchains for all three platforms
# you can also just provide an individual toolchain if you don't want to download them all
toolchain = select({
"@bazel_tools//src/conditions:linux_x86_64": "@nodejs_linux_amd64//:node_toolchain",
"@bazel_tools//src/conditions:darwin": "@nodejs_darwin_amd64//:node_toolchain",
"@bazel_tools//src/conditions:windows": "@nodejs_windows_amd64//:node_toolchain",
"@bazel_tools//src/conditions:linux_x86_64": "@nodejs_linux_amd64//:toolchain",
"@bazel_tools//src/conditions:darwin": "@nodejs_darwin_amd64//:toolchain",
"@bazel_tools//src/conditions:windows": "@nodejs_windows_amd64//:toolchain",
}),
)

Expand Down
8 changes: 4 additions & 4 deletions e2e/smoke/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

def _my_nodejs_impl(ctx):
if ctx.attr.toolchain:
toolchain = ctx.attr.toolchain[platform_common.ToolchainInfo].nodeinfo
nodeinfo = ctx.attr.toolchain[platform_common.ToolchainInfo].nodeinfo
else:
toolchain = ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo
nodeinfo = ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo
ctx.actions.run(
inputs = toolchain.tool_files + [ctx.file.entry_point],
executable = toolchain.target_tool_path,
inputs = [ctx.file.entry_point],
executable = nodeinfo.node,
arguments = [ctx.file.entry_point.path, ctx.outputs.out.path],
outputs = [ctx.outputs.out],
)
Expand Down
2 changes: 1 addition & 1 deletion nodejs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//nodejs/private:toolchains_repo.bzl", "PLATFORMS")
load("//nodejs/private:nodejs_toolchains_repo.bzl", "PLATFORMS")
load("//nodejs/private:user_build_settings.bzl", "user_args")
load("//nodejs/private:current_node_cc_headers.bzl", "current_node_cc_headers")

Expand Down
8 changes: 4 additions & 4 deletions nodejs/index.for_docs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ load(
":providers.bzl",
_UserBuildSettingInfo = "UserBuildSettingInfo",
)
load(":repositories.bzl", _node_repositories = "node_repositories")
load(":toolchain.bzl", _nodejs_toolchain = "node_toolchain")
load(":repositories.bzl", _nodejs_repositories = "nodejs_repositories")
load(":toolchain.bzl", _nodejs_toolchain = "nodejs_toolchain")

UserBuildSettingInfo = _UserBuildSettingInfo
node_repositories = _node_repositories
node_toolchain = _nodejs_toolchain
nodejs_repositories = _nodejs_repositories
nodejs_toolchain = _nodejs_toolchain
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ PLATFORMS = {
),
}

def _toolchains_repo_impl(repository_ctx):
def _nodejs_toolchains_repo_impl(repository_ctx):
# Expose a concrete toolchain which is the result of Bazel resolving the toolchain
# for the execution or target platform.
# Workaround for https://github.com/bazelbuild/bazel/issues/14009
starlark_content = """# Generated by toolchains_repo.bzl
starlark_content = """# Generated by nodejs_toolchains_repo.bzl

# Forward all the providers
def _resolved_toolchain_impl(ctx):
Expand All @@ -88,7 +88,7 @@ resolved_toolchain = rule(
"""
repository_ctx.file("defs.bzl", starlark_content)

build_content = """# Generated by toolchains_repo.bzl
build_content = """# Generated by nodejs_toolchains_repo.bzl
#
# These can be registered in the workspace file or passed to --extra_toolchains flag.
# By default all these toolchains are registered by the nodejs_register_toolchains macro
Expand All @@ -105,13 +105,13 @@ resolved_toolchain(name = "resolved_toolchain", visibility = ["//visibility:publ
toolchain(
name = "{platform}_toolchain",
exec_compatible_with = {compatible_with},
toolchain = "@{user_node_repository_name}_{platform}//:node_toolchain",
toolchain = "@{user_node_repository_name}_{platform}//:toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)
toolchain(
name = "{platform}_toolchain_target",
target_compatible_with = {compatible_with},
toolchain = "@{user_node_repository_name}_{platform}//:node_toolchain",
toolchain = "@{user_node_repository_name}_{platform}//:toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)
""".format(
Expand All @@ -124,8 +124,8 @@ toolchain(
# Base BUILD file for this repository
repository_ctx.file("BUILD.bazel", build_content)

toolchains_repo = repository_rule(
_toolchains_repo_impl,
nodejs_toolchains_repo = repository_rule(
_nodejs_toolchains_repo_impl,
doc = """Creates a repository with toolchain definitions for all known platforms
which can be registered or selected.""",
attrs = {
Expand Down
Loading
Loading