Skip to content
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
27 changes: 27 additions & 0 deletions e2e/smoke/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ write_file(
content = ["v16.5.0"],
)

write_file(
name = "write_node_version_24",
out = "expected_node_24",
content = ["v24.12.0"],
)

# To see what nodejs version is used by default
my_nodejs(
name = "run_no_toolchain",
Expand Down Expand Up @@ -312,3 +318,24 @@ diff_test(
file1 = "write_node_version_15",
file2 = "thing_toolchain_15",
)

my_nodejs(
name = "run_24",
out = "thing_toolchain_24",
entry_point = "version.js",
# 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": "@node24_linux_amd64//:toolchain",
"@bazel_tools//src/conditions:linux_aarch64": "@node24_linux_arm64//:toolchain",
"@bazel_tools//src/conditions:darwin_x86_64": "@node24_darwin_amd64//:toolchain",
"@bazel_tools//src/conditions:darwin_arm64": "@node24_darwin_arm64//:toolchain",
"@bazel_tools//src/conditions:windows": "@node24_windows_amd64//:toolchain",
}),
)

diff_test(
name = "test_node_version_24",
file1 = "write_node_version_24",
file2 = "thing_toolchain_24",
)
9 changes: 9 additions & 0 deletions e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ node.toolchain(
],
node_version = "15.14.0",
)
node.toolchain(
name = "node24",
node_version = "24.12.0",
)

# FIXME(6.0): a repo rule with name=foo should create a repo named @foo, not @foo_toolchains
use_repo(
Expand All @@ -34,6 +38,11 @@ use_repo(
"node17_linux_amd64",
"node17_linux_arm64",
"node17_windows_amd64",
"node24_darwin_amd64",
"node24_darwin_arm64",
"node24_linux_amd64",
"node24_linux_arm64",
"node24_windows_amd64",
"nodejs_darwin_amd64",
"nodejs_darwin_arm64",
"nodejs_linux_amd64",
Expand Down
5 changes: 5 additions & 0 deletions e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ nodejs_register_toolchains(
node_version = "15.14.0",
)

nodejs_register_toolchains(
name = "node24",
node_version = "24.12.0",
)

http_archive(
name = "npm_acorn-8.5.0",
build_file_content = """load("@bazel_lib//lib:copy_directory.bzl", "copy_directory")
Expand Down
17 changes: 0 additions & 17 deletions nodejs/private/os_name.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"""Helper function for repository rules
"""

load(":node_versions.bzl", "NODE_VERSIONS")

OS_ARCH_NAMES = [
("windows", "amd64"),
("windows", "arm64"),
Expand Down Expand Up @@ -65,18 +63,3 @@ def os_name(rctx):

def is_windows_os(rctx):
return rctx.os.name.find("windows") != -1

def node_exists_for_os(node_version, os_name, node_repositories):
if not node_repositories:
node_repositories = NODE_VERSIONS

return "-".join([node_version, os_name]) in node_repositories.keys()

def assert_node_exists_for_host(rctx):
node_version = rctx.attr.node_version
node_repositories = rctx.attr.node_repositories

if not node_exists_for_os(node_version, os_name(rctx), node_repositories):
fail("No nodejs is available for {} at version {}".format(os_name(rctx), node_version) +
"\n Consider upgrading by setting node_version in a call to node_repositories in WORKSPACE." +
"\n Note that Node 16.x is the minimum published for Apple Silicon (M1 Macs), and 20.x is the minimum for Windows ARM64.")
14 changes: 5 additions & 9 deletions nodejs/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
load("//nodejs/private:node_versions.bzl", "NODE_VERSIONS")
load("//nodejs/private:nodejs_repo_host_os_alias.bzl", "nodejs_repo_host_os_alias")
load("//nodejs/private:nodejs_toolchains_repo.bzl", "PLATFORMS", "nodejs_toolchains_repo")
load("//nodejs/private:os_name.bzl", "assert_node_exists_for_host", "node_exists_for_os")

# Default base name for node toolchain repositories
# created by the module extension
Expand Down Expand Up @@ -85,19 +84,17 @@ def _download_node(repository_ctx):
if not node_repositories.items():
node_repositories = NODE_VERSIONS

# Skip the download if we know it will fail
Comment thread
jbedard marked this conversation as resolved.
if not node_exists_for_os(node_version, host_os, node_repositories):
return

node_urls = repository_ctx.attr.node_urls[:]
if not node_urls:
# Go back the default if the user explicitly specifies []
node_urls = [DEFAULT_NODE_URL]

# Download node & npm
version_host_os = "%s-%s" % (node_version, host_os)
if not version_host_os in node_repositories:
fail("Unknown Node.js version-host %s" % version_host_os)
if version_host_os not in node_repositories.keys():
fail("No nodejs is available for {} at version {}".format(host_os, node_version) +
"\n Consider upgrading by setting node_version in a call to node_repositories in WORKSPACE." +
"\n Note that Node 16.x is the minimum published for Apple Silicon (M1 Macs), and 20.x is the minimum for Windows ARM64.")

filename, strip_prefix, sha256 = node_repositories[version_host_os]

urls = [url.format(version = node_version, filename = filename) for url in node_urls]
Expand Down Expand Up @@ -311,7 +308,6 @@ def _verify_version_is_valid(version):
fail("Invalid node version: %s" % version)

def _nodejs_repositories_impl(repository_ctx):
assert_node_exists_for_host(repository_ctx)
_download_node(repository_ctx)
_prepare_node(repository_ctx)

Expand Down
Loading