diff --git a/e2e/smoke/BUILD.bazel b/e2e/smoke/BUILD.bazel index f19879be13..27fc5f531b 100644 --- a/e2e/smoke/BUILD.bazel +++ b/e2e/smoke/BUILD.bazel @@ -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", @@ -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", +) diff --git a/e2e/smoke/MODULE.bazel b/e2e/smoke/MODULE.bazel index 7221a4468e..fb3e130ec2 100644 --- a/e2e/smoke/MODULE.bazel +++ b/e2e/smoke/MODULE.bazel @@ -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( @@ -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", diff --git a/e2e/smoke/WORKSPACE.bazel b/e2e/smoke/WORKSPACE.bazel index d3db703c62..982df0ba94 100644 --- a/e2e/smoke/WORKSPACE.bazel +++ b/e2e/smoke/WORKSPACE.bazel @@ -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") diff --git a/nodejs/private/os_name.bzl b/nodejs/private/os_name.bzl index 7d901fd949..8a2fd9a18b 100644 --- a/nodejs/private/os_name.bzl +++ b/nodejs/private/os_name.bzl @@ -15,8 +15,6 @@ """Helper function for repository rules """ -load(":node_versions.bzl", "NODE_VERSIONS") - OS_ARCH_NAMES = [ ("windows", "amd64"), ("windows", "arm64"), @@ -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.") diff --git a/nodejs/repositories.bzl b/nodejs/repositories.bzl index ac927a6a78..2b890aaba7 100644 --- a/nodejs/repositories.bzl +++ b/nodejs/repositories.bzl @@ -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 @@ -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 - 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] @@ -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)