2020-04-24 16:14:28 -04:00
|
|
|
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")
|
2020-03-18 12:01:41 -04:00
|
|
|
|
|
|
|
def copy_default_file(origin, destination):
|
|
|
|
"""
|
2020-05-08 15:56:39 -04:00
|
|
|
Copies a file from ./defaults to the destination.
|
2020-03-18 12:01:41 -04:00
|
|
|
|
|
|
|
Args:
|
2020-05-08 15:56:39 -04:00
|
|
|
origin: The name of a file in ./defaults to be copied.
|
2020-03-18 12:01:41 -04:00
|
|
|
destination: Where the original file will be clopied to.
|
|
|
|
"""
|
|
|
|
native.genrule(
|
|
|
|
name = "copy_default_" + origin + "_file_genrule",
|
2020-04-24 16:14:28 -04:00
|
|
|
srcs = ["//dev-infra/benchmark/component_benchmark/defaults:" + origin],
|
2020-03-18 12:01:41 -04:00
|
|
|
outs = [destination],
|
|
|
|
cmd = "cat $(SRCS) >> $@",
|
|
|
|
)
|
|
|
|
|
|
|
|
def component_benchmark(
|
|
|
|
name,
|
|
|
|
prefix,
|
|
|
|
driver,
|
|
|
|
driver_deps,
|
|
|
|
ng_srcs,
|
|
|
|
ng_deps,
|
|
|
|
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
|
|
|
|
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,
|
|
|
|
# Creates ngFactory and ngSummary to be imported by the app's entry point.
|
|
|
|
generate_ve_shims = True,
|
|
|
|
deps = ng_deps,
|
2020-04-24 16:14:28 -04:00
|
|
|
tsconfig = "//dev-infra/benchmark/component_benchmark:tsconfig-e2e.json",
|
2020-03-18 12:01:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
# 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,
|
2020-04-24 16:14:28 -04:00
|
|
|
tsconfig = "//dev-infra/benchmark/component_benchmark:tsconfig-e2e.json",
|
2020-03-18 12:01:41 -04:00
|
|
|
testonly = True,
|
|
|
|
srcs = [driver],
|
|
|
|
deps = driver_deps,
|
|
|
|
)
|
|
|
|
|
|
|
|
# The server for our application.
|
|
|
|
ts_devserver(
|
|
|
|
name = server,
|
feat(zone.js): upgrade zone.js to angular package format(APF) (#36540)
Close #35157
In the current version of zone.js, zone.js uses it's own package format, and it is not following the rule
of Angualr package format(APF), so it is not easily to be consumed by Angular CLI or other bundle tools.
For example, zone.js npm package has two bundles,
1. zone.js/dist/zone.js, this is a `es5` bundle.
2. zone.js/dist/zone-evergreen.js, this is a `es2015` bundle.
And Angular CLI has to add some hard-coding code to handle this case, ohttps://github.com/angular/angular-cli/blob/5376a8b1392ac7bd252782d8474161ce03a4d1cb/packages/schematics/angular/application/files/src/polyfills.ts.template#L55-L58
This PR upgrade zone.js npm package format to follow APF rule, https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/edit#heading=h.k0mh3o8u5hx
The updated points are:
1. in package.json, update all bundle related properties
```
"main": "./bundles/zone.umd.js",
"module": "./fesm2015/zone.js",
"es2015": "./fesm2015/zone.js",
"fesm2015": "./fesm2015/zone.js",
```
2. re-organize dist folder, for example for `zone.js` bundle, now we have
```
dist/
bundles/
zone.js // this is the es5 bundle
fesm2015/
zone.js // this is the es2015 bundle (in the old version is `zone-evergreen.js`)
```
3. have several sub-packages.
1. `zone-testing`, provide zone-testing bundles include zone.js and testing libraries
2. `zone-node`, provide zone.js implemention for NodeJS
3. `zone-mix`, provide zone.js patches for both Browser and NodeJS
All those sub-packages will have their own `package.json` and the bundle will reference `bundles(es5)` and `fesm2015(es2015)`.
4. keep backward compatibility, still keep the `zone.js/dist` folder, and all bundles will be redirected to `zone.js/bundles` or `zone.js/fesm2015` folders.
PR Close #36540
2020-05-16 21:53:03 -04:00
|
|
|
bootstrap = ["//packages/zone.js/bundles:zone.umd.js"],
|
2020-03-18 12:01:41 -04:00
|
|
|
port = 4200,
|
|
|
|
static_files = assets + styles,
|
2020-06-17 04:37:36 -04:00
|
|
|
deps = [":" + app_main + ".min_debug.js"],
|
2020-04-24 16:14:28 -04:00
|
|
|
additional_root_paths = ["//dev-infra/benchmark/component_benchmark/defaults"],
|
|
|
|
serving_path = "/app_bundle.js",
|
2020-03-18 12:01:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
# Runs a protractor test that's set up to use @angular/benchpress.
|
|
|
|
benchmark_test(
|
|
|
|
name = name,
|
|
|
|
server = ":" + server,
|
|
|
|
deps = [":" + benchmark_driver],
|
|
|
|
)
|