Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove rules_nodejs dependency on bazel_skylib #3659

Merged
merged 1 commit into from
Apr 12, 2023
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
29 changes: 13 additions & 16 deletions nodejs/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ load("//nodejs/private:os_name.bzl", "assert_node_exists_for_host", "node_exists
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:toolchains_repo.bzl", "PLATFORMS", "toolchains_repo")
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

# Default base name for node toolchain repositories
# created by the module extension
Expand Down Expand Up @@ -236,8 +233,9 @@ def _prepare_node(repository_ctx):
node_entry = "bin/node%s" % entry_ext
npm_entry = "bin/npm%s" % entry_ext

node_bin_relative = paths.relativize(node_bin, "bin")
npm_script_relative = paths.relativize(npm_script, "bin")
node_bin_relative = _strip_bin(node_bin)
npm_script_relative = _strip_bin(npm_script)
node_entry_relative = _strip_bin(node_entry)

# The entry points for node for osx/linux and windows
if not is_windows:
Expand Down Expand Up @@ -279,7 +277,7 @@ set -e
"$SCRIPT_DIR/{node}" "$SCRIPT_DIR/{script}" --scripts-prepend-node-path=false "$@"
""".format(
get_script_dir = GET_SCRIPT_DIR,
node = paths.relativize(node_entry, "bin"),
node = node_entry_relative,
script = npm_script_relative,
),
executable = True,
Expand All @@ -292,7 +290,7 @@ set -e
SET SCRIPT_DIR=%~dp0
"%SCRIPT_DIR%\\{node}" "%SCRIPT_DIR%\\{script}" --scripts-prepend-node-path=false %*
""".format(
node = paths.relativize(node_entry, "bin"),
node = node_entry_relative,
script = npm_script_relative,
),
executable = True,
Expand Down Expand Up @@ -361,6 +359,12 @@ node_toolchain(
"""
repository_ctx.file("BUILD.bazel", content = build_content)

def _strip_bin(path):
if not path.startswith("bin/"):
fail("Expected path to start with 'bin/' but was %s" % path)

return path[len("bin/"):]

def _verify_version_is_valid(version):
major, minor, patch = (version.split(".") + [None, None, None])[:3]
if not major.isdigit() or not minor.isdigit() or not patch.isdigit():
Expand Down Expand Up @@ -424,12 +428,5 @@ def nodejs_register_toolchains(name, register = True, **kwargs):
)

def rules_nodejs_dependencies():
maybe(
http_archive,
name = "bazel_skylib",
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
],
)
# This is a no-op, but we keep it around for backwards compatibility.
return True
15 changes: 8 additions & 7 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def build_bazel_rules_nodejs_dependencies():
core_sha = "764a3b3757bb8c3c6a02ba3344731a3d71e558220adcb0cf7e43c9bba2c37ba8"
maybe(
http_archive,
name = "rules_nodejs",
sha256 = core_sha,
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-core-5.8.2.tar.gz"],
)

maybe(
http_archive,
name = "bazel_skylib",
Expand All @@ -30,13 +38,6 @@ def build_bazel_rules_nodejs_dependencies():
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
],
)
core_sha = "764a3b3757bb8c3c6a02ba3344731a3d71e558220adcb0cf7e43c9bba2c37ba8"
maybe(
http_archive,
name = "rules_nodejs",
sha256 = core_sha,
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-core-5.8.2.tar.gz"],
)

def build_bazel_rules_nodejs_dev_dependencies():
"""
Expand Down