build: override schematics to be built and tested using CommonJS (#48538)

The Angular CLI does not yet support schematics running as ESM. For
this reason we switch the schematics BUILD targets to explicitly
use ESM (as an exception in the repo).

PR Close #48538
This commit is contained in:
Paul Gschwendtner
2022-12-12 19:49:40 +00:00
parent 3922443827
commit 3a6a568113
8 changed files with 24 additions and 7 deletions
@@ -3,6 +3,8 @@ load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "google3",
srcs = glob(["**/*.ts"]),
# TODO(ESM): Change when schematics support ESM.
devmode_module = "commonjs",
tsconfig = "//packages/core/schematics:tsconfig.json",
visibility = ["//packages/core/schematics/test/google3:__pkg__"],
deps = [
@@ -3,6 +3,8 @@ load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "relative-link-resolution",
srcs = glob(["**/*.ts"]),
# TODO(ESM): Change when schematics support ESM.
devmode_module = "commonjs",
tsconfig = "//packages/core/schematics:tsconfig.json",
visibility = [
"//packages/core/schematics:__pkg__",
@@ -3,6 +3,8 @@ load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "router-link-with-href",
srcs = glob(["**/*.ts"]),
# TODO(ESM): Change when schematics support ESM.
devmode_module = "commonjs",
tsconfig = "//packages/core/schematics:tsconfig.json",
visibility = [
"//packages/core/schematics:__pkg__",
+6 -1
View File
@@ -1,4 +1,6 @@
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
# TODO(ESM): Use rule from defaults if schematics run as ESM.
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "test_lib",
@@ -7,6 +9,8 @@ ts_library(
data = [
"//packages/core/schematics:migrations.json",
],
# TODO(ESM): Change when schematics support ESM.
devmode_module = "commonjs",
deps = [
"//packages/core/schematics/migrations/relative-link-resolution",
"//packages/core/schematics/migrations/router-link-with-href",
@@ -20,6 +24,7 @@ ts_library(
jasmine_node_test(
name = "test",
templated_args = ["--nobazel_run_linker"],
deps = [
":test_lib",
"@npm//shelljs",
@@ -1,9 +1,13 @@
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
# TODO(ESM): Use rule from defaults if schematics run as ESM.
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "test_lib",
testonly = True,
srcs = glob(["**/*.ts"]),
# TODO(ESM): Change when schematics support ESM.
devmode_module = "commonjs",
deps = [
"//packages/core/schematics/migrations/google3",
"@npm//@types/shelljs",
@@ -13,6 +17,7 @@ ts_library(
jasmine_node_test(
name = "google3",
templated_args = ["--nobazel_run_linker"],
deps = [
":test_lib",
"@npm//shelljs",
@@ -3,6 +3,8 @@ load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "utils",
srcs = glob(["**/*.ts"]),
# TODO(ESM): Change when schematics support ESM.
devmode_module = "commonjs",
tsconfig = "//packages/core/schematics:tsconfig.json",
visibility = ["//packages/core/schematics:__subpackages__"],
deps = [
@@ -3,6 +3,8 @@ load("//tools:defaults.bzl", "ts_library")
ts_library(
name = "tslint",
srcs = glob(["**/*.ts"]),
# TODO(ESM): Change when schematics support ESM.
devmode_module = "commonjs",
tsconfig = "//packages/core/schematics:tsconfig.json",
visibility = [
"//packages/core/schematics/migrations/google3:__pkg__",
+2 -5
View File
@@ -112,8 +112,6 @@ def ts_library(
deps = [],
module_name = None,
package_name = None,
# TODO(devversion): disallow configuration of the target when binaries/schematics can be ESM.
devmode_target = None,
devmode_module = None,
**kwargs):
"""Default values for ts_library"""
@@ -143,9 +141,8 @@ def ts_library(
tsconfig = tsconfig,
testonly = testonly,
deps = deps,
# We also set devmode output to the same settings as prodmode as a first step in
# combining devmode and prodmode output.
devmode_target = devmode_target if devmode_target != None else default_target,
# TODO(ESM): Remove when schematics work with ESM.
devmode_target = default_target,
devmode_module = devmode_module if devmode_module != None else default_module,
# For prodmode, the target is set to `ES2020`. `@bazel/typecript` sets `ES2015` by
# default. Note that this should be in sync with the `ng_module` tsconfig generation.