Skip to content

Commit

Permalink
Merge pull request #9 from Canva/christianscott-minimum_node_18
Browse files Browse the repository at this point in the history
support >=nodejs 18
  • Loading branch information
christianscott authored Nov 15, 2023
2 parents c112d47 + 5b359f2 commit 86afedd
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2,191 deletions.
14 changes: 0 additions & 14 deletions internal/common/os_name.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,3 @@ def is_darwin_os(rctx):
def is_linux_os(rctx):
name = os_name(rctx)
return name == OS_NAMES[3] or name == OS_NAMES[4] or name == OS_NAMES[5]

def node_exists_for_os(node_version, os_name):
"Whether a node binary is available for this platform"
is_16_or_greater = check_version(node_version, "16.0.0")

# There is no Apple Silicon native version of node before 16
return is_16_or_greater or os_name != "darwin_arm64"

def assert_node_exists_for_host(rctx):
node_version = rctx.attr.node_version
if not node_exists_for_os(node_version, os_name(rctx)):
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)")
13 changes: 2 additions & 11 deletions internal/node/node_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ See https://docs.bazel.build/versions/master/skylark/repository_rules.html
"""

load("//internal/common:check_bazel_version.bzl", "check_bazel_version")
load("//internal/common:os_name.bzl", "OS_ARCH_NAMES", "assert_node_exists_for_host", "node_exists_for_os", "os_name")
load("//internal/common:os_name.bzl", "OS_ARCH_NAMES", "os_name")
load("//internal/node:node_versions.bzl", "NODE_VERSIONS")
load("//third_party/github.com/bazelbuild/bazel-skylib:lib/paths.bzl", "paths")
load("//toolchains/node:node_toolchain_configure.bzl", "node_toolchain_configure")

_DEFAULT_NODE_VERSION = "12.13.0"
_DEFAULT_NODE_VERSION = "18.16.1"

# @unsorted-dict-items
_YARN_VERSIONS = {
Expand Down Expand Up @@ -289,9 +289,6 @@ def _download_node(repository_ctx):

node_version = repository_ctx.attr.node_version

# Skip the download if we know it will fail
if not node_exists_for_os(node_version, host_os):
return
node_repositories = repository_ctx.attr.node_repositories

# We insert our default value here, not on the attribute's default, so it isn't documented.
Expand Down Expand Up @@ -722,7 +719,6 @@ filegroup(
))

def _nodejs_repo_impl(repository_ctx):
assert_node_exists_for_host(repository_ctx)
_download_node(repository_ctx)
_download_yarn(repository_ctx)
_prepare_node(repository_ctx)
Expand All @@ -736,8 +732,6 @@ node_repositories_rule = repository_rule(
)

def _nodejs_host_os_alias_impl(repository_ctx):
assert_node_exists_for_host(repository_ctx)

# Base BUILD file for this repository
repository_ctx.file("BUILD.bazel", content = """# Generated by node_repositories.bzl
package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -797,9 +791,6 @@ def node_repositories(**kwargs):
for os_arch_name in OS_ARCH_NAMES:
os_name = "_".join(os_arch_name)

# If we couldn't download node, don't make an external repo for it either
if not node_exists_for_os(node_version, os_name):
continue
node_repository_name = "nodejs_%s" % os_name
_maybe(
node_repositories_rule,
Expand Down
Loading

0 comments on commit 86afedd

Please sign in to comment.