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
149 lines
5.2 KiB
Python
149 lines
5.2 KiB
Python
load("//dev-infra/benchmark/ng_rollup_bundle:ng_rollup_bundle.bzl", "ng_rollup_bundle")
|
|
load("//tools:defaults.bzl", "ng_module")
|
|
load("@npm//@bazel/typescript:index.bzl", "ts_devserver", "ts_library")
|
|
load(":benchmark_test.bzl", "benchmark_test")
|
|
|
|
def copy_default_file(origin, destination):
|
|
"""
|
|
Copies a file from ./defaults to the destination.
|
|
|
|
Args:
|
|
origin: The name of a file in ./defaults to be copied.
|
|
destination: Where the original file will be clopied to.
|
|
"""
|
|
native.genrule(
|
|
name = "copy_default_" + origin + "_file_genrule",
|
|
srcs = ["//dev-infra/benchmark/component_benchmark/defaults:" + origin],
|
|
outs = [destination],
|
|
cmd = "cat $(SRCS) >> $@",
|
|
)
|
|
|
|
def component_benchmark(
|
|
name,
|
|
prefix,
|
|
driver,
|
|
driver_deps,
|
|
ng_srcs,
|
|
ng_deps,
|
|
ng_assets = [],
|
|
assets = None,
|
|
styles = None,
|
|
entry_point = None,
|
|
entry_point_deps = [
|
|
"//packages/core",
|
|
"//packages/platform-browser",
|
|
]):
|
|
"""
|
|
Runs a benchmark test against the given angular app using the given driver.
|
|
|
|
This rule was created with the intention of reducing the amount of
|
|
duplicate/boilderplate code, while also allowing you to be as verbose with
|
|
your app as you'd like. The goal being that if you just want to test a
|
|
simple component, the only thing you'd need to provide are the component
|
|
(via ng_srcs) and driver.
|
|
|
|
** USAGE NOTES **
|
|
|
|
(assets/styles): The default index.html imports a stylesheet named
|
|
"styles.css". This allows the use of the default index.html with a custom
|
|
stylesheet through the styles arg by providing either a styles.css in the
|
|
prefix directory or by providing a css binary named styles.css.
|
|
|
|
(assets): The default index.html expects that the root selector for
|
|
the benchmark app is "app-root".
|
|
|
|
(entry_point): The default entry_point expects a file named "app.module" to export
|
|
the root NgModule for the benchmark application. It also expects that the
|
|
root NgModule is named "AppModule".
|
|
|
|
TIP: The server is named `name + "_server"` so that you can view/debug the
|
|
app.
|
|
|
|
Args:
|
|
name: The name of the benchmark_test to be run
|
|
prefix: The relative path to the root directory of the benchmark app
|
|
driver: The ts driver for running the benchmark
|
|
driver_deps: Driver's dependencies
|
|
ng_srcs: All of the ts srcs for the angular app
|
|
ng_deps: Dependencies for the angular app
|
|
ng_assets: The static assets for the angular app
|
|
assets: Static files
|
|
styles: Stylesheets
|
|
entry_point: Main entry point for the angular app
|
|
entry_point_deps: Entry point's dependencies
|
|
"""
|
|
app_lib = name + "_app_lib"
|
|
app_main = name + "_app_main"
|
|
benchmark_driver = name + "_driver"
|
|
server = name + "_server"
|
|
|
|
# If the user doesn't provide assets, entry_point, or styles, we use a
|
|
# default version.
|
|
# Note that we copy the default files to the same directory as what is used
|
|
# by the app for three reasons:
|
|
# 1. To avoid having the entry point be defined in a different package from
|
|
# where this macro is called.
|
|
# 2. So that we can use relative paths for imports in entry point.
|
|
# 3. To make using default static files as seamless as possible.
|
|
|
|
if not entry_point:
|
|
entry_point = prefix + "default_index.ts"
|
|
ng_srcs.append(entry_point)
|
|
copy_default_file("index.ts", entry_point)
|
|
|
|
if not assets:
|
|
html = prefix + "index.html"
|
|
assets = [html]
|
|
copy_default_file("index.html", html)
|
|
|
|
if not styles:
|
|
css = prefix + "styles.css"
|
|
styles = [css]
|
|
copy_default_file("styles.css", css)
|
|
|
|
# Bootstraps the application and creates
|
|
# additional files to be imported by the entry_point file.
|
|
ng_module(
|
|
name = app_lib,
|
|
srcs = ng_srcs,
|
|
assets = ng_assets,
|
|
# Creates ngFactory and ngSummary to be imported by the app's entry point.
|
|
generate_ve_shims = True,
|
|
deps = ng_deps,
|
|
tsconfig = "//dev-infra/benchmark/component_benchmark:tsconfig-e2e.json",
|
|
)
|
|
|
|
# Bundle the application (needed by ts_devserver).
|
|
ng_rollup_bundle(
|
|
name = app_main,
|
|
entry_point = entry_point,
|
|
deps = [":" + app_lib] + entry_point_deps,
|
|
)
|
|
|
|
# The ts_library for the driver that runs tests against the benchmark app.
|
|
ts_library(
|
|
name = benchmark_driver,
|
|
tsconfig = "//dev-infra/benchmark/component_benchmark:tsconfig-e2e.json",
|
|
testonly = True,
|
|
srcs = [driver],
|
|
deps = driver_deps,
|
|
)
|
|
|
|
# The server for our application.
|
|
ts_devserver(
|
|
name = server,
|
|
bootstrap = ["//packages/zone.js/bundles:zone.umd.js"],
|
|
port = 4200,
|
|
static_files = assets + styles,
|
|
deps = [":" + app_main + ".min_debug.js"],
|
|
additional_root_paths = ["//dev-infra/benchmark/component_benchmark/defaults"],
|
|
serving_path = "/app_bundle.js",
|
|
)
|
|
|
|
# Runs a protractor test that's set up to use @angular/benchpress.
|
|
benchmark_test(
|
|
name = name,
|
|
server = ":" + server,
|
|
deps = [":" + benchmark_driver],
|
|
)
|