Skip to content

Migrating to 5.0

Alex Eagle edited this page Dec 23, 2021 · 21 revisions

rules_nodejs dependencies

Prior to 5.0, the build_bazel_rules_nodejs workspace had zero starlark dependencies, because transitive handling of them in WORKSPACE was so difficult for users to get right. However now that Bazel 5.0 has bzlmod to manage these transitive dependencies, we feel it's the right time to add dependencies. (Documentation for using rules_nodejs with bzlmod will be added soon)

You need to update your WORKSPACE file to install the dependencies. Note that WORKSPACE ordering is critical, so if you need to override versions of rules_nodejs dependencies, you must do it before this code.

load("@build_bazel_rules_nodejs//nodejs:repositories.bzl", "rules_nodejs_dependencies")

rules_nodejs_dependencies()

Next, you can remove usage of node_repositories, which is now deprecated.

load("@build_bazel_rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")

nodejs_register_toolchains(
    # You can choose whatever name you like for the node toolchains, or register more than one version.
    name = "nodejs",
)

npm_install and yarn_install are repository rules, which means they can't use Bazel's toolchain resolution to see what you registered. By default, they'll look for "nodejs", and so if you use name = "nodejs" like the example above, then no changes are needed.

If you choose a different name, you have to tell npm_install and yarn_install what it is, e.g.

npm_install(
    node_repository = "my_node",
    ...
)

Users of vendored_yarn

You'll have to continue using node_repositories for now. Follow https://github.com/bazelbuild/rules_nodejs/issues/3175 for a migration path.

Users of "user managed dependencies"

You'll have to continue using node_repositories for now. We would like to remove this feature. Please tell us in https://github.com/bazelbuild/rules_nodejs/issues/3176 if you still rely on it.

nodejs_image from rules_docker

Get new release of rules_docker after commit TODO and add attribute to nodejs_image pointing to the node toolchain you registered, e.g. node_repository_name = "my_node_linux_amd64"

Updated defaults

The default nodejs version is now 16.12.0. To go back to the previous default, put this in your WORKSPACE:

nodejs_register_toolchains(
    node_version = "14.17.5",
)

Default version of Node is now X and Yarn is Y to continue using the previous default: Z

exports_directories_only

TODO: greg npm_umd_bundle can't work with exports_directories_only. https://github.com/bazelbuild/rules_nodejs/commit/c87ec6b084cdb95ec2503256bf2ef222fbca6b77

Moved

Dropped providers

todo Greg https://github.com/bazelbuild/rules_nodejs/commit/7f688a95c9002a9e5148f218dfa9f1ea6464f50a

Toolchain definition

The toolchain name is now controlled by the WORKSPACE file. The hard-coded @nodejs repo no longer exists.

In the examples below, we assume you used name "my_node" in your call to nodejs_register_toolchains.

If you explicitly used a label like @nodejs//:node, you can find a platform-specific variant at @my_node_linux_amd64//:node.

Custom rules should now use @rules_nodejs//nodejs:toolchain_type to request a nodejs toolchain. Genrules should now use @my_node_toolchains//:resolved_toolchain.

See e2e/core for example of using the toolchain.

If you used our platform definitions, they have changed from e.g. --platforms=@build_bazel_rules_nodejs//toolchains/node:darwin_amd64 to --platforms=@rules_nodejs//nodejs:darwin_amd64"

However, the new toolchain declares compatibility with the execution platform (node running as a tool to produce outputs), not with the target platform. So there's no need to pass a --platforms flag at this time, since we still don't cross-compile anything to the target platform.

angular

@bazel/angular is a minimal plugin for the Angular CLI builders system (aka. architect) teaching the ng command how to spawn bazel for build and test steps.

It has been moved from this repo and can now be found in https://github.com/just-jeb/angular-builders Thanks to @just-jeb for taking on maintenance of this code!

labs

The @bazel/labs package has been removed, and is no longer published to npm. This repo doesn't contain support for protocol buffers or gRPC.

ts_library

The ts_library rule is now in the @bazel/concatjs package. The @build_bazel_rules_typescript workspace no longer exists, the code was moved into the concatjs package.

nodejs_binary attrs

repository_args todo https://github.com/bazelbuild/rules_nodejs/commit/90c7fe07e086c8ba63e0e75cb65a181b90e0960e node todo https://github.com/bazelbuild/rules_nodejs/commit/cb8374633a93724c4df4be19ebfa09a0c81339c2

Reduced maintenance scope

The concatjs package is now in "maintenance mode". Since no one from Google participates in rules_nodejs, it has been impossible for us to keep this code up-to-date with what Google develops internally, and it is a complex package that OSS maintainers don't have time for.

Clone this wiki locally