Skip to content

Commit ebb7e44

Browse files
authored
Fix running terser from external repository. (#125)
I've got a repo which terses some typescript. It works when built inside the repo, but when the exact same target is built outside the repo, it fails to build. load("@aspect_rules_terser//terser:defs.bzl", terser_minified = "terser") terser_minified( name = name + "__min", srcs = [":" + name], node_modules = "//:node_modules", sourcemap = False, ) (cd /dev/shm/bazel-sandbox.a3f391e631c5ea6c72bb0d2c0b90317c117ec497a3759d6de83cbe1ad7ada353/linux-sandbox/6993/execroot/spacecookies && \ exec env - \ BAZEL_BINDIR=bazel-out/k8-opt/bin \ COMPILATION_MODE=opt \ TMPDIR=/tmp \ /home/austin/.cache/bazel/_bazel_austin/install/5309d864f9edb3a2e8380ffc84e6b95c/linux-sandbox -t 15 -w /dev/shm -w /dev/shm/bazel-sandbox.a3f391e631c5ea6c72bb0d2c0b90317c117ec497a3759d6de83cbe1ad7ada353/linux-sandbox/6993/execroot/spacecookies -w /tmp -e /tmp -S /dev/shm/bazel-sandbox.a3f391e631c5ea6c72bb0d2c0b90317c117ec497a3759d6de83cbe1ad7ada353/linux-sandbox/6993/stats.out -H -N -U -D /dev/shm/bazel-sandbox.a3f391e631c5ea6c72bb0d2c0b90317c117ec497a3759d6de83cbe1ad7ada353/linux-sandbox/6993/debug.out -- bazel-out/k8-opt-exec-ST-31ad040affd4/bin/external/aos/aos/network/www/_reflection_test_bundle__min_terser_binary_/_reflection_test_bundle__min_terser_binary ../aos/aos/network/www/reflection_test_bundle.js --output ../aos/aos/network/www/reflection_test_bundle__min.js --config-file bazel-out/k8-opt/bin/external/aos/aos/network/www/_reflection_test_bundle__min.minify_options.json) node:internal/fs/utils:356 throw err; ^ Error: ENOENT: no such file or directory, lstat '/dev/shm/bazel-sandbox.a3f391e631c5ea6c72bb0d2c0b90317c117ec497a3759d6de83cbe1ad7ada353/linux-sandbox/6993/execroot/spacecookies/bazel-out/k8-opt/aos/aos/network/www/reflection_test_bundle.js' at Object.lstatSync (node:fs:1666:3) at Object.lstatSync (/home/austin/.cache/bazel/_bazel_austin/0654a46dce625c9bc6e0b54d6df8dcff/external/aspect_rules_js/js/private/node-patches/fs.cjs:125:23) at isDirectory (/dev/shm/bazel-sandbox.a3f391e631c5ea6c72bb0d2c0b90317c117ec497a3759d6de83cbe1ad7ada353/linux-sandbox/6993/execroot/spacecookies/bazel-out/k8-opt-exec-ST-31ad040affd4/bin/external/aos/aos/network/www/_reflection_test_bundle__min_terser_binary_/_reflection_test_bundle__min_terser_binary.runfiles/aos/aos/network/www/_reflection_test_bundle__min_terser_runner.cjs:25:13) at Array.find (<anonymous>) at main (/dev/shm/bazel-sandbox.a3f391e631c5ea6c72bb0d2c0b90317c117ec497a3759d6de83cbe1ad7ada353/linux-sandbox/6993/execroot/spacecookies/bazel-out/k8-opt-exec-ST-31ad040affd4/bin/external/aos/aos/network/www/_reflection_test_bundle__min_terser_binary_/_reflection_test_bundle__min_terser_binary.runfiles/aos/aos/network/www/_reflection_test_bundle__min_terser_runner.cjs:251:15) at Object.<anonymous> (/dev/shm/bazel-sandbox.a3f391e631c5ea6c72bb0d2c0b90317c117ec497a3759d6de83cbe1ad7ada353/linux-sandbox/6993/execroot/spacecookies/bazel-out/k8-opt-exec-ST-31ad040affd4/bin/external/aos/aos/network/www/_reflection_test_bundle__min_terser_binary_/_reflection_test_bundle__min_terser_binary.runfiles/aos/aos/network/www/_reflection_test_bundle__min_terser_runner.cjs:269:3) at Module._compile (node:internal/modules/cjs/loader:1364:14) at Module._extensions..js (node:internal/modules/cjs/loader:1422:10) at Module.load (node:internal/modules/cjs/loader:1203:32) at Module._load (node:internal/modules/cjs/loader:1019:12) { errno: -2, syscall: 'lstat', code: 'ENOENT', path: '/dev/shm/bazel-sandbox.a3f391e631c5ea6c72bb0d2c0b90317c117ec497a3759d6de83cbe1ad7ada353/linux-sandbox/6993/execroot/spacecookies/bazel-out/k8-opt/aos/aos/network/www/reflection_test_bundle.js' } Node.js v18.20.3 When built locally, instead of `../aos/aos/network/www/reflection_test_bundle.js`, it references `aos/network/www/reflection_test_bundle.js` which works. Manually adjusting it to `external/aos/aos/network/www/reflection_test_bundle.js` makes it build. Really, this is an abuse of short_path, so abuse it a bit more. <!-- Delete this comment! Include a summary of your changes, links to related issue(s), relevant motivation and context for why you made the change, how you arrived at this design, or alternatives considered. For repositories that use a squash merge strategy, the pull request description may also be used as the landed commit description ensuring that useful information ends up in the git log. --> --- ### Changes are visible to end-users: yes/no <!-- If no, please delete this section. --> - Searched for relevant documentation and updated as needed: yes/no - Breaking change (forces users to change their own code or config): yes/no - Suggested release notes appear below: yes/no ### Test plan <!-- Delete any which do not apply --> - Covered by existing test cases - New test cases added - Manual testing; please provide instructions so we can reproduce: --------- Signed-off-by: Austin Schuh <[email protected]>
1 parent 4a0dba9 commit ebb7e44

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

terser/private/terser.bzl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ _ATTRS = {
3030
def _filter_js(files):
3131
return [f for f in files if f.is_directory or f.extension == "js" or f.extension == "mjs"]
3232

33+
def maybe_prefix_external(path):
34+
if path.startswith("../"):
35+
return "external" + path[2:]
36+
return path
37+
3338
def _impl(ctx):
3439
args = ctx.actions.args()
3540

@@ -49,8 +54,8 @@ def _impl(ctx):
4954
if ctx.attr.sourcemap:
5055
output_sources.append(ctx.actions.declare_file("%s.js.map" % ctx.label.name))
5156

52-
args.add_all([s.short_path for s in input_sources])
53-
args.add_all(["--output", output_sources[0].short_path])
57+
args.add_all([maybe_prefix_external(s.short_path) for s in input_sources])
58+
args.add_all(["--output", maybe_prefix_external(output_sources[0].short_path)])
5459

5560
debug = ctx.attr.debug or ctx.var["COMPILATION_MODE"] == "dbg"
5661
if debug:
@@ -90,7 +95,7 @@ def _impl(ctx):
9095
"\"bazel_no_debug\"": str(not debug).lower(),
9196
},
9297
)
93-
args.add_all(["--config-file", options.short_path])
98+
args.add_all(["--config-file", maybe_prefix_external(options.short_path)])
9499

95100
ctx.actions.run(
96101
inputs = inputs,

0 commit comments

Comments
 (0)