angular/packages/platform-server/BUILD.bazel
Paul Gschwendtner 1f1039475c feat(bazel): support shared chunks in ng_package (#60241)
Historically we've had to be VERY cautious about the way we import
things between entry-points. That is because the `ng_package` rule
bundling is subject to silently introducing code duplication, breaking
singletons etc. We've had this surface a couple of times already, and
dev-infra tried to help detect such cases by adding safety analysis into
`ng_package`.

Long-term we want to get to an approach where it's easy to simply share
code between chunks. Precisely, with the upcoming `rules_js` migration,
this will be necessary as we will have different import "guidelines"
that would currently, before this commit, result in code duplication, or
trigger our "safety check/lint".

This commit prepares `ng_package` to support relative imports between
entry-points, so that we only need the safety check for cross-package
imports/exports. The result is that `ng_package`/APF is now smartly able
to generate shared chunks for things that are needed between multiple
entry-points. Yay!

Note that those shared chunks still remain private, and are guarded by
our `package.json` "exports"; so no new public API surface is
exposed.

PR Close #60241
2025-03-06 10:29:05 -08:00

107 lines
2.5 KiB
Text

load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//tools:defaults.bzl", "api_golden_test_npm_package", "esbuild", "generate_api_docs", "ng_module", "ng_package", "tsec_test")
package(default_visibility = ["//visibility:public"])
ng_module(
name = "platform-server",
package_name = "@angular/platform-server",
srcs = glob(
[
"*.ts",
"src/**/*.ts",
],
exclude = ["src/bundled-domino.d.ts"],
),
deps = [
":bundled_domino_lib",
"//packages/common",
"//packages/common/http",
"//packages/compiler",
"//packages/core",
"//packages/platform-browser",
"//packages/zone.js/lib:zone_d_ts",
"@npm//@types/node",
"@npm//rxjs",
"@npm//xhr2",
],
)
esbuild(
name = "bundled_domino",
entry_point = "@npm//:node_modules/domino/lib/index.js",
format = "esm",
output = "src/bundled-domino.mjs",
deps = ["@npm//domino"],
)
js_library(
name = "bundled_domino_lib",
srcs = [
"src/bundled-domino.d.ts",
":bundled_domino",
],
)
tsec_test(
name = "tsec_test",
target = "platform-server",
tsconfig = "//packages:tsec_config",
)
ng_package(
name = "npm_package",
srcs = [
"package.json",
],
externals = [
"xhr2",
],
side_effect_entry_points = [
"@angular/platform-server/init",
],
tags = [
"release-with-framework",
],
# Do not add more to this list.
# Dependencies on the full npm_package cause long re-builds.
visibility = [
"//adev:__pkg__",
"//integration:__subpackages__",
"//modules/ssr-benchmarks:__subpackages__",
"//packages/compiler-cli/integrationtest:__pkg__",
],
deps = [
":platform-server",
"//packages/platform-server/init",
"//packages/platform-server/testing",
],
)
api_golden_test_npm_package(
name = "platform-server_api",
data = [
":npm_package",
"//goldens:public-api",
],
golden_dir = "angular/goldens/public-api/platform-server",
npm_package = "angular/packages/platform-server/npm_package",
)
filegroup(
name = "files_for_docgen",
srcs = glob([
"*.ts",
"src/**/*.ts",
]) + ["PACKAGE.md"],
)
generate_api_docs(
name = "platform-server_docs",
srcs = [
":files_for_docgen",
"//packages:common_files_and_deps_for_docs",
],
entry_point = ":index.ts",
module_name = "@angular/platform-server",
)