build: only ship type definitions along with bundles for compiler-cli (#43431)

We switched the build output for the compiler-cli to use esbuild-generated
bundles.

This means that actual devmode ES5 sources, or prodmode ES2020 non-bundled
sources are not actually needed. Only the types are needed, and this commit
makes sure only the type definitions are shipped. This reduces the code size
of the compiler-cli and also helps with avoiding incorrect module resolution.

PR Close #43431
This commit is contained in:
Paul Gschwendtner
2021-09-23 11:59:25 +02:00
committed by Dylan Hunn
parent e60058c88a
commit 7e0bab3856
2 changed files with 35 additions and 5 deletions
+10 -5
View File
@@ -1,5 +1,6 @@
load("//tools:defaults.bzl", "api_golden_test", "pkg_npm", "ts_config", "ts_library")
load("@npm//@bazel/esbuild:index.bzl", "esbuild", "esbuild_config")
load(":extract_typings_rule.bzl", "extract_typings")
# Load ng_perf_flag explicitly from ng_perf.bzl as it's private API, and not exposed to other
# consumers of @angular/bazel.
@@ -105,6 +106,11 @@ ts_library(
],
)
extract_typings(
name = "api_type_definitions",
deps = PUBLIC_TARGETS,
)
pkg_npm(
name = "npm_package",
srcs = [
@@ -119,11 +125,10 @@ pkg_npm(
"//integration:__pkg__",
"//packages/compiler-cli/integrationtest:__pkg__",
],
# Note: We add `PUBLIC_TARGETS` here to pull in the type definitions into
# the NPM package. This also brings in the devmode ES5 sources currently.
# These are not referenced anywhere but we would want to only include types.
# TODO(devversion): add support for including only type definitions here.
deps = [":bundles"] + PUBLIC_TARGETS,
deps = [
":api_type_definitions",
":bundles",
],
)
api_golden_test(
@@ -0,0 +1,25 @@
"""Starlark file that exposes a rule for extracting type definitions of dependencies."""
load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo")
def _extract_typings_rule_impl(ctx):
"""Implementation of the `extract_typings` rule."""
transitive_depsets = []
for dep in ctx.attr.deps:
# Based on whether declarations should be collected, extract direct
# and transitive declaration files using the `DeclarationInfo` provider.
if DeclarationInfo in dep:
transitive_depsets.append(dep[DeclarationInfo].transitive_declarations)
return [DefaultInfo(files = depset(transitive = transitive_depsets))]
extract_typings = rule(
implementation = _extract_typings_rule_impl,
doc = """Rule that extracts all transitive typings of dependencies""",
attrs = {
"deps": attr.label_list(
allow_files = True,
),
},
)