2018-01-09 15:24:00 -08:00
"""Re-export of some bazel rules with repository-wide defaults."""
2018-08-07 16:15:45 -07:00
2021-09-21 11:19:25 +02:00
load ( "@rules_pkg//:pkg.bzl" , "pkg_tar" )
2022-12-12 19:29:11 +00:00
load ( "@build_bazel_rules_nodejs//:index.bzl" , _npm_package_bin = "npm_package_bin" , _pkg_npm = "pkg_npm" )
2020-06-25 01:32:41 -07:00
load ( "@npm//@bazel/jasmine:index.bzl" , _jasmine_node_test = "jasmine_node_test" )
2022-12-15 20:50:19 +00:00
load ( "@npm//@bazel/concatjs:index.bzl" , _ts_config = "ts_config" , _ts_library = "ts_library" )
2020-06-25 01:32:41 -07:00
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" )
2020-02-04 11:45:40 -08:00
load ( "@npm//typescript:index.bzl" , "tsc" )
2022-07-27 08:03:49 +00:00
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" )
2022-12-08 17:40:44 +00:00
load ( "@npm//@angular/build-tooling/bazel/spec-bundling:spec-entrypoint.bzl" , "spec_entrypoint" )
2022-12-12 19:25:38 +00:00
load ( "@npm//@angular/build-tooling/bazel/spec-bundling:index.bzl" , "spec_bundle" )
2022-06-21 11:18:30 -07:00
load ( "@npm//tsec:index.bzl" , _tsec_test = "tsec_test" )
2022-12-06 13:57:06 +00:00
load ( "//packages/bazel:index.bzl" , _ng_module = "ng_module" , _ng_package = "ng_package" )
2022-12-16 20:04:01 +00:00
load ( "//tools/esm-interop:index.bzl" , "enable_esm_node_module_loader" , _nodejs_binary = "nodejs_binary" , _nodejs_test = "nodejs_test" )
2023-11-02 14:57:21 -07:00
load ( "@npm//@angular/build-tooling/bazel/api-gen:generate_api_docs.bzl" , _generate_api_docs = "generate_api_docs" )
2018-01-09 15:24:00 -08:00
2019-02-13 09:16:27 -08:00
_DEFAULT_TSCONFIG_TEST = "//packages:tsconfig-test"
2018-10-16 13:20:00 -07:00
_INTERNAL_NG_MODULE_COMPILER = "//packages/bazel/src/ngc-wrapped"
_INTERNAL_NG_MODULE_XI18N = "//packages/bazel/src/ngc-wrapped:xi18n"
2019-10-29 14:21:30 -07:00
_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"
2022-12-17 10:32:29 +00:00
_INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP = "//packages/bazel/src/ng_package/rollup"
2018-01-09 15:24:00 -08:00
2021-12-16 02:00:43 -05:00
esbuild_config = _esbuild_config
2022-03-26 16:54:20 +01:00
http_server = _http_server
2022-06-27 11:18:24 +00:00
extract_types = _extract_types
2021-12-16 02:00:43 -05:00
2018-03-13 11:00:53 -07:00
# Packages which are versioned together on npm
ANGULAR_SCOPED_PACKAGES = [ "@angular/ %s " % p for p in [
2018-08-07 16:15:45 -07:00
# 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" ,
2019-03-27 10:50:39 -07:00
# Current plan for Angular v8 is to not include @angular/http in ng update
# "http",
2018-08-07 16:15:45 -07:00
"platform-server" ,
"upgrade" ,
"router" ,
"language-service" ,
2019-11-11 07:52:46 +01:00
"localize" ,
2018-08-07 16:15:45 -07:00
"service-worker" ,
2018-03-13 11:00:53 -07:00
]]
PKG_GROUP_REPLACEMENTS = {
" \" NG_UPDATE_PACKAGE_GROUP \" " : """[
%s
2018-08-07 16:15:45 -07:00
]""" % ", \n " . join ([ " \" %s \" " % s for s in ANGULAR_SCOPED_PACKAGES ]),
2018-03-13 11:00:53 -07:00
}
2019-01-10 11:55:20 -08:00
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
2020-06-25 01:32:41 -07:00
ts_config = _ts_config
2022-11-16 14:33:32 +00:00
def ts_library (
name ,
tsconfig = None ,
testonly = False ,
deps = [],
module_name = None ,
package_name = None ,
2023-03-16 13:19:54 +00:00
devmode_target = "es2022" ,
prodmode_target = "es2022" ,
2022-11-16 14:33:32 +00:00
** kwargs ):
2018-10-04 13:14:14 -07:00
"""Default values for ts_library"""
2019-02-20 09:54:42 -08:00
deps = deps + [ "@npm//tslib" ]
2018-10-04 13:14:14 -07:00
if testonly :
# Match the types[] in //packages:tsconfig-test.json
2019-02-20 09:54:42 -08:00
deps . append ( "@npm//@types/jasmine" )
deps . append ( "@npm//@types/node" )
2019-04-02 11:42:58 -07:00
if not tsconfig and testonly :
tsconfig = _DEFAULT_TSCONFIG_TEST
2018-10-15 23:24:22 -07:00
2019-01-10 11:55:20 -08:00
if not module_name :
module_name = _default_module_name ( testonly )
2021-07-06 15:45:55 +02:00
# 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 )
2022-11-16 14:33:32 +00:00
default_module = "esnext"
2018-10-04 13:14:14 -07:00
_ts_library (
2019-12-28 18:14:36 -08:00
name = name ,
2018-10-04 13:14:14 -07:00
tsconfig = tsconfig ,
testonly = testonly ,
deps = deps ,
2023-03-16 13:19:54 +00:00
devmode_target = devmode_target ,
2022-12-16 20:04:01 +00:00
devmode_module = default_module ,
2023-03-16 11:21:04 +00:00
# For prodmode, the target is set to `ES2022`. `@bazel/typecript` sets `ES2015` by
2021-09-28 00:38:42 +02:00
# 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
2021-12-16 14:11:53 +01:00
# https://github.com/bazelbuild/rules_nodejs/blob/9b36274dba34204625579463e3da054a9f42cb47/packages/typescript/internal/build_defs.bzl#L85.
2023-03-16 13:19:54 +00:00
prodmode_target = prodmode_target ,
2022-11-16 14:33:32 +00:00
prodmode_module = default_module ,
2021-07-06 15:45:55 +02:00
# `module_name` is used for AMD module names within emitted JavaScript files.
2019-01-10 11:55:20 -08:00
module_name = module_name ,
2021-07-06 15:45:55 +02:00
# `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 ,
2018-10-04 13:14:14 -07:00
** kwargs
)
2018-01-09 15:24:00 -08:00
2022-03-21 12:24:52 +01:00
def ng_module ( name , tsconfig = None , entry_point = None , testonly = False , deps = [], module_name = None , package_name = None , ** kwargs ):
2018-10-04 13:14:14 -07:00
"""Default values for ng_module"""
2019-02-20 09:54:42 -08:00
deps = deps + [ "@npm//tslib" ]
2018-10-04 13:14:14 -07:00
if testonly :
# Match the types[] in //packages:tsconfig-test.json
2019-02-20 09:54:42 -08:00
deps . append ( "@npm//@types/jasmine" )
deps . append ( "@npm//@types/node" )
2019-04-02 11:42:58 -07:00
if not tsconfig and testonly :
tsconfig = _DEFAULT_TSCONFIG_TEST
2019-01-10 11:55:20 -08:00
if not module_name :
module_name = _default_module_name ( testonly )
2021-07-06 15:45:55 +02:00
# 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 )
2018-08-07 16:15:45 -07:00
if not entry_point :
entry_point = "public_api.ts"
2018-10-04 13:14:14 -07:00
_ng_module (
name = name ,
flat_module_out_file = name ,
tsconfig = tsconfig ,
entry_point = entry_point ,
testonly = testonly ,
deps = deps ,
2018-10-16 13:20:00 -07:00
compiler = _INTERNAL_NG_MODULE_COMPILER ,
ng_xi18n = _INTERNAL_NG_MODULE_XI18N ,
2021-07-06 15:45:55 +02:00
# `module_name` is used for AMD module names within emitted JavaScript files.
2019-01-10 11:55:20 -08:00
module_name = module_name ,
2021-07-06 15:45:55 +02:00
# `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 ,
2021-03-15 16:33:48 -07:00
perf_flag = "//packages/compiler-cli:ng_perf" ,
2018-10-04 13:14:14 -07:00
** kwargs
)
2018-05-21 15:48:00 -07:00
2018-10-04 13:14:14 -07:00
def ng_package ( name , readme_md = None , license_banner = None , deps = [], ** kwargs ):
"""Default values for ng_package"""
2018-08-07 16:15:45 -07:00
if not readme_md :
readme_md = "//packages:README.md"
if not license_banner :
license_banner = "//packages:license-banner.txt"
2020-02-04 11:45:40 -08:00
visibility = kwargs . pop ( "visibility" , None )
2018-02-13 11:26:06 -08:00
2020-06-25 01:32:41 -07:00
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 , ** {
2023-01-13 13:15:38 +00:00
"0.0.0-PLACEHOLDER" : " {STABLE_PROJECT_VERSION} " ,
2020-06-25 01:32:41 -07:00
})
2018-08-07 16:15:45 -07:00
_ng_package (
name = name ,
2018-10-04 13:14:14 -07:00
deps = deps ,
2022-08-10 02:26:39 -07:00
validate = True ,
2018-08-07 16:15:45 -07:00
readme_md = readme_md ,
license_banner = license_banner ,
2020-06-25 01:32:41 -07:00
substitutions = select ({
"//:stamp" : stamped_substitutions ,
"//conditions:default" : substitutions ,
}),
2019-10-29 14:21:30 -07:00
ng_packager = _INTERNAL_NG_PACKAGE_PACKAGER ,
rollup_config_tmpl = _INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP_CONFIG_TMPL ,
rollup = _INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP ,
2020-02-04 11:45:40 -08:00
visibility = visibility ,
2018-08-07 16:15:45 -07:00
** kwargs
)
2018-03-13 11:00:53 -07:00
2020-02-04 11:45:40 -08:00
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 ,
)
2022-12-16 20:04:01 +00:00
def pkg_npm ( name , deps = [], validate = True , ** kwargs ):
2020-02-04 11:45:40 -08:00
"""Default values for pkg_npm"""
visibility = kwargs . pop ( "visibility" , None )
2020-06-25 01:32:41 -07:00
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 , ** {
2023-01-13 13:15:38 +00:00
"0.0.0-PLACEHOLDER" : " {STABLE_PROJECT_VERSION} " ,
2020-06-25 01:32:41 -07:00
})
2022-12-16 20:04:01 +00:00
# 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.
2021-07-09 20:26:19 +02:00
extract_js_module_output (
name = " %s _js_module_output" % name ,
2022-12-16 20:04:01 +00:00
provider = "JSModuleInfo" ,
2021-07-09 20:26:19 +02:00
include_declarations = True ,
include_default_files = True ,
2021-11-18 14:55:50 +01:00
forward_linker_mappings = False ,
include_external_npm_packages = False ,
2021-07-09 20:26:19 +02:00
deps = deps ,
)
2019-12-28 16:37:59 -08:00
_pkg_npm (
2018-08-07 16:15:45 -07:00
name = name ,
2022-08-10 02:26:39 -07:00
validate = validate ,
2020-06-25 01:32:41 -07:00
substitutions = select ({
"//:stamp" : stamped_substitutions ,
"//conditions:default" : substitutions ,
}),
2021-07-09 20:26:19 +02:00
deps = [ ": %s _js_module_output" % name ],
2022-12-16 20:04:01 +00:00
visibility = visibility ,
2018-08-07 16:15:45 -07:00
** kwargs
)
2018-03-15 18:33:52 -07:00
2020-02-04 11:45:40 -08:00
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 ,
)
2022-12-14 10:38:17 +00:00
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 ):
2020-02-23 17:35:46 -08:00
"""Default values for karma_web_test_suite"""
# Default value for bootstrap
2022-12-12 19:25:38 +00:00
bootstrap = kwargs . pop ( "bootstrap" , []) + [
2020-02-23 17:35:46 -08:00
"//tools/testing:browser" ,
]
2022-12-12 19:25:38 +00:00
# Add common deps
deps = kwargs . pop ( "deps" , [])
2020-02-23 17:35:46 -08:00
data = kwargs . pop ( "data" , [])
tags = kwargs . pop ( "tags" , [])
2022-12-12 19:25:38 +00:00
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" ,
)
2020-02-23 17:35:46 -08:00
_karma_web_test_suite (
name = name ,
2022-12-12 19:25:38 +00:00
deps = [ ": %s _bundle" % name ],
2022-12-14 10:38:17 +00:00
browsers = browsers ,
2020-02-23 17:35:46 -08:00
data = data ,
tags = tags ,
** kwargs
)
2022-12-20 18:20:10 +00:00
# Add a saucelabs target for Karma tests in `//packages/`.
if native . package_name () . startswith ( "packages/" ):
_karma_web_test (
2023-02-20 12:37:34 -08:00
name = " {} _saucelabs" . format ( name ),
2022-12-20 18:20:10 +00:00
# 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" ,
2023-02-20 12:37:34 -08:00
"//tools/saucelabs-daemon/launcher:launcher_cjs" ,
2022-12-20 18:20:10 +00:00
],
tags = tags + [
"manual" ,
"no-remote-exec" ,
2023-09-29 14:44:46 +00:00
# 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" ,
2022-12-20 18:20:10 +00:00
"saucelabs" ,
],
configuration_env_vars = [ "KARMA_WEB_TEST_MODE" ],
** kwargs
)
2018-12-17 22:09:39 -08:00
2022-12-14 19:43:46 +00:00
def protractor_web_test_suite (
name ,
deps = [],
external = [],
browsers = [ "@npm//@angular/build-tooling/bazel/browsers/chromium:chromium" ],
** kwargs ):
2019-11-01 11:17:10 -07:00
"""Default values for protractor_web_test_suite"""
2022-12-13 20:39:23 +00:00
spec_bundle (
name = " %s _bundle" % name ,
deps = deps ,
platform = "cjs-legacy" ,
2022-12-14 19:43:46 +00:00
external = external + [ "protractor" ],
2022-12-13 20:39:23 +00:00
)
2019-11-01 11:17:10 -07:00
_protractor_web_test_suite (
2022-12-13 20:39:23 +00:00
name = name ,
deps = [ ": %s _bundle" % name ],
2022-12-14 19:43:46 +00:00
browsers = browsers ,
2018-12-17 22:09:39 -08:00
** kwargs
)
2022-12-06 13:57:06 +00:00
def nodejs_binary (
name ,
templated_args = [],
enable_linker = False ,
** kwargs ):
npm_workspace = _node_modules_workspace_name ()
2022-09-07 16:42:26 -07:00
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" ,
]
2018-10-04 13:14:14 -07:00
_nodejs_binary (
2022-12-06 13:57:06 +00:00
name = name ,
2022-12-12 19:29:11 +00:00
npm_workspace = npm_workspace ,
linker_enabled = enable_linker ,
2022-09-07 16:42:26 -07:00
templated_args = templated_args ,
2022-05-04 12:47:58 +00:00
** kwargs
)
2022-12-12 19:29:11 +00:00
def nodejs_test ( name , templated_args = [], enable_linker = False , ** kwargs ):
npm_workspace = _node_modules_workspace_name ()
2022-09-07 16:42:26 -07:00
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" ,
]
2022-05-04 12:47:58 +00:00
_nodejs_test (
2022-12-07 16:22:21 +00:00
name = name ,
2022-09-07 16:42:26 -07:00
templated_args = templated_args ,
2022-12-12 19:29:11 +00:00
linker_enabled = enable_linker ,
npm_workspace = npm_workspace ,
2022-05-04 12:47:58 +00:00
** kwargs
)
2022-09-07 16:42:26 -07:00
def _node_modules_workspace_name ():
return "npm" if not native . package_name () . startswith ( "aio" ) else "aio_npm"
2022-05-04 12:47:58 +00:00
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 ,
2018-10-04 13:14:14 -07:00
** kwargs
)
2018-09-11 18:11:32 -07:00
2022-12-13 20:39:23 +00:00
# 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.
2022-12-14 19:48:57 +00:00
def zone_compatible_jasmine_node_test ( name , external = [], srcs = [], deps = [], bootstrap = [], ** kwargs ):
2022-12-13 20:20:12 +00:00
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.
2022-12-14 19:48:57 +00:00
deps = srcs + deps + bootstrap ,
2022-12-13 20:20:12 +00:00
bootstrap = bootstrap ,
external = external + [ "domino" , "typescript" ],
platform = "node" ,
)
jasmine_node_test (
name = name ,
deps = [ ": %s _bundle" % name ],
** kwargs
)
2022-12-10 14:23:48 +00:00
def jasmine_node_test ( name , srcs = [], data = [], bootstrap = [], env = {}, ** kwargs ):
2020-01-07 23:56:49 -08:00
# Very common dependencies for tests
deps = kwargs . pop ( "deps" , []) + [
2019-02-20 09:54:42 -08:00
"@npm//chokidar" ,
"@npm//domino" ,
2019-03-21 12:11:29 -04:00
"@npm//jasmine-core" ,
2019-02-20 09:54:42 -08:00
"@npm//reflect-metadata" ,
"@npm//source-map-support" ,
"@npm//tslib" ,
"@npm//xhr2" ,
2018-10-04 13:14:14 -07:00
]
2021-11-02 14:39:52 -07:00
configuration_env_vars = kwargs . pop ( "configuration_env_vars" , [])
2021-02-04 14:09:42 -08:00
2022-05-04 12:47:58 +00:00
# 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" , [])
2022-12-08 17:40:44 +00:00
# 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 ,
2022-12-16 20:04:01 +00:00
deps = deps + srcs ,
bootstrap = bootstrap ,
2022-12-08 17:40:44 +00:00
)
2020-01-07 23:56:49 -08:00
2018-10-04 13:14:14 -07:00
_jasmine_node_test (
2022-12-08 17:40:44 +00:00
name = name ,
srcs = [ ": %s _spec_entrypoint.spec" % name ],
2022-12-16 20:04:01 +00:00
# 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 ,
2022-12-08 17:40:44 +00:00
use_direct_specs = True ,
2020-01-07 23:56:49 -08:00
configuration_env_vars = configuration_env_vars ,
2022-12-08 17:40:44 +00:00
env = env ,
2020-01-07 23:56:49 -08:00
templated_args = templated_args ,
2022-12-08 17:40:44 +00:00
use_esm = True ,
2018-10-04 13:14:14 -07:00
** kwargs
)
2018-09-11 18:11:32 -07:00
2021-12-15 16:22:01 +01:00
def app_bundle ( ** kwargs ):
"""Default values for app_bundle"""
_app_bundle ( ** kwargs )
2019-08-15 08:35:33 -07:00
2021-12-15 16:22:01 +01:00
# TODO: Consider removing this rule in favor of `esbuild` for more consistent bundling.
2019-12-22 10:27:41 +09:00
def rollup_bundle ( name , testonly = False , sourcemap = "true" , ** kwargs ):
2019-10-27 16:28:03 -07:00
"""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"
2020-10-10 04:06:24 +09:00
esm : "% {name} .esm.js"
esm : "% {name} .min.esm.js"
2019-10-27 16:28:03 -07:00
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 ,
}
2020-10-10 04:06:24 +09:00
# 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" ])
2019-10-27 16:28:03 -07:00
# es2015
2019-12-22 10:27:41 +09:00
_rollup_bundle ( name = name + ".es2015" , testonly = testonly , format = "iife" , sourcemap = sourcemap , ** kwargs )
2019-10-27 16:28:03 -07:00
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 = [
2020-01-08 02:08:00 -08:00
"$(execpath : %s .es2015.js)" % name ,
2019-10-27 16:28:03 -07:00
"--types" ,
"--skipLibCheck" ,
"--target" ,
"es5" ,
"--lib" ,
"es2015,dom" ,
"--allowJS" ,
"--outFile" ,
2020-01-08 02:08:00 -08:00
"$(execpath : %s .js)" % name ,
2019-10-27 16:28:03 -07:00
],
data = [
name + ".es2015.js" ,
],
2019-08-15 08:35:33 -07:00
)
2019-10-27 16:28:03 -07:00
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
2019-12-22 10:27:41 +09:00
_rollup_bundle ( name = name + ".umd" , testonly = testonly , format = "umd" , sourcemap = sourcemap , ** kwargs )
2019-10-27 16:28:03 -07:00
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 = [
2020-01-08 02:08:00 -08:00
"$(execpath : %s .umd.js)" % name ,
2019-10-27 16:28:03 -07:00
"--types" ,
"--skipLibCheck" ,
"--target" ,
"es5" ,
"--lib" ,
"es2015,dom" ,
"--allowJS" ,
"--outFile" ,
2020-01-08 02:08:00 -08:00
"$(execpath : %s .es5umd.js)" % name ,
2019-10-27 16:28:03 -07:00
],
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" ])
2020-02-26 09:09:35 -08:00
2021-06-28 19:50:44 +02:00
def api_golden_test ( ** kwargs ):
_api_golden_test (
2020-02-26 09:09:35 -08:00
** kwargs
)
2021-06-28 19:50:44 +02:00
def api_golden_test_npm_package ( ** kwargs ):
_api_golden_test_npm_package (
2020-02-26 09:09:35 -08:00
** kwargs
)
2022-06-21 11:18:30 -07:00
def tsec_test ( ** kwargs ):
"""Default values for tsec_test"""
_tsec_test (
use_runfiles_on_windows = True , # We explicitly enable runfiles in .bazelrc
** kwargs
)
2022-12-16 20:04:01 +00:00
def esbuild ( args = None , ** kwargs ):
_esbuild (
args = args if args else {
"resolveExtensions" : [ ".mjs" , ".js" , ".json" ],
},
** kwargs
)
2023-11-02 14:57:21 -07:00
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
)