Skip to content

Commit 50a3046

Browse files
devversionAndrewKushnir
authored andcommitted
build: patch rules_nodejs to ensure nodejs_binary targets can be used as tools in RBE (angular#48316)
See full explanation in: bazel-contrib/rules_nodejs#3605 PR Close angular#48316
1 parent f724010 commit 50a3046

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ http_archive(
2525

2626
http_archive(
2727
name = "build_bazel_rules_nodejs",
28+
patches = [
29+
# TODO(devversion): remove when https://github.com/bazelbuild/rules_nodejs/pull/3605 is available.
30+
"//tools:bazel-repo-patches/rules_nodejs__#3605.patch",
31+
],
2832
sha256 = "c29944ba9b0b430aadcaf3bf2570fece6fc5ebfb76df145c6cdad40d65c20811",
2933
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.7.0/rules_nodejs-5.7.0.tar.gz"],
3034
)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git internal/node/node.bzl internal/node/node.bzl
2+
index 18d7ce4..3b8ce74 100755
3+
--- internal/node/node.bzl
4+
+++ internal/node/node.bzl
5+
@@ -353,10 +353,22 @@ if (process.cwd() !== __dirname) {
6+
else:
7+
executable = ctx.outputs.launcher_sh
8+
9+
- # syntax sugar: allows you to avoid repeating the entry point in data
10+
- # entry point is only needed in runfiles if it is a javascript file
11+
- if len(ctx.files.entry_point) == 1 and is_javascript_file(ctx.files.entry_point[0]):
12+
- runfiles.extend(ctx.files.entry_point)
13+
+ # Note: `to_list()` is expensive and should only be called once.
14+
+ sources_list = sources.to_list()
15+
+ entry_point_input_short_path = _ts_to_js(_get_entry_point_file(ctx).short_path)
16+
+ entry_point_script = None
17+
+
18+
+ for f in sources_list:
19+
+ if f.short_path == entry_point_input_short_path:
20+
+ entry_point_script = f
21+
+ break
22+
+
23+
+ if not entry_point_script and len(ctx.files.entry_point) == 1 and is_javascript_file(ctx.files.entry_point[0]):
24+
+ entry_point_script = ctx.files.entry_point[0]
25+
+
26+
+ # Convenience: We add the entry point to the runfiles. This means that users would not
27+
+ # need to explicitly repeat the entry point in the `data` attribute.
28+
+ runfiles.append(entry_point_script)
29+
30+
return [
31+
DefaultInfo(
32+
@@ -371,14 +383,14 @@ if (process.cwd() !== __dirname) {
33+
# Calling the .to_list() method may have some perfs hits,
34+
# so we should be running this method only once per rule.
35+
# see: https://docs.bazel.build/versions/main/skylark/depsets.html#performance
36+
- node_modules.to_list() + sources.to_list(),
37+
+ node_modules.to_list() + sources_list,
38+
collect_data = True,
39+
),
40+
),
41+
# TODO(alexeagle): remove sources and node_modules from the runfiles
42+
# when downstream usage is ready to rely on linker
43+
NodeRuntimeDepsInfo(
44+
- deps = depset(ctx.files.entry_point, transitive = [node_modules, sources]),
45+
+ deps = depset([entry_point_script], transitive = [node_modules, sources]),
46+
pkgs = data,
47+
),
48+
# indicates that the this binary should be instrumented by coverage

0 commit comments

Comments
 (0)