bazelbuild / rules_nodejs

NodeJS toolchain for Bazel.

Home Page:https://bazelbuild.github.io/rules_nodejs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FR]: Support .nvmrc file in BZLMOD

BillyBlaze opened this issue · comments

What is the current behavior?

I am currently migrating from the WORKSPACE file to BZLMOD. In the previous version we could register the toolchain to look for the .nvmrc file, such as:

nodejs_register_toolchains(
    name = "nodejs",
    use_nvmrc = "//:.nvmrc",
)

however in BZLMOD we can only provide the version hardcoded:

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version = "20.8.0")

can we get the new toolchain to also include the .nvmrc file?

Describe the feature

Currently we have a single source of truth that manages the node version in our mono-repo. Without this feature the danger is that people will work locally with a different version than rules_nodejs are using. Reading the version from this file will make sure that CI and locally are more closely intertwined.

This issue has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs in 30 days. Note as of rules_nodejs v6 the rules_nodejs repository contains only the core nodejs toolchain and @bazel/runfiles package. All rulesets are removed and unmaintained. For alternate rulesets suggestions include https://github.com/aspect-build/rules_js, https://github.com/aspect-build/rules_ts Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

please dont close 😄

@BillyBlaze This seems to be working fine for me:

bazel_dep(name = "rules_nodejs", version = "6.1.1")
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version_from_nvmrc = "//:.nvmrc")

See.

@setoelkahfi thank you for the feedback! I didn't notice that this was introduced after I posted this issue. It would've been great that that they closed this issue with a fixed status, but I am more than happy that it landed!