Skip to content

Commit 9e21d6b

Browse files
committed
build: remove hard-coded karma systemjs config
Removes the hard-coded Karma SystemJS config in favor of a shared SystemJS config that is used by both the dev-app and the legacy unit tests. The config is generated through Bazel and leverages the entry-point/package configuration we need to main in Bazel. That way we only have one canonical place for package/entry-point configuration (the `config.bzl` files per package).
1 parent a30094b commit 9e21d6b

13 files changed

+308
-424
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ jobs:
240240
steps:
241241
- *checkout_code
242242
- *restore_cache
243+
- *setup_bazel_ci_config
243244
- *yarn_download
244245
- *yarn_install
245246

@@ -261,6 +262,7 @@ jobs:
261262
steps:
262263
- *checkout_code
263264
- *restore_cache
265+
- *setup_bazel_ci_config
264266
- *yarn_download
265267
- *yarn_install
266268

packages.bzl

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ VERSION_PLACEHOLDER_REPLACEMENTS = {
1313

1414
# List of default Angular library UMD bundles which are not processed by ngcc.
1515
ANGULAR_NO_NGCC_BUNDLES = [
16-
"@npm//:node_modules/@angular/compiler/bundles/compiler.umd.js",
16+
("@angular/compiler", ["compiler.umd.js"]),
1717
]
1818

1919
# List of Angular library UMD bundles which will are processed by ngcc.
@@ -29,20 +29,39 @@ ANGULAR_NGCC_BUNDLES = [
2929
("@angular/router", ["router.umd.js"]),
3030
]
3131

32-
ANGULAR_LIBRARY_VIEW_ENGINE_UMDS = ANGULAR_NO_NGCC_BUNDLES + [
33-
"@npm//:node_modules/%s/bundles/%s" % (pkgName, bundleName)
34-
for pkgName, bundleNames in ANGULAR_NGCC_BUNDLES
35-
for bundleName in bundleNames
36-
]
37-
ANGULAR_LIBRARY_IVY_UMDS = ANGULAR_NO_NGCC_BUNDLES + [
38-
"@npm//:node_modules/%s/__ivy_ngcc__/bundles/%s" % (pkgName, bundleName)
39-
for pkgName, bundleNames in ANGULAR_NGCC_BUNDLES
40-
for bundleName in bundleNames
41-
]
32+
"""
33+
Gets a dictionary of all packages and their bundle names.
34+
"""
35+
36+
def getFrameworkPackageBundles():
37+
res = {}
38+
for pkgName, bundleNames in ANGULAR_NGCC_BUNDLES + ANGULAR_NO_NGCC_BUNDLES:
39+
res[pkgName] = res.get(pkgName, []) + bundleNames
40+
return res
41+
42+
"""
43+
Gets a list of labels which resolve to the UMD bundles of the given packages.
44+
"""
45+
46+
def getUmdFilePaths(packages, ngcc_artifacts):
47+
tmpl = "@npm//:node_modules/%s" + ("/__ivy_ngcc__" if ngcc_artifacts else "") + "/bundles/%s"
48+
return [
49+
tmpl % (pkgName, bundleName)
50+
for pkgName, bundleNames in packages
51+
for bundleName in bundleNames
52+
]
53+
54+
ANGULAR_PACKAGE_BUNDLES = getFrameworkPackageBundles()
55+
56+
ANGULAR_LIBRARY_VIEW_ENGINE_UMDS = getUmdFilePaths(ANGULAR_NO_NGCC_BUNDLES, False) + \
57+
getUmdFilePaths(ANGULAR_NGCC_BUNDLES, False)
58+
59+
ANGULAR_LIBRARY_IVY_UMDS = getUmdFilePaths(ANGULAR_NO_NGCC_BUNDLES, False) + \
60+
getUmdFilePaths(ANGULAR_NGCC_BUNDLES, True)
4261

4362
"""
4463
Gets the list of targets for the Angular library UMD bundles. Conditionally
45-
switches between View Engine or Ivy UMD bundles based on the
64+
switches between View Engine or Ivy UMD bundles based on the
4665
"--config={ivy,view-engine}" flag.
4766
"""
4867

src/dev-app/BUILD.bazel

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ package(default_visibility = ["//visibility:public"])
22

33
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
44
load("@build_bazel_rules_nodejs//internal/common:devmode_js_sources.bzl", "devmode_js_sources")
5-
load("//src/cdk:config.bzl", "CDK_ENTRYPOINTS")
6-
load("//src/cdk-experimental:config.bzl", "CDK_EXPERIMENTAL_ENTRYPOINTS")
7-
load("//src/material:config.bzl", "MATERIAL_ENTRYPOINTS")
8-
load("//src/material-experimental:config.bzl", "MATERIAL_EXPERIMENTAL_ENTRYPOINTS")
5+
load("//tools:create-system-config.bzl", "create_system_config")
96
load("//tools:defaults.bzl", "ng_module", "sass_binary")
10-
load("//tools/bazel:expand_template.bzl", "expand_template")
117
load("//tools/dev-server:index.bzl", "dev_server")
128

139
ng_module(
@@ -102,17 +98,9 @@ sass_binary(
10298
],
10399
)
104100

105-
expand_template(
101+
create_system_config(
106102
name = "system-config",
107-
configuration_env_vars = ["angular_ivy_enabled"],
108103
output_name = "system-config.js",
109-
substitutions = {
110-
"$CDK_ENTRYPOINTS_TMPL": str(CDK_ENTRYPOINTS),
111-
"$CDK_EXPERIMENTAL_ENTRYPOINTS_TMPL": str(CDK_EXPERIMENTAL_ENTRYPOINTS),
112-
"$MATERIAL_ENTRYPOINTS_TMPL": str(MATERIAL_ENTRYPOINTS),
113-
"$MATERIAL_EXPERIMENTAL_ENTRYPOINTS_TMPL": str(MATERIAL_EXPERIMENTAL_ENTRYPOINTS),
114-
},
115-
template = "system-config-tmpl.js",
116104
)
117105

118106
# File group for all static files which are needed to serve the dev-app. These files are
@@ -123,10 +111,10 @@ filegroup(
123111
srcs = [
124112
"favicon.ico",
125113
"index.html",
126-
"system-rxjs-operators.js",
127114
":system-config",
128115
":theme",
129116
"//src/dev-app/icon:icon_demo_assets",
117+
"//tools:system-rxjs-operators.js",
130118
"@npm//:node_modules/@material/animation/dist/mdc.animation.js",
131119
"@npm//:node_modules/@material/auto-init/dist/mdc.autoInit.js",
132120
"@npm//:node_modules/@material/base/dist/mdc.base.js",

src/dev-app/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
<script src="https://www.youtube.com/iframe_api"></script>
3333
<script src="https://maps.googleapis.com/maps/api/js"></script>
3434
<script>
35+
System.config({
36+
map: {
37+
// Maps imports where the AMD module names start with workspace name (commonly done in Bazel).
38+
// This is needed for compatibility with dynamic runfile resolution of the devserver and the
39+
// static runfile resolution done in the "pkg_web" rule. In the built web package, the output
40+
// tree artifact serves as workspace root and root of the current dev-app Bazel package.
41+
'angular_material': '',
42+
'angular_material/src/dev-app': '',
43+
}
44+
});
3545
System.import('main').catch(console.error.bind(console));
3646
</script>
3747
</html>

src/dev-app/system-config-tmpl.js

Lines changed: 0 additions & 156 deletions
This file was deleted.

test/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3+
load("//tools:create-system-config.bzl", "create_system_config")
34
load("//tools:defaults.bzl", "ts_library")
45

56
exports_files(["bazel-karma-local-config.js"])
@@ -19,3 +20,14 @@ ts_library(
1920
"@npm//@types/jasmine",
2021
],
2122
)
23+
24+
# Creates a SystemJS configuration file that can be used for the Karma legacy
25+
# unit tests. This allows us to only have one canonical SystemJS configuration
26+
# file, and we don't need to repeat package/entry-point configurations.
27+
create_system_config(
28+
name = "system-config",
29+
base_url = "base/",
30+
node_modules_base_path = "node_modules/",
31+
output_name = "system-config.js",
32+
packages_dir = "dist/packages",
33+
)

0 commit comments

Comments
 (0)