diff --git a/package.json b/package.json index 0a91cc6550..2f2a1fe07a 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "@bazel/jasmine": "0.40.0", "@bazel/karma": "0.40.0", "@bazel/protractor": "0.40.0", + "@bazel/rollup": "0.40.0", "@bazel/terser": "0.40.0", "@bazel/typescript": "0.40.0", "@microsoft/api-extractor": "^7.3.9", diff --git a/packages/zone.js/BUILD.bazel b/packages/zone.js/BUILD.bazel index 2e59149a38..f683bc1480 100644 --- a/packages/zone.js/BUILD.bazel +++ b/packages/zone.js/BUILD.bazel @@ -3,6 +3,8 @@ load("//packages/zone.js:bundles.bzl", "ES2015_BUNDLES", "ES5_BUNDLES", "ES5_GLO exports_files([ "tsconfig.json", + "rollup-es5.config.js", + "rollup-es5_global-es2015.config.js", ]) genrule( diff --git a/packages/zone.js/dist/BUILD.bazel b/packages/zone.js/dist/BUILD.bazel index df4075e319..41f5811016 100644 --- a/packages/zone.js/dist/BUILD.bazel +++ b/packages/zone.js/dist/BUILD.bazel @@ -21,13 +21,12 @@ genrule( [ rollup_bundle( name = b[0].replace("-", "_") + "_rollup", + config_file = "//packages/zone.js:rollup-es5.config.js", entry_point = b[1] + ".ts", - globals = { - "electron": "electron", - }, - license_banner = "//packages:license-banner.txt", deps = [ "//packages/zone.js/lib", + "@npm//rollup-plugin-commonjs", + "@npm//rollup-plugin-node-resolve", ], ) for b in ES5_BUNDLES.items() @@ -36,63 +35,24 @@ genrule( [ rollup_bundle( name = b[0].replace("-", "_") + "_rollup", + config_file = "//packages/zone.js:rollup-es5_global-es2015.config.js", entry_point = b[1] + ".ts", - global_name = "Zone", - license_banner = "//packages:license-banner.txt", deps = [ "//packages/zone.js/lib", + "@npm//rollup-plugin-commonjs", + "@npm//rollup-plugin-node-resolve", ], ) for b in ES5_GLOBAL_BUNDLES.items() + ES2015_BUNDLES.items() ] -# the es5 filegroups -[ - filegroup( - name = b[0] + ".es5", - srcs = [":" + b[0].replace("-", "_") + "_rollup"], - output_group = "es5_umd", - ) - for b in ES5_BUNDLES.items() + ES5_GLOBAL_BUNDLES.items() -] - -# the es5.min filegroups -[ - filegroup( - name = b[0] + ".es5.min", - srcs = [":" + b[0].replace("-", "_") + "_rollup"], - output_group = "es5_umd_min", - ) - for b in ES5_BUNDLES.items() + ES5_GLOBAL_BUNDLES.items() -] - -# the es2015 filegroups -[ - filegroup( - name = b[0] + ".umd", - srcs = [":" + b[0].replace("-", "_") + "_rollup"], - output_group = "umd", - ) - for b in ES2015_BUNDLES.items() -] - -# the es2015.min filegroups -[ - filegroup( - name = b[0] + ".umd.min", - srcs = [":" + b[0].replace("-", "_") + "_rollup"], - output_group = "umd_min", - ) - for b in ES2015_BUNDLES.items() -] - # Extract and rename each es5 bundle to a .js and .min.js in the dist/ dir [ genrule( name = b[0] + "-dist", srcs = [ - b[0] + ".es5", - b[0] + ".es5.min", + b[0].replace("-", "_") + "_rollup.es5umd.js", + b[0].replace("-", "_") + "_rollup.min.es5umd.js", ], outs = [ b[0] + ".js", @@ -114,7 +74,7 @@ genrule( genrule( name = b[0] + "-dist-dev-test", srcs = [ - b[0] + ".es5", + b[0].replace("-", "_") + "_rollup.es5umd.js", ], outs = [ b[0] + ".dev.test.js", @@ -131,7 +91,7 @@ genrule( genrule( name = b + "-dist-dev-test", srcs = [ - b + ".umd", + b.replace("-", "_") + "_rollup.umd.js", ], outs = [ b + ".dev.test.js", @@ -149,7 +109,7 @@ genrule( genrule( name = b[0] + "-dist-test", srcs = [ - b[0] + ".es5.min", + b[0].replace("-", "_") + "_rollup.min.es5umd.js", ], outs = [ b[0] + ".test.min.js", @@ -167,8 +127,8 @@ genrule( genrule( name = b + "-dist", srcs = [ - b + ".umd", - b + ".umd.min", + b.replace("-", "_") + "_rollup.umd.js", + b.replace("-", "_") + "_rollup.min.umd.js", ], outs = [ b + ".js", @@ -190,7 +150,7 @@ genrule( genrule( name = b + "-dist-test", srcs = [ - b + ".umd.min", + b.replace("-", "_") + "_rollup.min.umd.js", ], outs = [ b + ".test.min.js", diff --git a/packages/zone.js/rollup-es5.config.js b/packages/zone.js/rollup-es5.config.js new file mode 100644 index 0000000000..0e39016fcd --- /dev/null +++ b/packages/zone.js/rollup-es5.config.js @@ -0,0 +1,19 @@ +const node = require('rollup-plugin-node-resolve'); +const commonjs = require('rollup-plugin-commonjs'); + +const banner = `/** +* @license Angular v0.0.0-PLACEHOLDER +* (c) 2010-2019 Google LLC. https://angular.io/ +* License: MIT +*/`; + +module.exports = { + plugins: [ + node({ + mainFields: ['es2015', 'module', 'jsnext:main', 'main'], + }), + commonjs(), + ], + external: ['electron'], + output: {globals: {electron: 'electron'}, banner}, +} diff --git a/packages/zone.js/rollup-es5_global-es2015.config.js b/packages/zone.js/rollup-es5_global-es2015.config.js new file mode 100644 index 0000000000..60c76e18df --- /dev/null +++ b/packages/zone.js/rollup-es5_global-es2015.config.js @@ -0,0 +1,18 @@ +const node = require('rollup-plugin-node-resolve'); +const commonjs = require('rollup-plugin-commonjs'); + +const banner = `/** +* @license Angular v0.0.0-PLACEHOLDER +* (c) 2010-2019 Google LLC. https://angular.io/ +* License: MIT +*/`; + +module.exports = { + plugins: [ + node({ + mainFields: ['es2015', 'module', 'jsnext:main', 'main'], + }), + commonjs(), + ], + output: {name: 'Zone', banner}, +} diff --git a/packages/zone.js/test/karma_test.bzl b/packages/zone.js/test/karma_test.bzl index 81ed5e01f5..49a451f425 100644 --- a/packages/zone.js/test/karma_test.bzl +++ b/packages/zone.js/test/karma_test.bzl @@ -14,19 +14,15 @@ def karma_test_prepare(name, env_srcs, env_deps, env_entry_point, test_srcs, tes entry_point = env_entry_point, deps = [ ":" + name + "_env", + "@npm//rollup-plugin-commonjs", + "@npm//rollup-plugin-node-resolve", ], ) - native.filegroup( - name = name + "_env_rollup.es5", - testonly = True, - srcs = [":" + name + "_env_rollup"], - output_group = "umd", - ) native.genrule( name = name + "_env_trim_map", testonly = True, srcs = [ - ":" + name + "_env_rollup.es5", + ":" + name + "_env_rollup.umd", ], outs = [ name + "_env_rollup_trim_map.js", @@ -45,24 +41,18 @@ def karma_test_prepare(name, env_srcs, env_deps, env_entry_point, test_srcs, tes name = name + "_rollup", testonly = True, entry_point = test_entry_point, - globals = { - "electron": "electron", - }, + config_file = "//packages/zone.js:rollup-es5.config.js", deps = [ ":" + name + "_test", + "@npm//rollup-plugin-commonjs", + "@npm//rollup-plugin-node-resolve", ], ) - native.filegroup( - name = name + "_rollup.es5", - testonly = True, - srcs = [":" + name + "_rollup"], - output_group = "umd", - ) native.genrule( name = name + "_trim_map", testonly = True, srcs = [ - ":" + name + "_rollup.es5", + ":" + name + "_rollup.umd", ], outs = [ name + "_rollup_trim_map.js", diff --git a/tools/defaults.bzl b/tools/defaults.bzl index d149cbb010..8837855963 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -1,6 +1,6 @@ """Re-export of some bazel rules with repository-wide defaults.""" -load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _npm_package = "npm_package", _rollup_bundle = "rollup_bundle") +load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _npm_package = "npm_package") load("@npm_bazel_jasmine//:index.bzl", _jasmine_node_test = "jasmine_node_test") load("@npm_bazel_karma//:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite") load("@npm_bazel_typescript//:index.bzl", _ts_library = "ts_library") @@ -8,6 +8,9 @@ load("@npm_bazel_protractor//:index.bzl", _protractor_web_test_suite = "protract load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package") load("//tools/ng_rollup_bundle:ng_rollup_bundle.bzl", _ng_rollup_bundle = "ng_rollup_bundle") load("//tools:ng_benchmark.bzl", _ng_benchmark = "ng_benchmark") +load("@npm_bazel_rollup//:index.bzl", _rollup_bundle = "rollup_bundle") +load("@npm_bazel_terser//:index.bzl", "terser_minified") +load("@npm//typescript:index.bzl", "tsc") _DEFAULT_TSCONFIG_TEST = "//packages:tsconfig-test" _INTERNAL_NG_MODULE_API_EXTRACTOR = "//packages/bazel/src/api-extractor:api_extractor" @@ -263,11 +266,97 @@ def ng_rollup_bundle(deps = [], **kwargs): **kwargs ) -def rollup_bundle(**kwargs): - """Default values for rollup_bundle""" - _rollup_bundle( - # code-splitting is turned on by default in nodejs rules 0.35.0 - # we want to default to remain off - enable_code_splitting = False, - **kwargs +def rollup_bundle(name, testonly = False, **kwargs): + """A drop in replacement for the rules nodejs [legacy rollup_bundle]. + + Runs [rollup_bundle], [terser_minified] and [babel] for downleveling to es5 + to produce a number of output bundles. + + es2015 iife : "%{name}.es2015.js" + es2015 iife minified : "%{name}.min.es2015.js" + es2015 iife minified (debug) : "%{name}.min_debug.es2015.js" + es5 iife : "%{name}.js" + es5 iife minified : "%{name}.min.js" + es5 iife minified (debug) : "%{name}.min_debug.js" + es5 umd : "%{name}.es5umd.js" + es5 umd minified : "%{name}.min.es5umd.js" + es2015 umd : "%{name}.umd.js" + es2015 umd minified : "%{name}.min.umd.js" + + ".js.map" files are also produced for each bundle. + + [legacy rollup_bundle]: https://github.com/bazelbuild/rules_nodejs/blob/0.38.3/internal/rollup/rollup_bundle.bzl + [rollup_bundle]: https://bazelbuild.github.io/rules_nodejs/Rollup.html + [terser_minified]: https://bazelbuild.github.io/rules_nodejs/Terser.html + [babel]: https://babeljs.io/ + """ + + # Common arguments for all terser_minified targets + common_terser_args = { + "args": ["--comments"], + "sourcemap": False, + } + + # es2015 + _rollup_bundle(name = name + ".es2015", testonly = testonly, format = "iife", sourcemap = "true", **kwargs) + terser_minified(name = name + ".min.es2015", testonly = testonly, src = name + ".es2015", **common_terser_args) + native.filegroup(name = name + ".min.es2015.js", testonly = testonly, srcs = [name + ".min.es2015"]) + terser_minified(name = name + ".min_debug.es2015", testonly = testonly, src = name + ".es2015", **common_terser_args) + native.filegroup(name = name + ".min_debug.es2015.js", testonly = testonly, srcs = [name + ".min_debug.es2015"]) + + # es5 + tsc( + name = name, + testonly = testonly, + outs = [ + name + ".js", + ], + args = [ + "$(location :%s.es2015.js)" % name, + "--types", + "--skipLibCheck", + "--target", + "es5", + "--lib", + "es2015,dom", + "--allowJS", + "--outFile", + "$(location :%s.js)" % name, + ], + data = [ + name + ".es2015.js", + ], ) + terser_minified(name = name + ".min", testonly = testonly, src = name + "", **common_terser_args) + native.filegroup(name = name + ".min.js", testonly = testonly, srcs = [name + ".min"]) + terser_minified(name = name + ".min_debug", testonly = testonly, src = name + "", debug = True, **common_terser_args) + native.filegroup(name = name + ".min_debug.js", testonly = testonly, srcs = [name + ".min_debug"]) + + # umd + _rollup_bundle(name = name + ".umd", testonly = testonly, format = "umd", sourcemap = "true", **kwargs) + terser_minified(name = name + ".min.umd", testonly = testonly, src = name + ".umd", **common_terser_args) + native.filegroup(name = name + ".min.umd.js", testonly = testonly, srcs = [name + ".min.umd"]) + tsc( + name = name + ".es5umd", + testonly = testonly, + outs = [ + name + ".es5umd.js", + ], + args = [ + "$(location :%s.umd.js)" % name, + "--types", + "--skipLibCheck", + "--target", + "es5", + "--lib", + "es2015,dom", + "--allowJS", + "--outFile", + "$(location :%s.es5umd.js)" % name, + ], + data = [ + name + ".umd.js", + ], + ) + terser_minified(name = name + ".min.es5umd", testonly = testonly, src = name + ".es5umd", **common_terser_args) + native.filegroup(name = name + ".min.es5umd.js", testonly = testonly, srcs = [name + ".min.es5umd"]) diff --git a/yarn.lock b/yarn.lock index fff0cd27ab..fc27392e51 100644 --- a/yarn.lock +++ b/yarn.lock @@ -315,6 +315,11 @@ dependencies: protractor "^5.4.2" +"@bazel/rollup@0.40.0": + version "0.40.0" + resolved "https://registry.yarnpkg.com/@bazel/rollup/-/rollup-0.40.0.tgz#8ee08e1967c1ff7d549ce81b676872fa7e45afdb" + integrity sha512-7ZKzOIfHm0lEc3G/o2ykCZQlc7xcKSHiwIV4GIeaYJIbFUnO/L0cmaWzxOhdlr7NFfTdXcltTFnCrG7wlaad9A== + "@bazel/terser@0.40.0": version "0.40.0" resolved "https://registry.yarnpkg.com/@bazel/terser/-/terser-0.40.0.tgz#e31c76c32055a6bdffc711b05b530ae8df7ed1d5"