Skip to content

Commit fa9c1e0

Browse files
committed
fix: set copy_data_to_bin default to True to mitigate ESM loader issue #362
1 parent 20858e0 commit fa9c1e0

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Known issues:
1515
- Doesn't support Remote Execution (RBE) due to https://github.com/bazelbuild/bazel/issues/10298.
1616
- Doesn't work with rules_docker due to https://github.com/bazelbuild/rules_pkg/issues/115#issuecomment-1137465914.
1717
- No examples yet for publishing npm packages.
18+
- ESM imports escape the runfiles tree and the sandbox due to https://github.com/aspect-build/rules_js/issues/362
1819

1920
rules_js is just a part of what Aspect provides:
2021

examples/macro/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ npm_link_all_packages(name = "node_modules")
1010
mocha_test(
1111
name = "test",
1212
srcs = ["test.js"],
13-
# Work-around for mocha leaving the runfiles & sandbox
14-
copy_data_to_bin = True,
1513
)
1614

1715
bzl_library(

js/private/js_binary.bzl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ _ATTRS = {
159159
"preserve_symlinks_main": attr.bool(
160160
doc = """When True, the --preserve-symlinks-main flag is passed to node.
161161
162-
This prevents node from following entry script out of runfiles and the sandbox which can happen for some entry
163-
files such as `.mjs` where the fs node patches, which guard the runfiles and sandbox, are not used.
162+
This prevents node from following entry script out of runfiles and the sandbox which can happen for `.mjs` ESM
163+
entry points where the fs node patches, which guard the runfiles and sandbox, are not applied.
164+
See https://github.com/aspect-build/rules_js/issues/362 for more information. Once #362 is resolved,
165+
the default for this attribute can be set to False.
164166
165167
This flag was added in Node.js v10.2.0 (released 2018-05-23). If your node toolchain is configured to use a
166168
Node.js version older than this you'll need to set this attribute to False.
@@ -173,14 +175,16 @@ _ATTRS = {
173175
doc = """When True, data files and the entry_point file are copied to the Bazel output tree before being passed
174176
as inputs to runfiles.
175177
176-
This default to False. It should only be needed if the program manages to skirt the node fs patches and leave
177-
its runfiles and/or sandbox. In that case, setting this to True will prevent the program from following symlinks
178-
into the source tree and it will end up in the output tree instead where node_modules and other inputs the
179-
program may need will be.
178+
Ideally, the default for this would be False as it is optimal, but there is a yet unresloved issue of ESM imports
179+
skirting the node fs patches and escaping the sandbox: https://github.com/aspect-build/rules_js/issues/362.
180+
This is hit in some test popular runners such as mocha, which use native `import()` statements
181+
(https://github.com/aspect-build/rules_js/pull/353).
180182
181-
Mocha, for example, has been observed to escape its runfiles & sandbox: https://github.com/aspect-build/rules_js/pull/353.
183+
A default of True will prevent program such as mocha from following symlinks into the source tree. They will
184+
escape the sandbox but they will end up in the output tree where node_modules and other inputs required will be
185+
available. With this in mind, the default will remain true until issue #362 is resolved.
182186
""",
183-
default = False,
187+
default = True,
184188
),
185189
"_launcher_template": attr.label(
186190
default = Label("//js/private:js_binary.sh.tpl"),

0 commit comments

Comments
 (0)