Greg Magolan 42a164f522 build: upgrade angular build, integration/bazel and @angular/bazel package to rule_nodejs 2.2.0 (#39182)
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.

PR Close #39182
2020-10-08 11:54:59 -07:00

115 lines
4.2 KiB
Python

load("//tools:defaults.bzl", "rollup_bundle", "ts_library")
load("@npm//@bazel/karma:index.bzl", "karma_web_test_suite")
def karma_test_prepare(name, env_srcs, env_deps, env_entry_point, test_srcs, test_deps, test_entry_point):
ts_library(
name = name + "_env",
testonly = True,
srcs = env_srcs,
deps = env_deps,
)
rollup_bundle(
name = name + "_env_rollup",
testonly = True,
sourcemap = "false",
entry_point = env_entry_point,
silent = True,
deps = [
":" + name + "_env",
"@npm//rollup-plugin-commonjs",
"@npm//rollup-plugin-node-resolve",
],
)
ts_library(
name = name + "_test",
testonly = True,
srcs = test_srcs,
deps = test_deps,
)
rollup_bundle(
name = name + "_rollup",
testonly = True,
silent = True,
sourcemap = "false",
entry_point = test_entry_point,
config_file = "//packages/zone.js:rollup-es5.config.js",
deps = [
":" + name + "_test",
"@npm//rollup-plugin-commonjs",
"@npm//rollup-plugin-node-resolve",
],
)
def karma_test(name, env_srcs, env_deps, env_entry_point, test_srcs, test_deps, test_entry_point, bootstraps, ci):
first = True
for subname in bootstraps:
bootstrap = bootstraps[subname]
firstFlag = first
if first:
first = False
karma_test_prepare(name, env_srcs, env_deps, env_entry_point, test_srcs, test_deps, test_entry_point)
_karma_test_required_dist_files = [
"//packages/zone.js/bundles:task-tracking.umd.js",
"//packages/zone.js/bundles:wtf.umd.js",
"//packages/zone.js/bundles:webapis-notification.umd.js",
"//packages/zone.js/bundles:webapis-media-query.umd.js",
"//packages/zone.js/bundles:zone-patch-canvas.umd.js",
"//packages/zone.js/bundles:zone-patch-fetch.umd.js",
"//packages/zone.js/bundles:zone-patch-resize-observer.umd.js",
"//packages/zone.js/bundles:zone-patch-message-port.umd.js",
"//packages/zone.js/bundles:zone-patch-user-media.umd.js",
":" + name + "_rollup.umd",
]
karma_web_test_suite(
name = subname + "_karma_jasmine_test",
srcs = [
"fake_entry.js",
],
bootstrap = [
":" + name + "_env_rollup.umd",
] + bootstrap +
_karma_test_required_dist_files,
browsers = ["//dev-infra/browsers/chromium:chromium"],
static_files = [
":assets/sample.json",
":assets/worker.js",
":assets/import.html",
],
tags = ["zone_karma_test"],
runtime_deps = [
"@npm//karma-browserstack-launcher",
],
)
if ci and firstFlag:
karma_web_test_suite(
name = "karma_jasmine_test_ci",
srcs = [
"fake_entry.js",
],
bootstrap = [
":saucelabs.js",
":" + name + "_env_rollup.umd",
"//packages/zone.js/bundles:zone-testing-bundle.umd.min.js",
] + _karma_test_required_dist_files,
browsers = ["//dev-infra/browsers/chromium:chromium"],
config_file = "//:karma-js.conf.js",
configuration_env_vars = ["KARMA_WEB_TEST_MODE"],
data = [
"//:browser-providers.conf.js",
"//tools:jasmine-seed-generator.js",
],
static_files = [
":assets/sample.json",
":assets/worker.js",
":assets/import.html",
],
tags = ["zone_karma_test"],
# Visible to //:saucelabs_unit_tests_poc target
visibility = ["//:__pkg__"],
runtime_deps = [
"@npm//karma-browserstack-launcher",
],
)