angular-cn/tools/defaults.bzl

392 lines
14 KiB
Python
Raw Normal View History

"""Re-export of some bazel rules with repository-wide defaults."""
load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _pkg_npm = "pkg_npm")
load("@npm_bazel_jasmine//:index.bzl", _jasmine_node_test = "jasmine_node_test")
load("@npm_bazel_karma//:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
load("@npm_bazel_typescript//:index.bzl", _ts_devserver = "ts_devserver", _ts_library = "ts_library")
load("@npm_bazel_protractor//:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite")
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
build: remove deps on legacy nodejs rules rollup_bundle internals (#33201) (#33607) The legacy nodejs rules rollup_bundle is now deprecated and will be removed in the nodejs rules 1.0 release due in mid-November. This PR brings in the rules_nodejs internal API deps that ng_rollup_bundle, ng_package and ls_rollup_bundle depend on into this repo to break the dependency. In the future these rules should switch to use the new rollup_bundle via a macro as done in https://github.com/angular/angular/pull/33329 but this is not possible right now due to the complication of having esm5 re-rooted ts_library dependencies. The es6 sources now have .mjs extensions so they no longer need to be re-rooted to `{package}.es6`. This eliminates the need for the collect_es6_sources() function. Note: repo has been updated to the newest working version of rollup which is 1.25.2. There is some regression in 1.26.0 which causes the following bundling failure: ``` ERROR: /Users/greg/google/angular/packages/localize/BUILD.bazel:20:1: Optimizing JavaScript packages/localize/localize.umd.min.js [terser] failed (Exit 1) terser.sh failed: error executing command bazel-out/host/bin/external/npm/terser/bin/terser.sh bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.js --output bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.min.js ... (remaining 5 argument(s) skipped) Use --sandbox_debug to see verbose messages from the sandbox Parse error at packages/localize/localize.umd.js:491,4 export * from './src/constants'; ^ ERROR: Export statement may only appear at top level at js_error (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/parse.js:357:11) at Dn.visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/scope.js:347:13) at Dn._visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1207:24) at AST_Export._walk (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:718:17) at walk_body (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:168:17) at AST_Function.call (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:430:13) at descend (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1208:21) at Dn.visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/scope.js:256:13) at Dn._visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1207:24) at AST_Function._walk (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:424:24) [Function] Target //packages/localize:npm_package failed to build Use --verbose_failures to see the command lines of failed build steps. ERROR: /Users/greg/google/angular/packages/localize/BUILD.bazel:20:1 Optimizing JavaScript packages/localize/localize.umd.min.js [terser] failed (Exit 1) terser.sh failed: error executing command bazel-out/host/bin/external/npm/terser/bin/terser.sh bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.js --output bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.min.js ... (remaining 5 argument(s) skipped) ``` Will leave that for another day. Terser also updated to 4.3.3. Updating to 4.3.4 (https://github.com/terser/terser/blob/master/CHANGELOG.md) turns comments preservation on by default which increases the size of the //packages/core/test/bundling/todo:bundle.min.js in CI. After bazelbuild/rules_nodejs#1317 terser can be updated to the latest as passing —comments /a^/ to args can turn off all comments for the //packages/core/test/bundling/todo:bundle.min.js size test. PR Close #33201 PR Close #33607
2019-10-29 17:21:30 -04:00
load("//tools/ng_rollup_bundle:ng_rollup_bundle.bzl", _ng_rollup_bundle = "ng_rollup_bundle")
load("//tools:ng_benchmark.bzl", _ng_benchmark = "ng_benchmark")
load("@npm_bazel_rollup//:index.bzl", _rollup_bundle = "rollup_bundle")
load("@npm_bazel_terser//:index.bzl", "terser_minified")
load("@npm//typescript:index.bzl", "tsc")
_DEFAULT_TSCONFIG_TEST = "//packages:tsconfig-test"
_INTERNAL_NG_MODULE_API_EXTRACTOR = "//packages/bazel/src/api-extractor:api_extractor"
_INTERNAL_NG_MODULE_COMPILER = "//packages/bazel/src/ngc-wrapped"
_INTERNAL_NG_MODULE_XI18N = "//packages/bazel/src/ngc-wrapped:xi18n"
build: remove deps on legacy nodejs rules rollup_bundle internals (#33201) (#33607) The legacy nodejs rules rollup_bundle is now deprecated and will be removed in the nodejs rules 1.0 release due in mid-November. This PR brings in the rules_nodejs internal API deps that ng_rollup_bundle, ng_package and ls_rollup_bundle depend on into this repo to break the dependency. In the future these rules should switch to use the new rollup_bundle via a macro as done in https://github.com/angular/angular/pull/33329 but this is not possible right now due to the complication of having esm5 re-rooted ts_library dependencies. The es6 sources now have .mjs extensions so they no longer need to be re-rooted to `{package}.es6`. This eliminates the need for the collect_es6_sources() function. Note: repo has been updated to the newest working version of rollup which is 1.25.2. There is some regression in 1.26.0 which causes the following bundling failure: ``` ERROR: /Users/greg/google/angular/packages/localize/BUILD.bazel:20:1: Optimizing JavaScript packages/localize/localize.umd.min.js [terser] failed (Exit 1) terser.sh failed: error executing command bazel-out/host/bin/external/npm/terser/bin/terser.sh bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.js --output bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.min.js ... (remaining 5 argument(s) skipped) Use --sandbox_debug to see verbose messages from the sandbox Parse error at packages/localize/localize.umd.js:491,4 export * from './src/constants'; ^ ERROR: Export statement may only appear at top level at js_error (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/parse.js:357:11) at Dn.visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/scope.js:347:13) at Dn._visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1207:24) at AST_Export._walk (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:718:17) at walk_body (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:168:17) at AST_Function.call (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:430:13) at descend (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1208:21) at Dn.visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/scope.js:256:13) at Dn._visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1207:24) at AST_Function._walk (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:424:24) [Function] Target //packages/localize:npm_package failed to build Use --verbose_failures to see the command lines of failed build steps. ERROR: /Users/greg/google/angular/packages/localize/BUILD.bazel:20:1 Optimizing JavaScript packages/localize/localize.umd.min.js [terser] failed (Exit 1) terser.sh failed: error executing command bazel-out/host/bin/external/npm/terser/bin/terser.sh bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.js --output bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.min.js ... (remaining 5 argument(s) skipped) ``` Will leave that for another day. Terser also updated to 4.3.3. Updating to 4.3.4 (https://github.com/terser/terser/blob/master/CHANGELOG.md) turns comments preservation on by default which increases the size of the //packages/core/test/bundling/todo:bundle.min.js in CI. After bazelbuild/rules_nodejs#1317 terser can be updated to the latest as passing —comments /a^/ to args can turn off all comments for the //packages/core/test/bundling/todo:bundle.min.js size test. PR Close #33201 PR Close #33607
2019-10-29 17:21:30 -04:00
_INTERNAL_NG_PACKAGE_PACKAGER = "//packages/bazel/src/ng_package:packager"
_INTERNAL_NG_PACKAGE_DEFALUT_TERSER_CONFIG_FILE = "//packages/bazel/src/ng_package:terser_config.default.json"
_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_for_ng_package"
# 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",
"platform-webworker",
"platform-webworker-dynamic",
"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
def ts_devserver(**kwargs):
"""Default values for ts_devserver"""
serving_path = kwargs.pop("serving_path", "/app_bundle.js")
_ts_devserver(
serving_path = serving_path,
**kwargs
)
def ts_library(name, tsconfig = None, testonly = False, deps = [], module_name = None, **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")
build: fix build failures with worker mode cache and @types/events (#31325) Errors observed only in tests on CircleCI — was not reproducible locally. ``` ERROR: /home/circleci/ng/packages/http/test/BUILD.bazel:3:1: Compiling TypeScript (devmode) //packages/http/test:test_lib failed (Exit 1): tsc_wrapped failed: error executing command (cd /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular && \ exec env - \ BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \ PATH=/bin:/usr/bin:/usr/local/bin \ bazel-out/host/bin/external/npm/@bazel/typescript/bin/tsc_wrapped @@bazel-out/k8-fastbuild/bin/packages/http/test/test_lib_es5_tsconfig.json) Execution platform: //tools:rbe_ubuntu1604-angular Compilation failed Error: missing input digest for /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular/external/npm/node_modules/@types/events/index.d.ts. ERROR: /home/circleci/ng/packages/benchpress/test/BUILD.bazel:3:1: Compiling TypeScript (devmode) //packages/benchpress/test:test_lib failed (Exit 1): tsc_wrapped failed: error executing command (cd /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular && \ exec env - \ BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \ PATH=/bin:/usr/bin:/usr/local/bin \ bazel-out/host/bin/external/npm/@bazel/typescript/bin/tsc_wrapped @@bazel-out/k8-fastbuild/bin/packages/benchpress/test/test_lib_es5_tsconfig.json) Execution platform: //tools:rbe_ubuntu1604-angular Compilation failed Error: missing input digest for /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular/external/npm/node_modules/@types/events/index.d.ts ERROR: C:/codefresh/volume/angular/packages/compiler/test/css_parser/BUILD.bazel:3:1: Compiling TypeScript (devmode) //packages/compiler/test/css_parser:css_parser_lib failed (Exit 1): tsc_wrapped.exe failed: error executing command cd C:/users/containeradministrator/_bazel_containeradministrator/zquin2l6/execroot/angular SET PATH=C:\msys64\usr\bin;C:\msys64\bin;C:\Windows;C:\Windows\System32;C:\Windows\System32\WindowsPowerShell\v1.0 SET RUNFILES_MANIFEST_ONLY=1 bazel-out/host/bin/external/npm/@bazel/typescript/bin/tsc_wrapped.exe @@bazel-out/x64_windows-fastbuild/bin/packages/compiler/test/css_parser/css_parser_lib_es5_tsconfig.json Execution platform: @bazel_tools//platforms:host_platform Compilation failed Error: missing input digest for C:/users/containeradministrator/_bazel_containeradministrator/zquin2l6/execroot/angular/external/npm/node_modules/@types/events/index. d.ts ``` PR Close #31325
2019-06-22 00:52:00 -04:00
deps.append("@npm//@types/events")
if not tsconfig and testonly:
tsconfig = _DEFAULT_TSCONFIG_TEST
if not module_name:
module_name = _default_module_name(testonly)
_ts_library(
name = name,
tsconfig = tsconfig,
testonly = testonly,
deps = deps,
module_name = module_name,
**kwargs
)
# Select the es5 .js output of the ts_library for use in downstream boostrap targets
# with `output_group = "es5_sources"`. This exposes an internal detail of ts_library
# that is not ideal.
# TODO(gregmagolan): clean this up by using tsc() in these cases rather than ts_library
native.filegroup(
name = "%s_es5" % name,
srcs = [":%s" % name],
testonly = testonly,
output_group = "es5_sources",
)
def ng_module(name, tsconfig = None, entry_point = None, testonly = False, deps = [], module_name = None, bundle_dts = True, **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")
build: fix build failures with worker mode cache and @types/events (#31325) Errors observed only in tests on CircleCI — was not reproducible locally. ``` ERROR: /home/circleci/ng/packages/http/test/BUILD.bazel:3:1: Compiling TypeScript (devmode) //packages/http/test:test_lib failed (Exit 1): tsc_wrapped failed: error executing command (cd /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular && \ exec env - \ BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \ PATH=/bin:/usr/bin:/usr/local/bin \ bazel-out/host/bin/external/npm/@bazel/typescript/bin/tsc_wrapped @@bazel-out/k8-fastbuild/bin/packages/http/test/test_lib_es5_tsconfig.json) Execution platform: //tools:rbe_ubuntu1604-angular Compilation failed Error: missing input digest for /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular/external/npm/node_modules/@types/events/index.d.ts. ERROR: /home/circleci/ng/packages/benchpress/test/BUILD.bazel:3:1: Compiling TypeScript (devmode) //packages/benchpress/test:test_lib failed (Exit 1): tsc_wrapped failed: error executing command (cd /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular && \ exec env - \ BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \ PATH=/bin:/usr/bin:/usr/local/bin \ bazel-out/host/bin/external/npm/@bazel/typescript/bin/tsc_wrapped @@bazel-out/k8-fastbuild/bin/packages/benchpress/test/test_lib_es5_tsconfig.json) Execution platform: //tools:rbe_ubuntu1604-angular Compilation failed Error: missing input digest for /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular/external/npm/node_modules/@types/events/index.d.ts ERROR: C:/codefresh/volume/angular/packages/compiler/test/css_parser/BUILD.bazel:3:1: Compiling TypeScript (devmode) //packages/compiler/test/css_parser:css_parser_lib failed (Exit 1): tsc_wrapped.exe failed: error executing command cd C:/users/containeradministrator/_bazel_containeradministrator/zquin2l6/execroot/angular SET PATH=C:\msys64\usr\bin;C:\msys64\bin;C:\Windows;C:\Windows\System32;C:\Windows\System32\WindowsPowerShell\v1.0 SET RUNFILES_MANIFEST_ONLY=1 bazel-out/host/bin/external/npm/@bazel/typescript/bin/tsc_wrapped.exe @@bazel-out/x64_windows-fastbuild/bin/packages/compiler/test/css_parser/css_parser_lib_es5_tsconfig.json Execution platform: @bazel_tools//platforms:host_platform Compilation failed Error: missing input digest for C:/users/containeradministrator/_bazel_containeradministrator/zquin2l6/execroot/angular/external/npm/node_modules/@types/events/index. d.ts ``` PR Close #31325
2019-06-22 00:52:00 -04:00
deps.append("@npm//@types/events")
if not tsconfig and testonly:
tsconfig = _DEFAULT_TSCONFIG_TEST
if not module_name:
module_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,
bundle_dts = bundle_dts,
deps = deps,
compiler = _INTERNAL_NG_MODULE_COMPILER,
api_extractor = _INTERNAL_NG_MODULE_API_EXTRACTOR,
ng_xi18n = _INTERNAL_NG_MODULE_XI18N,
module_name = module_name,
**kwargs
)
build(ivy): support alternate compilation modes to enable Ivy testing (#24056) Bazel has a restriction that a single output (eg. a compiled version of //packages/common) can only be produced by a single rule. This precludes the Angular repo from having multiple rules that build the same code. And the complexity of having a single rule produce multiple outputs (eg. an ngc-compiled version of //packages/common and an Ivy-enabled version) is too high. Additionally, the Angular repo has lots of existing tests which could be executed as-is under Ivy. Such testing is very valuable, and it would be nice to share not only the code, but the dependency graph / build config as well. Thus, this change introduces a --define flag 'compile' with three potential values. When --define=compile=X is set, the entire build system runs in a particular mode - the behavior of all existing targets is controlled by the flag. This allows us to reuse our entire build structure for testing in a variety of different manners. The flag has three possible settings: * legacy (the default): the traditional View Engine (ngc) build * local: runs the prototype ngtsc compiler, which does not rely on global analysis * jit: runs ngtsc in a mode which executes tsickle, but excludes the Angular related transforms, which approximates the behavior of plain tsc. This allows the main packages such as common to be tested with the JIT compiler. Additionally, the ivy_ng_module() rule still exists and runs ngc in a mode where Ivy-compiled output is produced from global analysis information, as a stopgap while ngtsc is being developed. PR Close #24056
2018-05-21 18:48:00 -04:00
def ng_package(name, readme_md = None, license_banner = 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"
deps = deps + [
"@npm//tslib",
]
_ng_package(
name = name,
deps = deps,
readme_md = readme_md,
license_banner = license_banner,
substitutions = PKG_GROUP_REPLACEMENTS,
build: remove deps on legacy nodejs rules rollup_bundle internals (#33201) (#33607) The legacy nodejs rules rollup_bundle is now deprecated and will be removed in the nodejs rules 1.0 release due in mid-November. This PR brings in the rules_nodejs internal API deps that ng_rollup_bundle, ng_package and ls_rollup_bundle depend on into this repo to break the dependency. In the future these rules should switch to use the new rollup_bundle via a macro as done in https://github.com/angular/angular/pull/33329 but this is not possible right now due to the complication of having esm5 re-rooted ts_library dependencies. The es6 sources now have .mjs extensions so they no longer need to be re-rooted to `{package}.es6`. This eliminates the need for the collect_es6_sources() function. Note: repo has been updated to the newest working version of rollup which is 1.25.2. There is some regression in 1.26.0 which causes the following bundling failure: ``` ERROR: /Users/greg/google/angular/packages/localize/BUILD.bazel:20:1: Optimizing JavaScript packages/localize/localize.umd.min.js [terser] failed (Exit 1) terser.sh failed: error executing command bazel-out/host/bin/external/npm/terser/bin/terser.sh bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.js --output bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.min.js ... (remaining 5 argument(s) skipped) Use --sandbox_debug to see verbose messages from the sandbox Parse error at packages/localize/localize.umd.js:491,4 export * from './src/constants'; ^ ERROR: Export statement may only appear at top level at js_error (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/parse.js:357:11) at Dn.visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/scope.js:347:13) at Dn._visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1207:24) at AST_Export._walk (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:718:17) at walk_body (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:168:17) at AST_Function.call (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:430:13) at descend (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1208:21) at Dn.visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/scope.js:256:13) at Dn._visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1207:24) at AST_Function._walk (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:424:24) [Function] Target //packages/localize:npm_package failed to build Use --verbose_failures to see the command lines of failed build steps. ERROR: /Users/greg/google/angular/packages/localize/BUILD.bazel:20:1 Optimizing JavaScript packages/localize/localize.umd.min.js [terser] failed (Exit 1) terser.sh failed: error executing command bazel-out/host/bin/external/npm/terser/bin/terser.sh bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.js --output bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.min.js ... (remaining 5 argument(s) skipped) ``` Will leave that for another day. Terser also updated to 4.3.3. Updating to 4.3.4 (https://github.com/terser/terser/blob/master/CHANGELOG.md) turns comments preservation on by default which increases the size of the //packages/core/test/bundling/todo:bundle.min.js in CI. After bazelbuild/rules_nodejs#1317 terser can be updated to the latest as passing —comments /a^/ to args can turn off all comments for the //packages/core/test/bundling/todo:bundle.min.js size test. PR Close #33201 PR Close #33607
2019-10-29 17:21:30 -04:00
ng_packager = _INTERNAL_NG_PACKAGE_PACKAGER,
terser_config_file = _INTERNAL_NG_PACKAGE_DEFALUT_TERSER_CONFIG_FILE,
rollup_config_tmpl = _INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP_CONFIG_TMPL,
rollup = _INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP,
**kwargs
)
def pkg_npm(name, substitutions = {}, **kwargs):
"""Default values for npm_package"""
_pkg_npm(
name = name,
substitutions = dict(substitutions, **PKG_GROUP_REPLACEMENTS),
**kwargs
)
def karma_web_test(bootstrap = [], deps = [], data = [], runtime_deps = [], **kwargs):
"""Default values for karma_web_test"""
if not bootstrap:
bootstrap = ["//:web_test_bootstrap_scripts"]
local_deps = [
"@npm//karma-browserstack-launcher",
"@npm//karma-sauce-launcher",
"@npm//:node_modules/tslib/tslib.js",
"//tools/rxjs:rxjs_umd_modules",
"//packages/zone.js:npm_package",
] + deps
local_runtime_deps = [
"//tools/testing:browser",
] + runtime_deps
_karma_web_test(
runtime_deps = local_runtime_deps,
bootstrap = bootstrap,
config_file = "//:karma-js.conf.js",
deps = local_deps,
data = data + [
"//:browser-providers.conf.js",
"//tools:jasmine-seed-generator.js",
],
configuration_env_vars = ["KARMA_WEB_TEST_MODE"],
**kwargs
)
def karma_web_test_suite(bootstrap = [], deps = [], runtime_deps = [], **kwargs):
"""Default values for karma_web_test_suite"""
if not bootstrap:
bootstrap = ["//:web_test_bootstrap_scripts"]
local_deps = [
"@npm//:node_modules/tslib/tslib.js",
"//tools/rxjs:rxjs_umd_modules",
] + deps
local_runtime_deps = [
"//tools/testing:browser",
] + runtime_deps
_karma_web_test_suite(
runtime_deps = local_runtime_deps,
bootstrap = bootstrap,
deps = local_deps,
browsers = ["//tools/browsers:chromium"],
**kwargs
)
def protractor_web_test_suite(**kwargs):
"""Default values for protractor_web_test_suite"""
_protractor_web_test_suite(
browsers = ["//tools/browsers:chromium"],
**kwargs
)
def ng_benchmark(**kwargs):
"""Default values for ng_benchmark"""
_ng_benchmark(**kwargs)
def nodejs_binary(data = [], **kwargs):
"""Default values for nodejs_binary"""
_nodejs_binary(
configuration_env_vars = ["angular_ivy_enabled"],
data = data + ["@npm//source-map-support"],
**kwargs
)
def jasmine_node_test(bootstrap = [], **kwargs):
"""Default values for jasmine_node_test"""
# 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", []) + [
"angular_ivy_enabled",
]
templated_args = kwargs.pop("templated_args", [])
for label in bootstrap:
deps += [label]
templated_args += ["--node_options=--require=$(rlocation $(location %s))" % label]
_jasmine_node_test(
deps = deps,
configuration_env_vars = configuration_env_vars,
templated_args = templated_args,
**kwargs
)
def ng_rollup_bundle(deps = [], **kwargs):
"""Default values for ng_rollup_bundle"""
deps = deps + [
"@npm//tslib",
"@npm//reflect-metadata",
]
_ng_rollup_bundle(
deps = deps,
**kwargs
)
def rollup_bundle(name, testonly = False, **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"
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,
}
# es2015
_rollup_bundle(name = name + ".es2015", testonly = testonly, format = "iife", sourcemap = "true", **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 = [
"$(location :%s.es2015.js)" % name,
"--types",
"--skipLibCheck",
"--target",
"es5",
"--lib",
"es2015,dom",
"--allowJS",
"--outFile",
"$(location :%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 = "true", **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 = [
"$(location :%s.umd.js)" % name,
"--types",
"--skipLibCheck",
"--target",
"es5",
"--lib",
"es2015,dom",
"--allowJS",
"--outFile",
"$(location :%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"])