forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBUILD.bazel
392 lines (360 loc) · 10.8 KB
/
BUILD.bazel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
load("@aio_npm//@angular-devkit/architect-cli:index.bzl", "architect", "architect_test")
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "npm_package_bin")
load("//tools:defaults.bzl", "nodejs_binary")
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load(":local_packages_util.bzl", "link_local_packages", "substitute_local_package_deps")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
load("//aio/scripts:local_server_test.bzl", "local_server_test")
load("@aio_npm//@angular/build-tooling/bazel/remote-execution:index.bzl", "ENABLE_NETWORK")
load(":aio_targets.bzl", "aio_test")
load("@bazel_skylib//lib:collections.bzl", "collections")
exports_files([
"firebase.json",
"ngsw-config.json",
"ngsw-config.template.json",
"tsconfig.json",
])
# If set will use first party angular deps for aio targets instead of their npm equivalent
bool_flag(
name = "flag_aio_local_deps",
build_setting_default = False,
)
config_setting(
name = "aio_local_deps",
flag_values = {
":flag_aio_local_deps": "true",
},
)
# Config setting controlling the AIO architect configuration to build with
string_flag(
name = "flag_aio_build_config",
build_setting_default = "stable",
values = [
"stable",
"rc",
"next",
"archive",
],
)
config_setting(
name = "aio_build_config_stable",
flag_values = {
":flag_aio_build_config": "stable",
},
)
config_setting(
name = "aio_build_config_rc",
flag_values = {
":flag_aio_build_config": "rc",
},
)
config_setting(
name = "aio_build_config_next",
flag_values = {
":flag_aio_build_config": "next",
},
)
config_setting(
name = "aio_build_config_archive",
flag_values = {
":flag_aio_build_config": "archive",
},
)
# Run dgeni generation
npm_package_bin(
name = "dgeni",
# angular.io-package is a js_library target, which copies sources to $(BINDIR)
args = ["./$(BINDIR)/aio/tools/transforms/angular.io-package"],
data = [
"//aio/tools/transforms/angular.io-package",
# Dgeni typescript package crawls type definitions for Angular dependencies
"@npm//rxjs",
"@npm//@types/node",
],
env = {
"BAZEL_DGENI_OUTPUT_PATH": "$(@D)",
"GIT_BIN": "$(GIT_BIN_PATH)",
},
exec_properties = ENABLE_NETWORK,
output_dir = True,
stamp = "@rules_nodejs//nodejs/stamp:use_stamp_flag",
# Makes remote git calls to get previous versions
tags = [
"requires-network",
],
tool = "@aio_npm//dgeni/bin:dgeni",
toolchains = [
"@npm//@angular/build-tooling/bazel/git-toolchain:current_git_toolchain",
],
visibility = ["//aio/tests/deployment:__subpackages__"],
)
# Copy stackblitz live examples to expected assets location
copy_to_directory(
name = "stackblitz",
srcs = ["//aio/content/examples:all-stackblitz"],
replace_prefixes = {
"examples": "generated/live-examples",
},
root_paths = [
"aio/content",
],
)
# Copy example zips to expected assets location
copy_to_directory(
name = "example-zips",
srcs = ["//aio/content/examples:all-example-zips"],
replace_prefixes = {
"examples": "generated/zips",
},
root_paths = [
"aio/content",
],
)
# All source and configuration files required to build the docs app
APPLICATION_FILES = [
"angular.json",
"tsconfig.app.json",
"tsconfig.json",
"tsconfig.worker.json",
"security-exemptions.json",
"//aio/src/assets",
"//aio/src/assets/js",
] + glob(
["src/**/*"],
exclude = [
"src/**/*.spec.ts",
# Temporarily exclude generated sources produced by the non-bazel
# build until the whole project is built by bazel and this directory
# isn't needed.
"src/generated/**/*",
],
)
# Dependencies required to build the docs app.
APPLICATION_DEPS = [
":dgeni",
":stackblitz",
":example-zips",
"//aio/src/generated:ngsw-config",
"@aio_npm//@angular-devkit/build-angular",
"@aio_npm//@angular-eslint/builder",
"@aio_npm//@angular/animations",
"@aio_npm//@angular/cdk",
"@aio_npm//@angular/cli",
"@aio_npm//@angular/common",
"@aio_npm//@angular/compiler",
"@aio_npm//@angular/compiler-cli",
"@aio_npm//@angular/core",
"@aio_npm//@angular/elements",
"@aio_npm//@angular/forms",
"@aio_npm//@angular/material",
"@aio_npm//@angular/platform-browser",
"@aio_npm//@angular/platform-browser-dynamic",
"@aio_npm//@angular/router",
"@aio_npm//@angular/service-worker",
"@aio_npm//@types/lunr",
"@aio_npm//@types/trusted-types",
"@aio_npm//lunr",
"@aio_npm//rxjs",
"@aio_npm//safevalues",
"@aio_npm//tslib",
"@aio_npm//zone.js",
]
# All sources, specs, and config files required to test the docs app
TEST_FILES = APPLICATION_FILES + [
"karma.conf.js",
"tsconfig.spec.json",
] + glob(
["src/**/*.spec.ts"],
)
# Dependencies required to test the docs app
TEST_DEPS = APPLICATION_DEPS + [
"@aio_npm//@angular/build-tooling/bazel/browsers/chromium",
"@aio_npm//@types/jasmine",
"@aio_npm//@types/node",
"@aio_npm//assert",
"@aio_npm//jasmine",
"@aio_npm//jasmine-core",
"@aio_npm//karma-chrome-launcher",
"@aio_npm//karma-coverage",
"@aio_npm//karma-jasmine",
"@aio_npm//karma-jasmine-html-reporter",
"//aio/tools:windows-chromium-path",
]
# All sources, specs, and config files required to serve the app
# and run e2e tests against it
E2E_FILES = APPLICATION_FILES + glob(["tests/e2e/**"])
# Dependencies required to run the e2e tests
E2E_DEPS = APPLICATION_DEPS + [
"@aio_npm//@angular/build-tooling/bazel/browsers/chromium",
"@aio_npm//@types/jasmine",
"@aio_npm//@types/node",
"@aio_npm//jasmine-spec-reporter",
"@aio_npm//protractor",
"@aio_npm//ts-node",
"//aio/tools:windows-chromium-path",
]
# Poll period for architect rules that watch for changes
ARCHITECT_POLL_MS = 1000
# Stamp npm_link targets for all dependencies that correspond to a
# first-party equivalent pacakge in angular.
link_local_packages(all_aio_deps = collections.uniq(APPLICATION_DEPS + TEST_DEPS + E2E_DEPS))
copy_to_bin(
name = "application_files_bin",
srcs = APPLICATION_FILES,
)
architect(
name = "build-app",
args = select({
":aio_build_config_stable": ["site:build:stable"],
":aio_build_config_next": ["site:build:next"],
":aio_build_config_rc": ["site:build:rc"],
":aio_build_config_archive": ["site:build:archive"],
}) + [
"--output-path=build-app",
],
chdir = "$(RULEDIR)",
data = [":application_files_bin"] + select({
":aio_local_deps": substitute_local_package_deps(APPLICATION_DEPS),
"//conditions:default": APPLICATION_DEPS,
}),
output_dir = True,
# When building with local packages (--config=aio_local_deps), RBE complains about
# the input tree being too large (> 70,000 files).
tags = ["no-remote-exec"],
)
npm_package_bin(
name = "404-page",
outs = ["404.html"],
args = [
"$(execpath src/404-body.html)",
"$(execpath :build-app)",
"$@",
],
data = [
"src/404-body.html",
":build-app",
],
tool = "//aio/scripts:build-404-page",
)
# Prepare the final build artifact which substitutes a generated 404 page
# into the architect output.
copy_to_directory(
name = "build",
srcs = [
":404-page",
":build-app",
],
replace_prefixes = {
"build-app": "",
},
visibility = ["//aio/scripts/deploy-to-firebase:__pkg__"],
)
TEST_DATA = TEST_FILES + select({
":aio_local_deps": substitute_local_package_deps(TEST_DEPS),
"//conditions:default": TEST_DEPS,
})
aio_test(
name = "test",
args = [
"site:test",
"--no-watch",
],
data = TEST_DATA,
)
aio_test(
name = "test-and-watch",
args = [
"site:test",
"--watch",
"--poll=%d" % ARCHITECT_POLL_MS,
],
data = TEST_DATA,
tags = [
"ibazel_notify_changes",
"manual",
],
)
architect_test(
name = "e2e",
size = "large",
args = [
"site:e2e",
"--no-webdriver-update",
"--port=0",
],
chdir = package_name(),
data = E2E_FILES + select({
":aio_local_deps": substitute_local_package_deps(E2E_DEPS),
"//conditions:default": E2E_DEPS,
}),
env = {
"CHROME_BIN": "../$(CHROMIUM)",
"CHROMEDRIVER_BIN": "../$(CHROMEDRIVER)",
},
# TODO: investigate why those tests became more flaky
# (presumably after AIO migration to Bazel)
flaky = True,
toolchains = [
"@aio_npm//@angular/build-tooling/bazel/browsers/chromium:toolchain_alias",
],
)
# Build and serve the app. Run with ibazel to watch for changes and re-serve.
architect(
name = "serve",
args = [
"site:serve",
"--open",
"--poll=%d" % ARCHITECT_POLL_MS,
"--live-reload",
"--watch",
],
chdir = package_name(),
data = APPLICATION_FILES + select({
":aio_local_deps": substitute_local_package_deps(APPLICATION_DEPS),
"//conditions:default": APPLICATION_DEPS,
}),
tags = ["ibazel_notify_changes"],
)
# Build and serve the app, watch for changes, and run a fast but low-fidelity
# rebuild when docs change. Watching and serving is a part of the node script,
# so there is no need to run with ibazel, which would be slow as it would redo
# the full dgeni build on each change.
nodejs_binary(
name = "docs-watch",
chdir = package_name(),
data = APPLICATION_FILES + [
"//aio/scripts:fast-serve-and-watch",
] + select({
":aio_local_deps": substitute_local_package_deps(APPLICATION_DEPS),
"//conditions:default": APPLICATION_DEPS,
}),
enable_linker = True,
entry_point = "//aio/scripts:fast-serve-and-watch.js",
env = {
# Have the authors package output its low-fi dgeni build
# to a different directory in the runfiles tree because bazel
# write-protects original dgeni runfiles. Then in angular.json
# we list this folder last under assets so that it will
# take precedence over the original dgeni assets, effectively
# overwriting select sources and then serving them.
"BAZEL_DGENI_OUTPUT_PATH": "dgeni-fast",
},
)
local_server_test(
name = "test-a11y-score-localhost",
args = ["LOCALHOST_URL"],
entry_point = "//aio/scripts:test-aio-a11y",
serve_target = ":build",
)
local_server_test(
name = "test-pwa-score-localhost",
args = [
"LOCALHOST_URL",
"all:0,pwa:100",
],
data = [
"//aio/scripts:audit-web-app",
],
entry_point = "//aio/scripts:audit-web-app-script",
serve_target = ":build",
)