-
Notifications
You must be signed in to change notification settings - Fork 25.8k
/
Copy pathdefaults.bzl
708 lines (631 loc) Β· 27.3 KB
/
defaults.bzl
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
"""Re-export of some bazel rules with repository-wide defaults."""
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test", _npm_package_bin = "npm_package_bin", _pkg_npm = "pkg_npm")
load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test")
load("@npm//@bazel/concatjs:index.bzl", _ts_config = "ts_config", _ts_library = "ts_library")
load("@npm//@bazel/rollup:index.bzl", _rollup_bundle = "rollup_bundle")
load("@npm//@bazel/terser:index.bzl", "terser_minified")
load("@npm//@bazel/protractor:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite")
load("@npm//typescript:index.bzl", "tsc")
load("@npm//@angular/build-tooling/bazel/app-bundling:index.bzl", _app_bundle = "app_bundle")
load("@npm//@angular/build-tooling/bazel/http-server:index.bzl", _http_server = "http_server")
load("@npm//@angular/build-tooling/bazel/karma:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
load("@npm//@angular/build-tooling/bazel/api-golden:index.bzl", _api_golden_test = "api_golden_test", _api_golden_test_npm_package = "api_golden_test_npm_package")
load("@npm//@angular/build-tooling/bazel:extract_js_module_output.bzl", "extract_js_module_output")
load("@npm//@angular/build-tooling/bazel:extract_types.bzl", _extract_types = "extract_types")
load("@npm//@angular/build-tooling/bazel/esbuild:index.bzl", _esbuild = "esbuild", _esbuild_config = "esbuild_config", _esbuild_esm_bundle = "esbuild_esm_bundle")
load("@npm//@angular/build-tooling/bazel/spec-bundling:spec-entrypoint.bzl", "spec_entrypoint")
load("@npm//@angular/build-tooling/bazel/spec-bundling:index.bzl", "spec_bundle")
load("@npm//tsec:index.bzl", _tsec_test = "tsec_test")
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
load("//tools/esm-interop:index.bzl", "enable_esm_node_module_loader", _nodejs_binary = "nodejs_binary", _nodejs_test = "nodejs_test")
load("//adev/shared-docs/pipeline/api-gen:generate_api_docs.bzl", _generate_api_docs = "generate_api_docs")
_DEFAULT_TSCONFIG_TEST = "//packages:tsconfig-test"
_INTERNAL_NG_MODULE_COMPILER = "//packages/bazel/src/ngc-wrapped"
_INTERNAL_NG_MODULE_XI18N = "//packages/bazel/src/ngc-wrapped:xi18n"
_INTERNAL_NG_PACKAGE_PACKAGER = "//packages/bazel/src/ng_package:packager"
_INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP_CONFIG_TMPL = "//packages/bazel/src/ng_package:rollup.config.js"
_INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP = "//packages/bazel/src/ng_package/rollup"
esbuild_config = _esbuild_config
esbuild_esm_bundle = _esbuild_esm_bundle
http_server = _http_server
extract_types = _extract_types
# Packages which are versioned together on npm
ANGULAR_SCOPED_PACKAGES = ["@angular/%s" % p for p in [
# core should be the first package because it's the main package in the group
# this is significant for Angular CLI and "ng update" specifically, @angular/core
# is considered the identifier of the group by these tools.
"core",
"bazel",
"common",
"compiler",
"compiler-cli",
"animations",
"elements",
"platform-browser",
"platform-browser-dynamic",
"forms",
# Current plan for Angular v8 is to not include @angular/http in ng update
# "http",
"platform-server",
"upgrade",
"router",
"language-service",
"localize",
"service-worker",
]]
PKG_GROUP_REPLACEMENTS = {
"\"NG_UPDATE_PACKAGE_GROUP\"": """[
%s
]""" % ",\n ".join(["\"%s\"" % s for s in ANGULAR_SCOPED_PACKAGES]),
}
def _default_module_name(testonly):
""" Provide better defaults for package names.
e.g. rather than angular/packages/core/testing we want @angular/core/testing
TODO(alexeagle): we ought to supply a default module name for every library in the repo.
But we short-circuit below in cases that are currently not working.
"""
pkg = native.package_name()
if testonly:
# Some tests currently rely on the long-form package names
return None
if pkg.startswith("packages/bazel"):
# Avoid infinite recursion in the ViewEngine compiler. Error looks like:
# Compiling Angular templates (ngc) //packages/bazel/test/ngc-wrapped/empty:empty failed (Exit 1)
# : RangeError: Maximum call stack size exceeded
# at normalizeString (path.js:57:25)
# at Object.normalize (path.js:1132:12)
# at Object.join (path.js:1167:18)
# at resolveModule (execroot/angular/bazel-out/host/bin/packages/bazel/src/ngc-wrapped/ngc-wrapped.runfiles/angular/packages/compiler-cli/src/metadata/bundler.js:582:50)
# at MetadataBundler.exportAll (execroot/angular/bazel-out/host/bin/packages/bazel/src/ngc-wrapped/ngc-wrapped.runfiles/angular/packages/compiler-cli/src/metadata/bundler.js:119:42)
# at MetadataBundler.exportAll (execroot/angular/bazel-out/host/bin/packages/bazel/src/ngc-wrapped/ngc-wrapped.runfiles/angular/packages/compiler-cli/src/metadata/bundler.js:121:52)
return None
if pkg.startswith("packages/"):
return "@angular/" + pkg[len("packages/"):]
return None
ts_config = _ts_config
def ts_library(
name,
tsconfig = None,
testonly = False,
deps = [],
module_name = None,
package_name = None,
devmode_target = "es2022",
prodmode_target = "es2022",
**kwargs):
"""Default values for ts_library"""
deps = deps + ["@npm//tslib"]
if testonly:
# Match the types[] in //packages:tsconfig-test.json
deps.append("@npm//@types/jasmine")
deps.append("@npm//@types/node")
if not tsconfig and testonly:
tsconfig = _DEFAULT_TSCONFIG_TEST
if not module_name:
module_name = _default_module_name(testonly)
# If no `package_name` is explicitly set, we use the default module name as package
# name, so that the target can be resolved within NodeJS executions, by activating
# the Bazel NodeJS linker. See: https://github.com/bazelbuild/rules_nodejs/pull/2799.
if not package_name:
package_name = _default_module_name(testonly)
default_module = "esnext"
_ts_library(
name = name,
tsconfig = tsconfig,
testonly = testonly,
deps = deps,
devmode_target = devmode_target,
devmode_module = default_module,
# For prodmode, the target is set to `ES2022`. `@bazel/typecript` sets `ES2015` by
# default. Note that this should be in sync with the `ng_module` tsconfig generation.
# https://github.com/bazelbuild/rules_nodejs/blob/901df3868e3ceda177d3ed181205e8456a5592ea/third_party/github.com/bazelbuild/rules_typescript/internal/common/tsconfig.bzl#L195
# https://github.com/bazelbuild/rules_nodejs/blob/9b36274dba34204625579463e3da054a9f42cb47/packages/typescript/internal/build_defs.bzl#L85.
prodmode_target = prodmode_target,
prodmode_module = default_module,
# `module_name` is used for AMD module names within emitted JavaScript files.
module_name = module_name,
# `package_name` can be set to allow for the Bazel NodeJS linker to run. This
# allows for resolution of the given target within the `node_modules/`.
package_name = package_name,
**kwargs
)
def ng_module(name, tsconfig = None, entry_point = None, testonly = False, deps = [], module_name = None, package_name = None, **kwargs):
"""Default values for ng_module"""
deps = deps + ["@npm//tslib"]
if testonly:
# Match the types[] in //packages:tsconfig-test.json
deps.append("@npm//@types/jasmine")
deps.append("@npm//@types/node")
if not tsconfig and testonly:
tsconfig = _DEFAULT_TSCONFIG_TEST
if not module_name:
module_name = _default_module_name(testonly)
# If no `package_name` is explicitly set, we use the default module name as package
# name, so that the target can be resolved within NodeJS executions, by activating
# the Bazel NodeJS linker. See: https://github.com/bazelbuild/rules_nodejs/pull/2799.
if not package_name:
package_name = _default_module_name(testonly)
if not entry_point:
entry_point = "public_api.ts"
_ng_module(
name = name,
flat_module_out_file = name,
tsconfig = tsconfig,
entry_point = entry_point,
testonly = testonly,
deps = deps,
compiler = _INTERNAL_NG_MODULE_COMPILER,
ng_xi18n = _INTERNAL_NG_MODULE_XI18N,
# `module_name` is used for AMD module names within emitted JavaScript files.
module_name = module_name,
# `package_name` can be set to allow for the Bazel NodeJS linker to run. This
# allows for resolution of the given target within the `node_modules/`.
package_name = package_name,
perf_flag = "//packages/compiler-cli:ng_perf",
**kwargs
)
def ng_package(name, readme_md = None, license_banner = None, license = None, deps = [], **kwargs):
"""Default values for ng_package"""
if not readme_md:
readme_md = "//packages:README.md"
if not license_banner:
license_banner = "//packages:license-banner.txt"
if not license:
license = "//:LICENSE"
visibility = kwargs.pop("visibility", None)
common_substitutions = dict(kwargs.pop("substitutions", {}), **PKG_GROUP_REPLACEMENTS)
substitutions = dict(common_substitutions, **{
"0.0.0-PLACEHOLDER": "0.0.0",
})
stamped_substitutions = dict(common_substitutions, **{
"0.0.0-PLACEHOLDER": "{STABLE_PROJECT_VERSION}",
})
_ng_package(
name = name,
deps = deps,
validate = True,
readme_md = readme_md,
license = license,
license_banner = license_banner,
substitutions = select({
"//:stamp": stamped_substitutions,
"//conditions:default": substitutions,
}),
ng_packager = _INTERNAL_NG_PACKAGE_PACKAGER,
rollup_config_tmpl = _INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP_CONFIG_TMPL,
rollup = _INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP,
visibility = visibility,
**kwargs
)
pkg_tar(
name = name + "_archive",
srcs = [":%s" % name],
extension = "tar.gz",
strip_prefix = "./%s" % name,
# should not be built unless it is a dependency of another rule
tags = ["manual"],
visibility = visibility,
)
def pkg_npm(name, deps = [], validate = True, **kwargs):
"""Default values for pkg_npm"""
visibility = kwargs.pop("visibility", None)
common_substitutions = dict(kwargs.pop("substitutions", {}), **PKG_GROUP_REPLACEMENTS)
substitutions = dict(common_substitutions, **{
"0.0.0-PLACEHOLDER": "0.0.0",
})
stamped_substitutions = dict(common_substitutions, **{
"0.0.0-PLACEHOLDER": "{STABLE_PROJECT_VERSION}",
})
# NOTE: We keep this to avoid the linker mappings from `deps` to be forwarded.
# e.g. the `pkg_npm` might have a `package_name` but the source `ts_library` too.
# This is a bug in `rules_nodejs` that should be fixed.
# TODO(devversion): Remove this when we landed a fix in `rules_nodejs`.
# Related to: https://github.com/bazelbuild/rules_nodejs/issues/2941.
extract_js_module_output(
name = "%s_js_module_output" % name,
provider = "JSModuleInfo",
include_declarations = True,
include_default_files = True,
forward_linker_mappings = False,
include_external_npm_packages = False,
deps = deps,
)
_pkg_npm(
name = name,
validate = validate,
substitutions = select({
"//:stamp": stamped_substitutions,
"//conditions:default": substitutions,
}),
deps = [":%s_js_module_output" % name],
visibility = visibility,
**kwargs
)
pkg_tar(
name = name + "_archive",
srcs = [":%s" % name],
extension = "tar.gz",
strip_prefix = "./%s" % name,
# should not be built unless it is a dependency of another rule
tags = ["manual"],
visibility = visibility,
)
def karma_web_test_suite(
name,
external = [],
browsers = [
"@npm//@angular/build-tooling/bazel/browsers/chromium:chromium",
"@npm//@angular/build-tooling/bazel/browsers/firefox:firefox",
],
**kwargs):
"""Default values for karma_web_test_suite"""
# Default value for bootstrap
bootstrap = kwargs.pop("bootstrap", []) + [
"//tools/testing:browser",
]
# Add common deps
deps = kwargs.pop("deps", [])
data = kwargs.pop("data", [])
tags = kwargs.pop("tags", [])
spec_bundle(
name = "%s_bundle" % name,
# Specs from this attribute are filtered and will be executed. We
# add bootstrap here for discovery of the module mappings aspect.
deps = deps + bootstrap,
bootstrap = bootstrap,
workspace_name = "angular",
external = external,
platform = "browser",
)
_karma_web_test_suite(
name = name,
deps = [":%s_bundle" % name],
browsers = browsers,
data = data,
tags = tags,
**kwargs
)
# Add a saucelabs target for Karma tests in `//packages/`.
if native.package_name().startswith("packages/"):
_karma_web_test(
name = "{}_saucelabs".format(name),
# Default timeout is moderate (5min). This causes the test to be terminated while
# Saucelabs browsers keep running. Ultimately resulting in failing tests and browsers
# unnecessarily being acquired. Our specified Saucelabs idle timeout is 10min, so we use
# Bazel's long timeout (15min). This ensures that Karma can shut down properly.
timeout = "long",
config_file = "//:karma-js.conf.js",
deps = [
":%s_bundle" % name,
],
data = data + [
"//:browser-providers.conf.js",
"//tools/saucelabs-daemon/launcher:launcher_cjs",
],
tags = tags + [
"manual",
"no-remote-exec",
# Requires network to be able to access saucelabs daemon
"requires-network",
# Prevent the sandbox from being used so that it can communicate with the saucelabs daemon
"no-sandbox",
"saucelabs",
],
configuration_env_vars = ["KARMA_WEB_TEST_MODE"],
**kwargs
)
def protractor_web_test_suite(
name,
deps = [],
external = [],
browsers = ["@npm//@angular/build-tooling/bazel/browsers/chromium:chromium"],
**kwargs):
"""Default values for protractor_web_test_suite"""
spec_bundle(
name = "%s_bundle" % name,
deps = deps,
platform = "cjs-legacy",
external = external + ["protractor"],
)
_protractor_web_test_suite(
name = name,
deps = [":%s_bundle" % name],
browsers = browsers,
**kwargs
)
def nodejs_binary(
name,
templated_args = [],
enable_linker = False,
**kwargs):
npm_workspace = _node_modules_workspace_name()
if not enable_linker:
templated_args = templated_args + [
# Disable the linker and rely on patched resolution which works better on Windows
# and is less prone to race conditions when targets build concurrently.
"--nobazel_run_linker",
]
_nodejs_binary(
name = name,
npm_workspace = npm_workspace,
linker_enabled = enable_linker,
templated_args = templated_args,
**kwargs
)
def nodejs_test(name, templated_args = [], enable_linker = False, **kwargs):
npm_workspace = _node_modules_workspace_name()
if not enable_linker:
templated_args = templated_args + [
# Disable the linker and rely on patched resolution which works better on Windows
# and is less prone to race conditions when targets build concurrently.
"--nobazel_run_linker",
]
_nodejs_test(
name = name,
templated_args = templated_args,
linker_enabled = enable_linker,
npm_workspace = npm_workspace,
**kwargs
)
def _node_modules_workspace_name():
return "npm"
def npm_package_bin(args = [], **kwargs):
_npm_package_bin(
# Disable the linker and rely on patched resolution which works better on Windows
# and is less prone to race conditions when targets build concurrently.
args = ["--nobazel_run_linker"] + args,
**kwargs
)
# TODO(devversion): Jasmine Node tests are only bundled using `spec_bundle`
# because `async/await` syntax needs to be downleveled for ZoneJS. In the
# future this can be removed when ZoneJS can work with native async/await in NodeJS.
def zone_compatible_jasmine_node_test(name, external = [], srcs = [], deps = [], bootstrap = [], **kwargs):
spec_bundle(
name = "%s_bundle" % name,
# Specs from this attribute are filtered and will be executed. We
# add bootstrap here for discovery of the module mappings aspect.
deps = srcs + deps + bootstrap,
bootstrap = bootstrap,
external = external + ["domino", "typescript"],
platform = "node",
)
jasmine_node_test(
name = name,
deps = [":%s_bundle" % name],
**kwargs
)
def esbuild_jasmine_node_test(name, specs = [], external = [], bootstrap = [], **kwargs):
templated_args = kwargs.pop("templated_args", []) + [
# TODO: Disable the linker fully here. Currently it is needed for ESM.
"--bazel_patch_module_resolver",
]
deps = kwargs.pop("deps", []) + [
"@npm//chokidar",
"@npm//domino",
"@npm//jasmine-core",
"@npm//reflect-metadata",
"@npm//source-map-support",
"@npm//tslib",
"@npm//xhr2",
]
spec_bundle(
name = "%s_test_bundle" % name,
platform = "node",
target = "es2020",
bootstrap = bootstrap,
deps = specs + deps,
external = external,
)
_jasmine_node_test(
name = name,
srcs = [":%s_test_bundle" % name],
use_direct_specs = True,
templated_args = templated_args,
deps = deps,
**kwargs
)
def jasmine_node_test(name, srcs = [], data = [], bootstrap = [], env = {}, **kwargs):
# Very common dependencies for tests
deps = kwargs.pop("deps", []) + [
"@npm//chokidar",
"@npm//domino",
"@npm//jasmine-core",
"@npm//reflect-metadata",
"@npm//source-map-support",
"@npm//tslib",
"@npm//xhr2",
]
configuration_env_vars = kwargs.pop("configuration_env_vars", [])
# Disable the linker and rely on patched resolution which works better on Windows
# and is less prone to race conditions when targets build concurrently.
templated_args = ["--nobazel_run_linker"] + kwargs.pop("templated_args", [])
# We disable the linker, so the ESM node module loader needs to be enabled.
npm_workspace = _node_modules_workspace_name()
env = enable_esm_node_module_loader(npm_workspace, env)
spec_entrypoint(
name = "%s_spec_entrypoint.spec" % name,
testonly = True,
deps = deps + srcs,
bootstrap = bootstrap,
)
_jasmine_node_test(
name = name,
srcs = [":%s_spec_entrypoint.spec" % name],
# Note: `deps`, `srcs` and `bootstrap` are explicitly added here as otherwise their linker
# mappings may not be discovered, given the `bootstrap` attr not being covered by the aspect.
data = data + deps + srcs + bootstrap,
use_direct_specs = True,
configuration_env_vars = configuration_env_vars,
env = env,
templated_args = templated_args,
use_esm = True,
**kwargs
)
def app_bundle(**kwargs):
"""Default values for app_bundle"""
_app_bundle(**kwargs)
# TODO: Consider removing this rule in favor of `esbuild` for more consistent bundling.
def rollup_bundle(name, testonly = False, sourcemap = "true", **kwargs):
"""A drop in replacement for the rules nodejs [legacy rollup_bundle].
Runs [rollup_bundle], [terser_minified] and [babel] for downleveling to es5
to produce a number of output bundles.
es2015 iife : "%{name}.es2015.js"
es2015 iife minified : "%{name}.min.es2015.js"
es2015 iife minified (debug) : "%{name}.min_debug.es2015.js"
esm : "%{name}.esm.js"
esm : "%{name}.min.esm.js"
es5 iife : "%{name}.js"
es5 iife minified : "%{name}.min.js"
es5 iife minified (debug) : "%{name}.min_debug.js"
es5 umd : "%{name}.es5umd.js"
es5 umd minified : "%{name}.min.es5umd.js"
es2015 umd : "%{name}.umd.js"
es2015 umd minified : "%{name}.min.umd.js"
".js.map" files are also produced for each bundle.
[legacy rollup_bundle]: https://github.com/bazelbuild/rules_nodejs/blob/0.38.3/internal/rollup/rollup_bundle.bzl
[rollup_bundle]: https://bazelbuild.github.io/rules_nodejs/Rollup.html
[terser_minified]: https://bazelbuild.github.io/rules_nodejs/Terser.html
[babel]: https://babeljs.io/
"""
# Common arguments for all terser_minified targets
common_terser_args = {
"args": ["--comments"],
"sourcemap": False,
}
# esm
_rollup_bundle(name = name + ".esm", testonly = testonly, format = "esm", sourcemap = sourcemap, **kwargs)
terser_minified(name = name + ".min.esm", testonly = testonly, src = name + ".esm", **common_terser_args)
native.filegroup(name = name + ".min.esm.js", testonly = testonly, srcs = [name + ".min.esm"])
# es2015
_rollup_bundle(name = name + ".es2015", testonly = testonly, format = "iife", sourcemap = sourcemap, **kwargs)
terser_minified(name = name + ".min.es2015", testonly = testonly, src = name + ".es2015", **common_terser_args)
native.filegroup(name = name + ".min.es2015.js", testonly = testonly, srcs = [name + ".min.es2015"])
terser_minified(name = name + ".min_debug.es2015", testonly = testonly, src = name + ".es2015", **common_terser_args)
native.filegroup(name = name + ".min_debug.es2015.js", testonly = testonly, srcs = [name + ".min_debug.es2015"])
# es5
tsc(
name = name,
testonly = testonly,
outs = [
name + ".js",
],
args = [
"$(execpath :%s.es2015.js)" % name,
"--types",
"--skipLibCheck",
"--target",
"es5",
"--lib",
"es2015,dom",
"--allowJS",
"--outFile",
"$(execpath :%s.js)" % name,
],
data = [
name + ".es2015.js",
],
)
terser_minified(name = name + ".min", testonly = testonly, src = name + "", **common_terser_args)
native.filegroup(name = name + ".min.js", testonly = testonly, srcs = [name + ".min"])
terser_minified(name = name + ".min_debug", testonly = testonly, src = name + "", debug = True, **common_terser_args)
native.filegroup(name = name + ".min_debug.js", testonly = testonly, srcs = [name + ".min_debug"])
# umd
_rollup_bundle(name = name + ".umd", testonly = testonly, format = "umd", sourcemap = sourcemap, **kwargs)
terser_minified(name = name + ".min.umd", testonly = testonly, src = name + ".umd", **common_terser_args)
native.filegroup(name = name + ".min.umd.js", testonly = testonly, srcs = [name + ".min.umd"])
tsc(
name = name + ".es5umd",
testonly = testonly,
outs = [
name + ".es5umd.js",
],
args = [
"$(execpath :%s.umd.js)" % name,
"--types",
"--skipLibCheck",
"--target",
"es5",
"--lib",
"es2015,dom",
"--allowJS",
"--outFile",
"$(execpath :%s.es5umd.js)" % name,
],
data = [
name + ".umd.js",
],
)
terser_minified(name = name + ".min.es5umd", testonly = testonly, src = name + ".es5umd", **common_terser_args)
native.filegroup(name = name + ".min.es5umd.js", testonly = testonly, srcs = [name + ".min.es5umd"])
def api_golden_test(**kwargs):
_api_golden_test(
**kwargs
)
def api_golden_test_npm_package(**kwargs):
_api_golden_test_npm_package(
**kwargs
)
def tsec_test(**kwargs):
"""Default values for tsec_test"""
_tsec_test(
use_runfiles_on_windows = True, # We explicitly enable runfiles in .bazelrc
**kwargs
)
def esbuild(args = None, **kwargs):
_esbuild(
args = args if args else {
"resolveExtensions": [".mjs", ".js", ".json"],
},
**kwargs
)
def esbuild_checked_in(name, **kwargs):
esbuild_esm_bundle(
name = "%s_generated" % name,
# Unfortunately we need to omit source maps from the checked-in files as these
# will vary based on the platform. See more details below in the sanitization
# genrule transformation. It is acceptable not having source-maps for the checked-in
# files as those are not minified and its to debug, the checked-in file can be visited.
sourcemap = "external",
# We always disable minification for checked-in files as otherwise it will
# become difficult determining potential differences. e.g. on Windows ESBuild
# accidentally included `source-map-support` due to the missing sandbox.
minify = False,
**kwargs
)
# ESBuild adds comments and function identifiers with the name of their module
# location. e.g. `"bazel-out/x64_windows-fastbuild/bin/node_modules/a"function(exports)`.
# We strip all of these paths as that would break approval of the he checked-in files within
# different platforms (e.g. RBE running with K8). Additionally these paths depend
# on the non-deterministic hoisting of the package manager across all platforms.
native.genrule(
name = "%s_sanitized" % name,
srcs = ["%s_generated.js" % name],
outs = ["%s_sanitized.js" % name],
cmd = """cat $< | sed -E "s#(bazel-out|node_modules)/[^\\"']+##g" > $@""",
)
generated_file_test(
name = name,
src = "%s.js" % name,
generated = "%s_sanitized.js" % name,
)
def generate_api_docs(**kwargs):
_generate_api_docs(
# We need to specify import mappings for Angular packages that import other Angular
# packages.
import_map = {
# We only need to specify top-level entry-points, and only those that
# are imported from other packages.
"//packages/animations:index.ts": "@angular/animations",
"//packages/common:index.ts": "@angular/common",
"//packages/core:index.ts": "@angular/core",
"//packages/forms:index.ts": "@angular/forms",
"//packages/localize:index.ts": "@angular/localize",
"//packages/platform-browser-dynamic:index.ts": "@angular/platform-browser-dynamic",
"//packages/platform-browser:index.ts": "@angular/platform-browser",
"//packages/platform-server:index.ts": "@angular/platform-server",
"//packages/router:index.ts": "@angular/router",
"//packages/upgrade:index.ts": "@angular/upgrade",
},
**kwargs
)