From c0d20e05c3470ff69576227d03cb913b1ab1337f Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Wed, 29 Jan 2025 15:43:17 +0000 Subject: [PATCH] build: switch beasties bundling to `rules_js` 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: https://github.com/aspect-build/rules_js/issues/1827. This means we can't rely on the jailed resolution, but in practice it shouldn't cause an issue at this point. --- .../ssr/third_party/beasties/BUILD.bazel | 59 +++++++------------ .../third_party/beasties/rollup.config.mjs | 1 - 2 files changed, 20 insertions(+), 40 deletions(-) diff --git a/packages/angular/ssr/third_party/beasties/BUILD.bazel b/packages/angular/ssr/third_party/beasties/BUILD.bazel index b9623ec316ac..e54d156866e9 100644 --- a/packages/angular/ssr/third_party/beasties/BUILD.bazel +++ b/packages/angular/ssr/third_party/beasties/BUILD.bazel @@ -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"]) @@ -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, ) diff --git a/packages/angular/ssr/third_party/beasties/rollup.config.mjs b/packages/angular/ssr/third_party/beasties/rollup.config.mjs index e2283403bc1c..c872fd914aba 100644 --- a/packages/angular/ssr/third_party/beasties/rollup.config.mjs +++ b/packages/angular/ssr/third_party/beasties/rollup.config.mjs @@ -28,7 +28,6 @@ export default { nodeResolve({ preferBuiltins: false, browser: true, - jail: process.cwd(), }), commonjs(), alias({