angular/tools/bazel/esbuild.bzl
Alan Agius adda6c5c10 build: update aspect_rules_js to 3.0.2
This updates the major version of `aspect_rules_js`.
2026-03-11 13:35:26 -07:00

38 lines
1.8 KiB
Python

load("@aspect_rules_esbuild//esbuild:defs.bzl", _esbuild = "esbuild")
load("@bazel_lib//lib:write_source_files.bzl", "write_source_file")
esbuild = _esbuild
def esbuild_checked_in(name, **kwargs):
esbuild(
name = "%s_generated" % name,
# Unfortunately we need to omit source maps from the checked-in files as these
# will vary based on the platform. See more details below in the sanitization
# genrule transformation. It is acceptable not having source-maps for the checked-in
# files as those are not minified and its to debug, the checked-in file can be visited.
sourcemap = "external",
# We always disable minification for checked-in files as otherwise it will
# become difficult determining potential differences. e.g. on Windows ESBuild
# accidentally included `source-map-support` due to the missing sandbox.
minify = False,
output = "%s_generated.js" % name,
**kwargs
)
# ESBuild adds comments and function identifiers with the name of their module
# location. e.g. `"bazel-out/x64_windows-fastbuild/bin/node_modules/a"function(exports)`.
# We strip all of these paths as that would break approval of the he checked-in files within
# different platforms (e.g. RBE running with K8). Additionally these paths depend
# on the non-deterministic hoisting of the package manager across all platforms.
native.genrule(
name = "%s_sanitized" % name,
srcs = ["%s_generated.js" % name],
outs = ["%s_sanitized.js" % name],
cmd = """cat $< | sed -E "s#(bazel-out|node_modules)/[^\\"']+##g" > $@""",
)
write_source_file(
name = name,
out_file = "%s.js" % name,
in_file = "%s_sanitized.js" % name,
)