Skip to content

Commit 0a40f98

Browse files
committed
fix: node v24+ directory structure
1 parent b19c329 commit 0a40f98

File tree

3 files changed

+89
-14
lines changed

3 files changed

+89
-14
lines changed

e2e/smoke/BUILD.bazel

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,25 @@ write_file(
234234
content = ["v16.5.0"],
235235
)
236236

237+
write_file(
238+
name = "write_node_version_20",
239+
out = "expected_node_20",
240+
content = ["v20.19.6"],
241+
)
242+
243+
write_file(
244+
name = "write_node_version_24",
245+
out = "expected_node_24",
246+
content = ["v24.12.0"],
247+
)
248+
237249
# To see what nodejs version is used by default
238250
my_nodejs(
239251
name = "run_no_toolchain",
240252
out = "thing_no_toolchain",
241253
entry_point = "version.js",
242254
)
243255

244-
# this tests to make sure that the first version imported in the workspace is used as default
245-
diff_test(
246-
name = "node_version_default_toolchain_test",
247-
file1 = "write_node_version_16",
248-
file2 = "thing_no_toolchain",
249-
)
250-
251256
# Output contains the version number of node that is used.
252257
# This is used in tests later to verify the toolchain specified is resolved correctly
253258
my_nodejs(
@@ -279,11 +284,11 @@ my_nodejs(
279284
# using the select statement will download toolchains for all three platforms
280285
# you can also just provide an individual toolchain if you don't want to download them all
281286
toolchain = select({
282-
"@bazel_tools//src/conditions:linux_x86_64": "@nodejs_linux_amd64//:toolchain",
283-
"@bazel_tools//src/conditions:linux_aarch64": "@nodejs_linux_arm64//:toolchain",
284-
"@bazel_tools//src/conditions:darwin_x86_64": "@nodejs_darwin_amd64//:toolchain",
285-
"@bazel_tools//src/conditions:darwin_arm64": "@nodejs_darwin_arm64//:toolchain",
286-
"@bazel_tools//src/conditions:windows": "@nodejs_windows_amd64//:toolchain",
287+
"@bazel_tools//src/conditions:linux_x86_64": "@node16_linux_amd64//:toolchain",
288+
"@bazel_tools//src/conditions:linux_aarch64": "@node16_linux_arm64//:toolchain",
289+
"@bazel_tools//src/conditions:darwin_x86_64": "@node16_darwin_amd64//:toolchain",
290+
"@bazel_tools//src/conditions:darwin_arm64": "@node16_darwin_arm64//:toolchain",
291+
"@bazel_tools//src/conditions:windows": "@node16_windows_amd64//:toolchain",
287292
}),
288293
)
289294

@@ -312,3 +317,46 @@ diff_test(
312317
file1 = "write_node_version_15",
313318
file2 = "thing_toolchain_15",
314319
)
320+
321+
my_nodejs(
322+
name = "run_default",
323+
out = "thing_toolchain_20",
324+
entry_point = "version.js",
325+
# using the select statement will download toolchains for all three platforms
326+
# you can also just provide an individual toolchain if you don't want to download them all
327+
toolchain = select({
328+
"@bazel_tools//src/conditions:linux_x86_64": "@nodejs_linux_amd64//:toolchain",
329+
"@bazel_tools//src/conditions:linux_aarch64": "@nodejs_linux_arm64//:toolchain",
330+
"@bazel_tools//src/conditions:darwin_x86_64": "@nodejs_darwin_amd64//:toolchain",
331+
"@bazel_tools//src/conditions:darwin_arm64": "@nodejs_darwin_arm64//:toolchain",
332+
"@bazel_tools//src/conditions:windows": "@nodejs_windows_amd64//:toolchain",
333+
}),
334+
)
335+
336+
# this tests to make sure that the first version imported in the workspace is used as default
337+
diff_test(
338+
name = "node_version_default_toolchain_test",
339+
file1 = "write_node_version_20",
340+
file2 = "thing_no_toolchain",
341+
)
342+
343+
my_nodejs(
344+
name = "run_24",
345+
out = "thing_toolchain_24",
346+
entry_point = "version.js",
347+
# using the select statement will download toolchains for all three platforms
348+
# you can also just provide an individual toolchain if you don't want to download them all
349+
toolchain = select({
350+
"@bazel_tools//src/conditions:linux_x86_64": "@node24_linux_amd64//:toolchain",
351+
"@bazel_tools//src/conditions:linux_aarch64": "@node24_linux_arm64//:toolchain",
352+
"@bazel_tools//src/conditions:darwin_x86_64": "@node24_darwin_amd64//:toolchain",
353+
"@bazel_tools//src/conditions:darwin_arm64": "@node24_darwin_arm64//:toolchain",
354+
"@bazel_tools//src/conditions:windows": "@node24_windows_amd64//:toolchain",
355+
}),
356+
)
357+
358+
diff_test(
359+
name = "test_node_version_24",
360+
file1 = "write_node_version_24",
361+
file2 = "thing_toolchain_24",
362+
)

e2e/smoke/MODULE.bazel

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ bazel_dep(name = "bazel_skylib", version = "1.7.1", dev_dependency = True)
99
bazel_dep(name = "platforms", version = "0.0.10", dev_dependency = True)
1010

1111
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node", dev_dependency = True)
12-
node.toolchain(node_version = "16.5.0")
12+
node.toolchain()
13+
node.toolchain(
14+
name = "node16",
15+
node_version = "16.5.0",
16+
)
1317
node.toolchain(
1418
name = "node17",
1519
node_version = "17.9.1",
@@ -23,17 +27,32 @@ node.toolchain(
2327
node_version = "15.14.0",
2428
)
2529

30+
# Node24 changed some directory structures: https://github.com/bazel-contrib/rules_nodejs/issues/3887
31+
node.toolchain(
32+
name = "node24",
33+
node_version = "24.12.0",
34+
)
35+
2636
# FIXME(6.0): a repo rule with name=foo should create a repo named @foo, not @foo_toolchains
2737
use_repo(
2838
node,
2939
"node15_darwin_amd64",
3040
"node15_linux_amd64",
3141
"node15_windows_amd64",
42+
"node16_darwin_amd64",
43+
"node16_darwin_arm64",
44+
"node16_linux_amd64",
45+
"node16_windows_amd64",
3246
"node17_darwin_amd64",
3347
"node17_darwin_arm64",
3448
"node17_linux_amd64",
3549
"node17_linux_arm64",
3650
"node17_windows_amd64",
51+
"node24_darwin_amd64",
52+
"node24_darwin_arm64",
53+
"node24_linux_amd64",
54+
"node24_linux_arm64",
55+
"node24_windows_amd64",
3756
"nodejs_darwin_amd64",
3857
"nodejs_darwin_arm64",
3958
"nodejs_linux_amd64",

e2e/smoke/WORKSPACE.bazel

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
99

1010
# The order matters because Bazel will provide the first registered toolchain when a rule asks Bazel to select it
1111
# This applies to the resolved_toolchain
12-
nodejs_register_toolchains(node_version = "16.5.0")
12+
nodejs_register_toolchains(
13+
name = "node16",
14+
node_version = "16.5.0",
15+
)
1316

1417
nodejs_register_toolchains(
1518
name = "node17",
@@ -25,6 +28,11 @@ nodejs_register_toolchains(
2528
node_version = "15.14.0",
2629
)
2730

31+
nodejs_register_toolchains(
32+
name = "node24",
33+
node_version = "24.12.0",
34+
)
35+
2836
http_archive(
2937
name = "npm_acorn-8.5.0",
3038
build_file_content = """load("@bazel_lib//lib:copy_directory.bzl", "copy_directory")

0 commit comments

Comments
 (0)