Skip to content

Commit 8588b17

Browse files
devversionjbedard
authored andcommitted
feat: add experimental js_binary(patch_node_esm_loader)
1 parent 1295398 commit 8588b17

33 files changed

+710
-207
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ js/private/coverage/coverage.js linguist-generated=true
66
js/private/devserver/js_run_devserver.mjs linguist-generated=true
77
js/private/watch/aspect_watch_protocol.mjs linguist-generated=true
88
js/private/watch/aspect_watch_protocol.d.mts linguist-generated=true
9-
js/private/node-patches/fs.cjs linguist-generated=true
9+
js/private/node-patches/fs*.cjs linguist-generated=true
1010
js/private/js_image_layer.mjs linguist-generated=true

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ examples/**/*-docs.md
66
js/private/coverage/coverage.js
77
js/private/devserver/js_run_devserver.mjs
88
js/private/node-patches/fs.cjs
9+
js/private/node-patches/fs_stat.cjs
910
js/private/watch/aspect_watch_protocol.mjs
1011
js/private/watch/aspect_watch_protocol.d.mts
1112
min/

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bazel_dep(name = "bazel_features", version = "1.9.0")
1414
bazel_dep(name = "bazel_lib", version = "3.0.0")
1515
bazel_dep(name = "bazel_skylib", version = "1.5.0")
1616
bazel_dep(name = "platforms", version = "0.0.5")
17-
bazel_dep(name = "rules_nodejs", version = "6.3.0")
17+
bazel_dep(name = "rules_nodejs", version = "6.4.0")
1818

1919
tel = use_extension("@aspect_tools_telemetry//:extension.bzl", "telemetry")
2020
use_repo(tel, "aspect_tools_telemetry_report")

js/private/js_binary.bzl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ _ATTRS = {
205205
which can lead to non-hermetic behavior.""",
206206
default = True,
207207
),
208+
"patch_node_esm_loader": attr.bool(
209+
doc = """Apply the internal lstat patch to prevent the program from following symlinks out of
210+
the execroot, runfiles and the sandbox even when using the ESM loader.
211+
212+
This flag only has an effect when `patch_node_fs` is True.""",
213+
default = False,
214+
),
208215
"include_sources": attr.bool(
209216
doc = """When True, `sources` from `JsInfo` providers in `data` targets are included in the runfiles of the target.""",
210217
default = True,
@@ -320,7 +327,10 @@ _ATTRS = {
320327
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
321328
"_node_patches_files": attr.label_list(
322329
allow_files = True,
323-
default = [Label("@aspect_rules_js//js/private/node-patches:fs.cjs")],
330+
default = [
331+
Label("@aspect_rules_js//js/private/node-patches:fs.cjs"),
332+
Label("@aspect_rules_js//js/private/node-patches:fs_stat.cjs"),
333+
],
324334
),
325335
"_node_patches": attr.label(
326336
allow_single_file = True,
@@ -566,11 +576,18 @@ def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [],
566576
)
567577

568578
def _js_binary_impl(ctx):
579+
# Only apply lstat patch if it's requested
580+
JS_BINARY__PATCH_NODE_ESM_LOADER = "1" if ctx.attr.patch_node_esm_loader else "0"
581+
fixed_env = {
582+
"JS_BINARY__PATCH_NODE_ESM_LOADER": JS_BINARY__PATCH_NODE_ESM_LOADER,
583+
}
584+
569585
launcher = _create_launcher(
570586
ctx,
571587
log_prefix_rule_set = "aspect_rules_js",
572588
log_prefix_rule = "js_test" if ctx.attr.testonly else "js_binary",
573589
fixed_args = ctx.attr.fixed_args,
590+
fixed_env = fixed_env,
574591
)
575592
runfiles = launcher.runfiles
576593

js/private/node-patches/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ write_source_files(
44
name = "checked_in_compile",
55
files = {
66
"fs.cjs": "//js/private/node-patches/src:fs-generated.cjs",
7+
"fs_stat.cjs": "//js/private/node-patches/src:fs_stat.cjs",
78
},
89
)
910

1011
exports_files([
1112
"fs.cjs",
13+
"fs_stat.cjs",
1214
"register.cjs",
1315
])

js/private/node-patches/fs.cjs

Lines changed: 82 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)