Skip to content

Commit 0d778af

Browse files
committed
wip
1 parent 063d7e8 commit 0d778af

20 files changed

Lines changed: 196 additions & 177 deletions

docs/js_run_binary.md

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

js/private/js_binary.bzl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ def _bash_launcher(ctx, nodeinfo, entry_point_path, log_prefix_rule_set, log_pre
401401
if ctx.attr.patch_node_fs:
402402
# Set patch node fs API env if not already set to allow js_run_binary to override
403403
envs.append(_ENV_SET_IFF_NOT_SET.format(var = "JS_BINARY__PATCH_NODE_FS", value = "1"))
404+
if ctx.attr.patch_node_esm_loader:
405+
envs.append(_ENV_SET_IFF_NOT_SET.format(var = "JS_BINARY__PATCH_NODE_ESM_LOADER", value = "1"))
404406

405407
if ctx.attr.expected_exit_code:
406408
envs.append(_ENV_SET.format(
@@ -576,18 +578,11 @@ def _create_launcher(ctx, log_prefix_rule_set, log_prefix_rule, fixed_args = [],
576578
)
577579

578580
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-
585581
launcher = _create_launcher(
586582
ctx,
587583
log_prefix_rule_set = "aspect_rules_js",
588584
log_prefix_rule = "js_test" if ctx.attr.testonly else "js_binary",
589585
fixed_args = ctx.attr.fixed_args,
590-
fixed_env = fixed_env,
591586
)
592587
runfiles = launcher.runfiles
593588

js/private/js_run_binary.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def js_run_binary(
4343
execution_requirements = None,
4444
stamp = 0,
4545
patch_node_fs = True,
46+
patch_node_esm_loader = False,
4647
allow_execroot_entry_point_with_no_copy_data_to_bin = False,
4748
use_default_shell_env = None,
4849
**kwargs):
@@ -224,6 +225,8 @@ def js_run_binary(
224225
When disabled, node programs can leave the execroot, runfiles and sandbox by following symlinks
225226
which can lead to non-hermetic behavior.
226227
228+
patch_node_esm_loader: additionally patch the Node.js ESM loader
229+
227230
allow_execroot_entry_point_with_no_copy_data_to_bin: Turn off validation that the `js_binary` tool
228231
has `copy_data_to_bin` set to True when `use_execroot_entry_point` is set to True.
229232
@@ -337,6 +340,11 @@ WARNING: js_library 'include_declarations' is deprecated. Use 'include_types' in
337340
# Disable node patches if requested
338341
if patch_node_fs:
339342
fixed_env["JS_BINARY__PATCH_NODE_FS"] = "1"
343+
344+
if patch_node_esm_loader:
345+
fixed_env["JS_BINARY__PATCH_NODE_ESM_LOADER"] = "1"
346+
else:
347+
fixed_env["JS_BINARY__PATCH_NODE_ESM_LOADER"] = "0"
340348
else:
341349
# Set explicitly to "0" so disable overrides any enable in the js_binary
342350
fixed_env["JS_BINARY__PATCH_NODE_FS"] = "0"

js/private/node-patches/fs.cjs

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

0 commit comments

Comments
 (0)