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
This commit is contained in:
JiaLiPassion 2021-01-19 20:33:03 +08:00 committed by Jessica Janiuk
parent 21bc16d4d8
commit 1f53301fd3
6 changed files with 4 additions and 83 deletions

View File

@ -6,8 +6,7 @@ package(default_visibility = ["//visibility:public"])
exports_files([
"tsconfig.json",
"rollup-es5.config.js",
"rollup-es5_global-es2015.config.js",
"rollup.config.js",
])
genrule(

View File

@ -9,139 +9,105 @@ BUNDLES_ENTRY_POINTS = {
"zone": {
"es5": _DIR + "browser/rollup-legacy-main",
"es2015": _DIR + "browser/rollup-main",
"rollup": "global-es2015",
},
"zone-mix": {
"entrypoint": _DIR + "mix/rollup-mix",
"rollup": "global-es2015",
},
"zone-node": {
"entrypoint": _DIR + "node/rollup-main",
"rollup": "global-es2015",
},
"async-test": {
"entrypoint": _DIR + "testing/async-testing",
"rollup": "es5",
},
"fake-async-test": {
"entrypoint": _DIR + "testing/fake-async",
"rollup": "es5",
},
"long-stack-trace-zone": {
"entrypoint": _DIR + "zone-spec/long-stack-trace",
"rollup": "es5",
},
"proxy": {
"entrypoint": _DIR + "zone-spec/proxy",
"rollup": "es5",
},
"zone-patch-rxjs-fake-async": {
"entrypoint": _DIR + "zone-spec/proxy",
"rollup": "es5",
},
"sync-test": {
"entrypoint": _DIR + "zone-spec/sync-test",
"rollup": "es5",
},
"task-tracking": {
"entrypoint": _DIR + "zone-spec/task-tracking",
"rollup": "es5",
},
"wtf": {
"entrypoint": _DIR + "zone-spec/wtf",
"rollup": "es5",
},
"zone-error": {
"entrypoint": _DIR + "common/error-rewrite",
"rollup": "es5",
},
"zone-legacy": {
"entrypoint": _DIR + "browser/browser-legacy",
"rollup": "es5",
},
"zone-bluebird": {
"entrypoint": _DIR + "extra/bluebird",
"rollup": "es5",
},
"zone-patch-canvas": {
"entrypoint": _DIR + "browser/canvas",
"rollup": "es5",
},
"zone-patch-cordova": {
"entrypoint": _DIR + "extra/cordova",
"rollup": "es5",
},
"zone-patch-electron": {
"entrypoint": _DIR + "extra/electron",
"rollup": "es5",
},
"zone-patch-fetch": {
"entrypoint": _DIR + "common/fetch",
"rollup": "es5",
},
"jasmine-patch": {
"entrypoint": _DIR + "jasmine/jasmine",
"rollup": "es5",
},
"zone-patch-jsonp": {
"entrypoint": _DIR + "extra/jsonp",
"rollup": "es5",
},
"webapis-media-query": {
"entrypoint": _DIR + "browser/webapis-media-query",
"rollup": "es5",
},
"mocha-patch": {
"entrypoint": _DIR + "mocha/mocha",
"rollup": "es5",
},
"webapis-notification": {
"entrypoint": _DIR + "browser/webapis-notification",
"rollup": "es5",
},
"zone-patch-promise-test": {
"entrypoint": _DIR + "testing/promise-testing",
"rollup": "es5",
},
"zone-patch-resize-observer": {
"entrypoint": _DIR + "browser/webapis-resize-observer",
"rollup": "es5",
},
"webapis-rtc-peer-connection": {
"entrypoint": _DIR + "browser/webapis-rtc-peer-connection",
"rollup": "es5",
},
"zone-patch-rxjs": {
"entrypoint": _DIR + "rxjs/rxjs",
"rollup": "es5",
},
"webapis-shadydom": {
"entrypoint": _DIR + "browser/shadydom",
"rollup": "es5",
},
"zone-patch-socket-io": {
"entrypoint": _DIR + "extra/socket-io",
"rollup": "es5",
},
"zone-patch-message-port": {
"entrypoint": _DIR + "browser/message-port",
"rollup": "es5",
},
"zone-patch-user-media": {
"entrypoint": _DIR + "browser/webapis-user-media",
"rollup": "es5",
},
"zone-testing": {
"entrypoint": _DIR + "testing/zone-testing",
"rollup": "es5",
},
"zone-testing-bundle": {
"es5": _DIR + "browser/rollup-legacy-test-main",
"es2015": _DIR + "browser/rollup-test-main",
"rollup": "global-es2015",
},
"zone-testing-node-bundle": {
"entrypoint": _DIR + "node/rollup-test-main",
"rollup": "global-es2015",
},
}

View File

@ -1,40 +0,0 @@
const node = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
// Parse the stamp file produced by Bazel from the version control system
let version = '<unknown>';
if (bazel_stamp_file) {
const versionTag = require('fs')
.readFileSync(bazel_stamp_file, {encoding: 'utf-8'})
.split('\n')
.find(s => s.startsWith('BUILD_SCM_VERSION'));
// Don't assume BUILD_SCM_VERSION exists
if (versionTag) {
version = versionTag.split(' ')[1].trim();
}
}
// Add 'use strict' to the bundle, https://github.com/angular/angular/pull/40456
// When rollup build esm bundle of zone.js, there will be no 'use strict'
// since all esm bundles are `strict`, but when webpack load the esm bundle,
// because zone.js is a module without export and import, webpack is unable
// to determine the bundle is `esm` module or not, so it doesn't add the 'use strict'
// which webpack does to all other `esm` modules which has export or import.
// And it causes issues such as https://github.com/angular/angular/issues/40215
// `this` should be `undefined` but is assigned with `Window` instead.
const banner = `'use strict';
/**
* @license Angular v${version}
* (c) 2010-2020 Google LLC. https://angular.io/
* License: MIT
*/`;
module.exports = {
plugins: [
node({
mainFields: ['es2015', 'module', 'jsnext:main', 'main'],
}),
commonjs(),
],
output: {name: 'Zone', banner},
}

View File

@ -32,7 +32,7 @@ def karma_test_prepare(name, env_srcs, env_deps, env_entry_point, test_srcs, tes
silent = True,
sourcemap = "false",
entry_point = test_entry_point,
config_file = "//packages/zone.js:rollup-es5.config.js",
config_file = "//packages/zone.js:rollup.config.js",
deps = [
":" + name + "_test",
"@npm//rollup-plugin-commonjs",

View File

@ -3,11 +3,7 @@
load("//tools:defaults.bzl", "rollup_bundle")
def zone_rollup_bundle(module_name, entry_point, rollup_config):
config_file = ""
if rollup_config["rollup"] == "global-es2015":
config_file = "//packages/zone.js:rollup-es5_global-es2015.config.js"
if rollup_config["rollup"] == "es5":
config_file = "//packages/zone.js:rollup-es5.config.js"
config_file = "//packages/zone.js:rollup.config.js"
rollup_bundle(
name = module_name + "-rollup",
config_file = config_file,