Skip to content

Commit

Permalink
build: switch beasties bundling to rules_js
Browse files Browse the repository at this point in the history
Switches the beasties bundling to `rules_js`, using rollup directly from
the node modules installation.

Notably we are facing a small issue that doesn't cause any issues right
now, because rollup tries to dereference symlinks by default given
a bug: aspect-build/rules_js#1827.

This means we can't rely on the jailed resolution, but in practice it
shouldn't cause an issue at this point.
  • Loading branch information
devversion authored and alan-agius4 committed Jan 30, 2025
1 parent 3194f56 commit c0d20e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
59 changes: 20 additions & 39 deletions packages/angular/ssr/third_party/beasties/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
load("@npm2//:rollup/package_json.bzl", rollup = "bin")

package(default_visibility = ["//visibility:public"])

Expand All @@ -16,52 +16,33 @@ js_library(
js_library(
name = "beasties_bundled",
srcs = [
":bundled_beasties_files",
],
deps = [
"//:node_modules/beasties",
":bundled_beasties",
],
)

# Filter out esbuild metadata files and only copy the necessary files
genrule(
name = "bundled_beasties_files",
rollup.rollup(
name = "bundled_beasties",
srcs = [
":bundled_beasties",
"rollup.config.mjs",
"//:node_modules/@rollup/plugin-alias",
"//:node_modules/@rollup/plugin-commonjs",
"//:node_modules/@rollup/plugin-node-resolve",
"//:node_modules/beasties",
"//:node_modules/rollup-license-plugin",
"//:node_modules/unenv",
],
outs = [
"THIRD_PARTY_LICENSES.txt",
"index.js",
"index.js.map",
"THIRD_PARTY_LICENSES.txt",
],
cmd = """
for f in $(locations :bundled_beasties); do
# Only process files inside the bundled_beasties directory
if [[ "$${f}" == *bundled_beasties ]]; then
cp "$${f}/index.js" $(location :index.js)
cp "$${f}/index.js.map" $(location :index.js.map)
cp "$${f}/THIRD_PARTY_LICENSES.txt" $(location :THIRD_PARTY_LICENSES.txt)
fi
done
""",
)

rollup_bundle(
name = "bundled_beasties",
config_file = ":rollup.config.mjs",
entry_points = {
"@npm//:node_modules/beasties/dist/index.mjs": "index",
},
format = "esm",
link_workspace_root = True,
output_dir = True,
sourcemap = "true",
deps = [
"@npm//@rollup/plugin-alias",
"@npm//@rollup/plugin-commonjs",
"@npm//@rollup/plugin-node-resolve",
"@npm//beasties",
"@npm//rollup-license-plugin",
"@npm//unenv",
args = [
"--format=esm",
"--config=$(rootpath rollup.config.mjs)",
"--input=node_modules/beasties/dist/index.mjs",
"--sourcemap=true",
"--dir=packages/angular/ssr/third_party/beasties",
],
progress_message = "Bundling beasties",
silent_on_success = False,
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default {
nodeResolve({
preferBuiltins: false,
browser: true,
jail: process.cwd(),
}),
commonjs(),
alias({
Expand Down

0 comments on commit c0d20e0

Please sign in to comment.