Skip to content

Commit f1d6fda

Browse files
committed
refactor: remove rules_nodejs dependency on bazel_skylib
1 parent 079f852 commit f1d6fda

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

nodejs/repositories.bzl

+13-16
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ load("//nodejs/private:os_name.bzl", "assert_node_exists_for_host", "node_exists
44
load("//nodejs/private:node_versions.bzl", "NODE_VERSIONS")
55
load("//nodejs/private:nodejs_repo_host_os_alias.bzl", "nodejs_repo_host_os_alias")
66
load("//nodejs/private:toolchains_repo.bzl", "PLATFORMS", "toolchains_repo")
7-
load("@bazel_skylib//lib:paths.bzl", "paths")
8-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
9-
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
107

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

239-
node_bin_relative = paths.relativize(node_bin, "bin")
240-
npm_script_relative = paths.relativize(npm_script, "bin")
236+
node_bin_relative = _strip_bin(node_bin)
237+
npm_script_relative = _strip_bin(npm_script)
238+
node_entry_relative = _strip_bin(node_entry)
241239

242240
# The entry points for node for osx/linux and windows
243241
if not is_windows:
@@ -279,7 +277,7 @@ set -e
279277
"$SCRIPT_DIR/{node}" "$SCRIPT_DIR/{script}" --scripts-prepend-node-path=false "$@"
280278
""".format(
281279
get_script_dir = GET_SCRIPT_DIR,
282-
node = paths.relativize(node_entry, "bin"),
280+
node = node_entry_relative,
283281
script = npm_script_relative,
284282
),
285283
executable = True,
@@ -292,7 +290,7 @@ set -e
292290
SET SCRIPT_DIR=%~dp0
293291
"%SCRIPT_DIR%\\{node}" "%SCRIPT_DIR%\\{script}" --scripts-prepend-node-path=false %*
294292
""".format(
295-
node = paths.relativize(node_entry, "bin"),
293+
node = node_entry_relative,
296294
script = npm_script_relative,
297295
),
298296
executable = True,
@@ -361,6 +359,12 @@ node_toolchain(
361359
"""
362360
repository_ctx.file("BUILD.bazel", content = build_content)
363361

362+
def _strip_bin(path):
363+
if not path.startswith("bin/"):
364+
fail("Expected path to start with 'bin/' but was %s" % path)
365+
366+
return path[len("bin/"):]
367+
364368
def _verify_version_is_valid(version):
365369
major, minor, patch = (version.split(".") + [None, None, None])[:3]
366370
if not major.isdigit() or not minor.isdigit() or not patch.isdigit():
@@ -424,12 +428,5 @@ def nodejs_register_toolchains(name, register = True, **kwargs):
424428
)
425429

426430
def rules_nodejs_dependencies():
427-
maybe(
428-
http_archive,
429-
name = "bazel_skylib",
430-
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
431-
urls = [
432-
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
433-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
434-
],
435-
)
431+
# This is a no-op, but we keep it around for backwards compatibility.
432+
return True

repositories.bzl

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2121
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
2222

2323
def build_bazel_rules_nodejs_dependencies():
24+
core_sha = "764a3b3757bb8c3c6a02ba3344731a3d71e558220adcb0cf7e43c9bba2c37ba8"
25+
maybe(
26+
http_archive,
27+
name = "rules_nodejs",
28+
sha256 = core_sha,
29+
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-core-5.8.2.tar.gz"],
30+
)
31+
2432
maybe(
2533
http_archive,
2634
name = "bazel_skylib",
@@ -30,13 +38,6 @@ def build_bazel_rules_nodejs_dependencies():
3038
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
3139
],
3240
)
33-
core_sha = "764a3b3757bb8c3c6a02ba3344731a3d71e558220adcb0cf7e43c9bba2c37ba8"
34-
maybe(
35-
http_archive,
36-
name = "rules_nodejs",
37-
sha256 = core_sha,
38-
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-core-5.8.2.tar.gz"],
39-
)
4041

4142
def build_bazel_rules_nodejs_dev_dependencies():
4243
"""

0 commit comments

Comments
 (0)