angular/packages/bazel/BUILD.bazel
Paul Gschwendtner 044dac98c9 feat(bazel): support bundling .d.ts with code splitting (#60321) (#60332)
Instead of relying on Microsoft's API extractor for `d.ts` bundling,
we are switching to Rollup-based `.d.ts` bundling.

This allows us to support code spliting, even for `.d.ts` files,
allowing for relative imports to be used between entry-points, without
ending up duplicating `.d.ts` definitions in two files. This would otherwise cause
problems with assignability of types.

It also nicely integrates into our existing rollup configuration, and
overall simplifies the `ng_package` rule even further!

Notably `tsup` also uses this rollup plugin, and it seems to work well.
Keep in mind that Microsoft's API extractor is pretty hard to integrate,
caused many problems in the past, and isn't capable of code splitting.
This aligns our d.ts bundling with the .mjs bundling (great alignment).

PR Close #60321

PR Close #60332
2025-03-11 15:33:05 -07:00

38 lines
1.6 KiB
Text

# BEGIN-DEV-ONLY
load("//tools:defaults.bzl", "pkg_npm")
pkg_npm(
name = "npm_package",
package_name = "@angular/bazel",
srcs = glob(
["*"],
exclude = ["yarn.lock"],
) + [
"//packages/bazel/src:package_assets",
"//packages/bazel/src/ng_module:package_assets",
"//packages/bazel/src/ng_package:package_assets",
"//packages/bazel/src/ngc-wrapped:package_assets",
"//packages/bazel/third_party/github.com/bazelbuild/bazel/src/main/protobuf:package_assets",
],
substitutions = {
"(#|//)\\s+BEGIN-DEV-ONLY[\\w\\W]+?(#|//)\\s+END-DEV-ONLY": "",
# The partial compilation transition is applied in the user workspace. We do not want to require
# users having to define the build setting, so we directly point the flag label to the place where
# we expect `@angular/bazel` being located. Note: This expects the `@npm//` workspace to be used.
"//packages/bazel/src:partial_compilation": "@npm//@angular/bazel/src:partial_compilation",
# Substitutions to account for label changes when `@angular/bazel` is consumed externally.
# NodeJS binaries are pre-built and should be consumed through the NPM bin scripts of the package.
"//packages/bazel/": "//@angular/bazel/",
"@npm//@bazel/concatjs/internal:": "//@bazel/concatjs/internal:",
},
# Do not add more to this list.
# Dependencies on the full npm_package cause long re-builds.
visibility = [
"//integration:__subpackages__",
],
deps = [
"//packages/bazel/src/ng_package:lib",
"//packages/bazel/src/ngc-wrapped:ngc_lib",
],
)
# END-DEV-ONLY