rules_nodejs icon indicating copy to clipboard operation
rules_nodejs copied to clipboard

[FR]: Support .nvmrc file in BZLMOD

Open BillyBlaze opened this issue 1 year ago • 1 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.

BillyBlaze avatar Mar 08 '24 11:03 BillyBlaze

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!

github-actions[bot] avatar May 08 '24 01:05 github-actions[bot]

please dont close 😄

BillyBlaze avatar May 29 '24 07:05 BillyBlaze

@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 avatar May 29 '24 11:05 setoelkahfi

@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!

BillyBlaze avatar Jun 03 '24 14:06 BillyBlaze