v1.37.0
Many companies are successfully building with rules_js.
If you're getting value from the project, please let us know!
Just comment on our Adoption Discussion.
Note
🏎️ This release adds a performance improvement for parsing the pnpm lock file in the npm_translate_lock
repository rule by using yq from aspect_bazel_lib. yq is approx 7X faster than the custom Starlark yaml parser used prior to this release. Thanks to @dzbarsky for teeing this one up in #1378 🧙.
Benchmarks on two different size lock files:
- 100k line lock file: starlark yaml parser 3.5s, yq 470ms
- 27k line lock file: starlark yaml parser 1.6s, yq 240ms
If you have issues with yq
yaml parsing, you can switch to the legacy starlark yaml parser by setting use_starlark_yaml_parser = True
on your npm_translate_lock
. In exceptional cases, it is possible that pnpm will generate a yaml file that yq
fails to parse. See the PR summary of #1458 for more details.
Using Bzlmod with Bazel 6:
Add to your MODULE.bazel
file:
bazel_dep(name = "aspect_rules_js", version = "1.37.0")
####### Node.js version #########
# By default you get the node version from DEFAULT_NODE_VERSION in @rules_nodejs//nodejs:repositories.bzl
# Optionally you can pin a different node version:
bazel_dep(name = "rules_nodejs", version = "5.8.2")
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version = "16.14.2")
#################################
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
name = "npm",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm")
Using WORKSPACE
Paste this snippet into your WORKSPACE
file:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "aspect_rules_js",
sha256 = "7130820ce72d11489501479accc0072d45e53a916e4abc5e91b680b7374b3dad",
strip_prefix = "rules_js-1.37.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.37.0/rules_js-v1.37.0.tar.gz",
)
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
rules_js_dependencies()
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
nodejs_register_toolchains(
name = "nodejs",
node_version = DEFAULT_NODE_VERSION,
)
# For convenience, npm_translate_lock does this call automatically.
# Uncomment if you don't call npm_translate_lock at all.
#load("@bazel_features//:deps.bzl", "bazel_features_deps")
#bazel_features_deps()
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
npm_translate_lock(
name = "npm",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)
load("@npm//:repositories.bzl", "npm_repositories")
npm_repositories()
To use rules_js with bazel-lib 2.x, you must additionally register the coreutils toolchain.
load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains")
register_coreutils_toolchains()
What's Changed
- chore: switch to a gitpkg.vercel.app that doens't trip pnpm/pnpm#5414 by @gregmagolan in #1459
- chore: sort node toolchains in MODULE.bazel files by @gregmagolan in #1461
- chore: improve error messages on rctx.execute calls by @gregmagolan in #1460
- fix: only output warnings on lockfile parsing when regenerating lockfile by @jbedard in #1454
- feat: use yq to parse yaml file by @gregmagolan in #1458
Full Changelog: v1.36.1...v1.37.0