angular-docs-cn/packages/examples/upgrade/upgrade_example.bzl

70 lines
2.2 KiB
Python
Raw Normal View History

load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_devserver", "ts_library")
"""
Macro that can be used to create the Bazel targets for an "upgrade" example. Since the
upgrade examples bootstrap their application manually, and we cannot serve all examples,
we need to define the devserver for each example. This macro reduces code duplication
for defining these targets.
"""
def create_upgrade_example_targets(name, srcs, e2e_srcs, entry_module, assets = []):
ng_module(
name = "%s_sources" % name,
srcs = srcs,
generate_ve_shims = True,
deps = [
"@npm//@types/angular",
"@npm//@types/jasmine",
"//packages/core",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
"//packages/upgrade/static",
"//packages/core/testing",
"//packages/upgrade/static/testing",
],
tsconfig = "//packages/examples/upgrade:tsconfig-build.json",
)
ts_library(
name = "%s_e2e_lib" % name,
srcs = e2e_srcs,
testonly = True,
deps = [
"@npm//@types/jasminewd2",
"@npm//protractor",
"//packages/examples/test-utils",
"//packages/private/testing",
],
tsconfig = "//packages/examples:tsconfig-e2e.json",
)
ts_devserver(
name = "devserver",
port = 4200,
entry_module = entry_module,
additional_root_paths = ["angular/packages/examples"],
bootstrap = [
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
"//packages/zone.js/bundles:zone.umd.js",
"@npm//:node_modules/angular/angular.js",
"@npm//:node_modules/reflect-metadata/Reflect.js",
],
static_files = [
"//packages/examples:index.html",
] + assets,
scripts = [
"@npm//:node_modules/tslib/tslib.js",
"//tools/rxjs:rxjs_umd_modules",
],
deps = [":%s_sources" % name],
)
protractor_web_test_suite(
name = "%s_protractor" % name,
on_prepare = "//packages/examples/upgrade:start-server.js",
server = ":devserver",
deps = [
":%s_e2e_lib" % name,
"@npm//selenium-webdriver",
],
)