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
|
|
|
"""Provides the rollup and dist file generation macro."""
|
|
|
|
|
|
|
|
load("//tools:defaults.bzl", "rollup_bundle")
|
|
|
|
|
|
|
|
def zone_rollup_bundle(module_name, entry_point, rollup_config):
|
refactor(zone.js): refactor zone rollup config (#40481)
When migrating zone.js from gulp to bazel, some legacy build config files are still there,
we have `rollup-es5.config.js` and `rollup-es5_global-es2015.config.js`, since in gulp build
system, build `es5` or `esm` files are set in the config file, but in the bazel world,
the output format is not config in the config.js file, but is required by the downstream
bazel target. So we don't really need the two rollup config files any longer.
Another difference is in `rollup-es5.config.js`, the `external` and `global` libraries names
are also config there, and these settings are also valid for `es2015` build, these settings
are not in the `es2015.config.js` for some legacy reasons. So we don't need to keep this
difference either.
PR Close #40481
2021-01-19 07:33:03 -05:00
|
|
|
config_file = "//packages/zone.js:rollup.config.js"
|
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
|
|
|
rollup_bundle(
|
|
|
|
name = module_name + "-rollup",
|
|
|
|
config_file = config_file,
|
|
|
|
entry_point = entry_point + ".ts",
|
|
|
|
silent = True,
|
|
|
|
sourcemap = "false",
|
|
|
|
deps = [
|
|
|
|
"//packages/zone.js/lib",
|
|
|
|
"@npm//rollup-plugin-commonjs",
|
|
|
|
"@npm//rollup-plugin-node-resolve",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
def copy_dist(module_name, module_format, output_module_name, suffix, umd):
|
|
|
|
umd_output = umd
|
|
|
|
suffix_output = suffix
|
|
|
|
if umd == "umd":
|
|
|
|
umd_output = "umd."
|
|
|
|
if suffix == "min":
|
|
|
|
suffix_output = "min."
|
|
|
|
native.genrule(
|
|
|
|
name = module_name + "." + suffix_output + "dist",
|
|
|
|
srcs = [
|
2020-10-09 15:06:24 -04:00
|
|
|
"//packages/zone.js:" + module_name + "-rollup." + suffix_output + module_format,
|
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
|
|
|
],
|
|
|
|
outs = [
|
|
|
|
output_module_name + "." + umd_output + suffix_output + "js",
|
|
|
|
],
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
cmd = "cp $< $@",
|
|
|
|
)
|
|
|
|
|
|
|
|
def generate_rollup_bundle(bundles):
|
|
|
|
for b in bundles.items():
|
|
|
|
module_name = b[0]
|
|
|
|
rollup_config = b[1]
|
|
|
|
if rollup_config.get("entrypoint") != None:
|
|
|
|
entry_point = rollup_config.get("entrypoint")
|
|
|
|
zone_rollup_bundle(
|
|
|
|
module_name = module_name + "-es5",
|
|
|
|
rollup_config = rollup_config,
|
|
|
|
entry_point = entry_point,
|
|
|
|
)
|
|
|
|
zone_rollup_bundle(
|
|
|
|
module_name = module_name + "-es2015",
|
|
|
|
rollup_config = rollup_config,
|
|
|
|
entry_point = entry_point,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
zone_rollup_bundle(
|
|
|
|
module_name = module_name + "-es5",
|
|
|
|
rollup_config = rollup_config,
|
|
|
|
entry_point = rollup_config.get("es5"),
|
|
|
|
)
|
|
|
|
zone_rollup_bundle(
|
|
|
|
module_name = module_name + "-es2015",
|
|
|
|
rollup_config = rollup_config,
|
|
|
|
entry_point = rollup_config.get("es2015"),
|
|
|
|
)
|
|
|
|
|
|
|
|
def generate_dist(bundles, output_format, umd):
|
2020-10-09 15:06:24 -04:00
|
|
|
module_format = "esm.js"
|
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
|
|
|
if output_format == "es5":
|
2020-10-09 15:06:24 -04:00
|
|
|
module_format = "es5umd.js"
|
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
|
|
|
for b in bundles:
|
|
|
|
module_name = b[0]
|
|
|
|
copy_dist(
|
|
|
|
module_name = module_name + "-" + output_format,
|
|
|
|
module_format = module_format,
|
|
|
|
output_module_name = module_name,
|
|
|
|
suffix = "",
|
|
|
|
umd = umd,
|
|
|
|
)
|
|
|
|
copy_dist(
|
|
|
|
module_name = module_name + "-" + output_format,
|
|
|
|
module_format = module_format,
|
|
|
|
output_module_name = module_name,
|
|
|
|
suffix = "min.",
|
|
|
|
umd = umd,
|
|
|
|
)
|