build: upgrade angular build, integration/bazel and @angular/bazel package to rule_nodejs 2.2.0 (#37727)

Updates to rules_nodejs 2.2.0. This is the first major release in 7 months and includes a number of features as well
as breaking changes.

Release notes: https://github.com/bazelbuild/rules_nodejs/releases/tag/2.0.0

Features of note for angular/angular:

* stdout/stderr/exit code capture; this could be potentially be useful

* TypeScript (ts_project); a simpler tsc rule that ts_library that can be used in the repo where ts_library is too
  heavy weight

Breaking changes of note for angular/angular:

* loading custom rules from npm packages: `ts_library` is no longer loaded from `@npm_bazel_typescript//:index.bzl`
  (which no longer exists) but is now loaded from `@npm//@bazel/typescript:index.bzl`

* with the loading changes above, `load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")` is
  no longer needed in the WORKSPACE which also means that yarn_install does not need to run unless building/testing
  a target that depends on @npm. In angular/angular this is a minor improvement as almost everything depends on @npm.

* @angular/bazel package is also updated in this PR to support the new load location; Angular + Bazel users that
  require it for ng_package (ng_module is no longer needed in OSS with Angular 10) will need to load from
  `@npm//@angular/bazel:index.bzl`. I investigated if it was possible to maintain backward compatability for the old
  load location `@npm_angular_bazel` but it is not since the package itself needs to be updated to load from
  `@npm//@bazel/typescript:index.bzl` instead of `@npm_bazel_typescript//:index.bzl` as it depends on ts_library
  internals for ng_module.

* runfiles.resolve will now throw instead of returning undefined to match behavior of node require

Other changes in angular/angular:

* integration/bazel has been updated to use both ng_module and ts_libary with use_angular_plugin=true.
  The latter is the recommended way for rules_nodejs users to compile Angular 10 with Ivy. Bazel + Angular ViewEngine is
  supported with @angular/bazel <= 9.0.5 and Angular <= 8. There is still Angular ViewEngine example on rules_nodejs
  https://github.com/bazelbuild/rules_nodejs/tree/stable/examples/angular_view_engine on these older versions but users
  that want to update to Angular 10 and are on Bazel must switch to Ivy and at that point ts_library with
  use_angular_plugin=true is more performant that ng_module. Angular example in rules_nodejs is configured this way
  as well: https://github.com/bazelbuild/rules_nodejs/tree/stable/examples/angular. As an aside, we also have an
  example of building Angular 10 with architect() rule directly instead of using ts_library with angular plugin:
  https://github.com/bazelbuild/rules_nodejs/tree/stable/examples/angular_bazel_architect.

NB: ng_module is still required for angular/angular repository as it still builds ViewEngine & @angular/bazel
also provides the ng_package rule. ng_module can be removed in the future if ViewEngine is no longer needed in
angular repo.

* JSModuleInfo provider added to ng_module. this is for forward compat for future rules_nodejs versions.
  @josephperrott, this touches `packages/bazel/src/external.bzl` which will make the sync to g3 non-trivial.

PR Close #37727
This commit is contained in:
Greg Magolan
2020-06-25 01:32:41 -07:00
committed by Joey Perrott
parent f2341e2372
commit db56cf18ba
63 changed files with 833 additions and 536 deletions
+1 -2
View File
@@ -1,7 +1,6 @@
package(default_visibility = ["//visibility:public"])
load("@npm_bazel_typescript//:index.bzl", "ts_config")
load("//tools:defaults.bzl", "nodejs_binary")
load("//tools:defaults.bzl", "nodejs_binary", "ts_config")
exports_files([
"tsconfig.json",
+33 -9
View File
@@ -2,12 +2,12 @@
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
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_rollup//:index.bzl", _rollup_bundle = "rollup_bundle")
load("@npm_bazel_terser//:index.bzl", "terser_minified")
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("@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/rollup:index.bzl", _rollup_bundle = "rollup_bundle")
load("@npm//@bazel/terser:index.bzl", "terser_minified")
load("@npm//@bazel/typescript:index.bzl", _ts_config = "ts_config", _ts_devserver = "ts_devserver", _ts_library = "ts_library")
load("@npm//@bazel/protractor:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite")
load("@npm//typescript:index.bzl", "tsc")
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
load("//dev-infra/benchmark/ng_rollup_bundle:ng_rollup_bundle.bzl", _ng_rollup_bundle = "ng_rollup_bundle")
@@ -93,6 +93,8 @@ def ts_devserver(**kwargs):
**kwargs
)
ts_config = _ts_config
def ts_library(name, tsconfig = None, testonly = False, deps = [], module_name = None, **kwargs):
"""Default values for ts_library"""
deps = deps + ["@npm//tslib"]
@@ -168,12 +170,23 @@ def ng_package(name, readme_md = None, license_banner = None, deps = [], **kwarg
]
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": "{BUILD_SCM_VERSION}",
})
_ng_package(
name = name,
deps = deps,
readme_md = readme_md,
license_banner = license_banner,
substitutions = PKG_GROUP_REPLACEMENTS,
substitutions = select({
"//:stamp": stamped_substitutions,
"//conditions:default": substitutions,
}),
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,
@@ -192,13 +205,24 @@ def ng_package(name, readme_md = None, license_banner = None, deps = [], **kwarg
visibility = visibility,
)
def pkg_npm(name, substitutions = {}, **kwargs):
def pkg_npm(name, **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": "{BUILD_SCM_VERSION}",
})
_pkg_npm(
name = name,
substitutions = dict(substitutions, **PKG_GROUP_REPLACEMENTS),
substitutions = select({
"//:stamp": stamped_substitutions,
"//conditions:default": substitutions,
}),
visibility = visibility,
**kwargs
)
+9 -2
View File
@@ -188,8 +188,15 @@ class TestRunner {
if (binary.startsWith('external/')) {
binary = `../${binary.substring('external/'.length)}`;
}
const runfilesBinary = runfiles.resolveWorkspaceRelative(binary);
binary = fs.existsSync(runfilesBinary) ? runfilesBinary : binary;
try {
// Attempt to resolve runfiles location if command is expected to
// be in runfiles. For example, $(rootpath @nodejs//:yarn_bin)
const runfilesBinary = runfiles.resolveWorkspaceRelative(binary);
binary = (runfilesBinary && fs.existsSync(runfilesBinary)) ? runfilesBinary : binary;
} catch (e) {
// If resolveWorkspaceRelative then command is likely a built-in
// such as 'mkdir' or 'rm'
}
log(`running test command ${this.successful + 1} of ${this.config.commands.length}: '${
binary} ${args.join(' ')}' in '${this.testRoot}'`);
const spawnedProcess = spawnSync(binary, args, {cwd: this.testRoot, stdio: 'inherit'});
+1 -1
View File
@@ -1,6 +1,6 @@
# BEGIN-INTERNAL
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@npm_bazel_typescript//:index.bzl", "ts_library")
load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("//tools:defaults.bzl", "jasmine_node_test")
ts_library(