Skip to content

Commit 9ea18f2

Browse files
committed
Adopt new NodeJS runtime toolchain
js_binary should use the new runtime toolchain to avoid execution toolchain being leaked into target environments (eg., js_image_oci) See bazel-contrib/rules_nodejs#3854
1 parent b589f68 commit 9ea18f2

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

e2e/pnpm_workspace/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ sh_test(
1919
"@nodejs_linux_amd64//:node_files",
2020
"@nodejs_linux_arm64//:node_files",
2121
],
22-
toolchains = ["@nodejs_toolchains//:resolved_toolchain"],
22+
toolchains = ["@rules_nodejs//nodejs:current_node_runtime"],
2323
)
2424

2525
build_test(

e2e/pnpm_workspace_rerooted/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ sh_test(
1919
"@nodejs_linux_amd64//:node_files",
2020
"@nodejs_linux_arm64//:node_files",
2121
],
22-
toolchains = ["@nodejs_toolchains//:resolved_toolchain"],
22+
toolchains = ["@rules_nodejs//nodejs:current_node_runtime"],
2323
)
2424

2525
build_test(

examples/genrule/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ genrule(
4343
# $@ is bazel shorthand for the path of the output file
4444
">$@",
4545
]),
46-
toolchains = ["@nodejs_toolchains//:resolved_toolchain"],
47-
tools = ["@nodejs_toolchains//:resolved_toolchain"],
46+
toolchains = ["@rules_nodejs//nodejs:current_node_toolchain"],
47+
tools = ["@rules_nodejs//nodejs:current_node_toolchain"],
4848
)
4949

5050
diff_test(
@@ -74,8 +74,8 @@ genrule(
7474
$(NODE_PATH) \\
7575
./$(execpath :require_acorn_js) \\
7676
$@""",
77-
toolchains = ["@nodejs_toolchains//:resolved_toolchain"],
78-
tools = ["@nodejs_toolchains//:resolved_toolchain"],
77+
toolchains = ["@rules_nodejs//nodejs:current_node_toolchain"],
78+
tools = ["@rules_nodejs//nodejs:current_node_toolchain"],
7979
)
8080

8181
diff_test(

js/private/js_binary.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ _ATTRS = {
288288
""",
289289
),
290290
"node_toolchain": attr.label(
291-
doc = """The Node.js toolchain to use for this target.
291+
doc = """The Node.js runtime toolchain to use for this target.
292292
293293
See https://bazel-contrib.github.io/rules_nodejs/Toolchains.html
294294
@@ -490,7 +490,7 @@ def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [],
490490
if ctx.attr.node_toolchain:
491491
nodeinfo = ctx.attr.node_toolchain[platform_common.ToolchainInfo].nodeinfo
492492
else:
493-
nodeinfo = ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo
493+
nodeinfo = ctx.toolchains["@rules_nodejs//nodejs:runtime_toolchain_type"].nodeinfo
494494

495495
directory_path_provider = DirectoryPathInfo if DirectoryPathInfo in ctx.attr.entry_point else _LegacyDirectoryPathInfo
496496
if directory_path_provider in ctx.attr.entry_point:
@@ -618,7 +618,7 @@ js_binary_lib = struct(
618618
toolchains = [
619619
# TODO: on Windows this toolchain is never referenced
620620
"@bazel_tools//tools/sh:toolchain_type",
621-
"@rules_nodejs//nodejs:toolchain_type",
621+
"@rules_nodejs//nodejs:runtime_toolchain_type",
622622
] + COPY_FILE_TO_BIN_TOOLCHAINS,
623623
)
624624

js/private/js_image_layer.bzl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ else {
408408
transitive = [files],
409409
)
410410

411-
nodeinfo = ctx.attr._current_node[platform_common.ToolchainInfo].nodeinfo
411+
nodeinfo = ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo
412412
node_exec = nodeinfo.node
413413
ctx.actions.run(
414414
inputs = inputs,
@@ -418,6 +418,7 @@ else {
418418
executable = node_exec,
419419
progress_message = "Computing Layer Groups %{label}",
420420
mnemonic = "JsImageLayerGroups",
421+
toolchain = "@rules_nodejs//nodejs:toolchain_type",
421422
)
422423

423424
return expected_layer_groups
@@ -623,10 +624,6 @@ js_image_layer_lib = struct(
623624
default = "//js/private:js_image_layer.mjs",
624625
allow_single_file = True,
625626
),
626-
"_current_node": attr.label(
627-
default = "@nodejs_toolchains//:resolved_toolchain",
628-
cfg = "exec",
629-
),
630627
"binary": attr.label(
631628
mandatory = True,
632629
cfg = _js_image_layer_transition,

npm/private/test/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ sh_test(
8585
"@nodejs_linux_amd64//:node_files",
8686
"@nodejs_linux_arm64//:node_files",
8787
],
88-
toolchains = ["@nodejs_toolchains//:resolved_toolchain"],
88+
toolchains = ["@rules_nodejs//nodejs:current_node_runtime"],
8989
)

0 commit comments

Comments
 (0)