build: `ng_package` no longer generate minified UMDs (#41425)

In version 12, applications will only be allowed to be built in Ivy, this makes the minified UMDs redundant since they cannot be processed by NGCC.

With this change, we remove the minified UMDs from the generated APF package.

BREAKING CHANGE:  Minified UMD bundles are no longer included in the distributed NPM packages.

PR Close #41425
This commit is contained in:
Alan Agius 2021-04-14 18:39:27 +02:00 committed by Zach Arend
parent beafa22de9
commit 5a8bc1bfe1
9 changed files with 11 additions and 300 deletions

View File

@ -21,13 +21,13 @@
},
map: {
app: 'app',
'@angular/core': 'npm:@angular/core/bundles/core.umd.min.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.min.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.min.js',
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser':
'npm:@angular/platform-browser/bundles/platform-browser.umd.min.js',
'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic':
'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.min.js',
'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
'ts': 'npm:plugin-typescript/lib/plugin.js',

View File

@ -1,7 +1,11 @@
package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
# BEGIN-DEV-ONLY
load("@npm//@bazel/typescript:index.bzl", "ts_library")
# END-DEV-ONLY
package(default_visibility = ["//visibility:public"])
nodejs_binary(
name = "rollup_for_ng_package",
data = [
@ -40,12 +44,9 @@ nodejs_binary(
exports_files([
"ng_package.bzl",
"rollup.config.js",
"terser_config.default.json",
])
# BEGIN-DEV-ONLY
load("@npm//@bazel/typescript:index.bzl", "ts_library")
ts_library(
name = "lib",
srcs = glob(["*.ts"]),
@ -61,7 +62,6 @@ filegroup(
srcs = glob(["*.bzl"]) + [
"BUILD.bazel",
"rollup.config.js",
"terser_config.default.json",
],
)

View File

@ -30,14 +30,7 @@ def _debug(vars, *args):
_DEFAULT_NG_PACKAGER = "//@angular/bazel/bin:packager"
_DEFAULT_ROLLUP_CONFIG_TMPL = "//:node_modules/@angular/bazel/src/ng_package/rollup.config.js"
_DEFALUT_TERSER_CONFIG_FILE = "//:node_modules/@angular/bazel/src/ng_package/terser_config.default.json"
_DEFAULT_ROLLUP = "//@angular/bazel/src/ng_package:rollup_for_ng_package"
_DEFAULT_TERSER = (
# BEGIN-DEV-ONLY
"@npm" +
# END-DEV-ONLY
"//terser/bin:terser"
)
_NG_PACKAGE_MODULE_MAPPINGS_ATTR = "ng_package_module_mappings"
@ -136,46 +129,6 @@ WELL_KNOWN_GLOBALS = {p: _global_name(p) for p in [
# TODO(gregmagolan): clean this up
_DEPSET_TYPE = "depset"
def _terser(ctx, input, output):
"""Runs terser on an input file.
Args:
ctx: Bazel rule execution context
input: input file
output: output file
Returns:
The sourcemap file
"""
map_output = ctx.actions.declare_file(output.basename + ".map", sibling = output)
args = ctx.actions.args()
args.add(input.path)
args.add_all(["--output", output.path])
# Source mapping options are comma-packed into one argv
# see https://github.com/terser-js/terser#command-line-usage
source_map_opts = ["includeSources", "base=" + ctx.bin_dir.path]
# This option doesn't work in the config file, only on the CLI
args.add_all(["--source-map", ",".join(source_map_opts)])
args.add("--comments")
args.add_all(["--config-file", ctx.file.terser_config_file.path])
ctx.actions.run(
progress_message = "Optimizing JavaScript %s [terser]" % output.short_path,
executable = ctx.executable.terser,
inputs = [input, ctx.file.terser_config_file],
outputs = [output, map_output],
arguments = [args],
)
return map_output
def _compute_node_modules_root(ctx):
"""Computes the node_modules root from the node_modules and deps attributes.
@ -478,11 +431,9 @@ def _ng_package_impl(ctx):
fesm_output_filename = entry_point.replace("/", "__")
fesm2015_output = ctx.actions.declare_file("fesm2015/%s.js" % fesm_output_filename)
umd_output = ctx.actions.declare_file("%s.umd.js" % umd_output_filename)
min_output = ctx.actions.declare_file("%s.umd.min.js" % umd_output_filename)
else:
fesm2015_output = ctx.outputs.fesm2015
umd_output = ctx.outputs.umd
min_output = ctx.outputs.umd_min
# Also include files from npm fine grained deps as inputs.
# These deps are identified by the NpmPackageInfo provider.
@ -526,13 +477,6 @@ def _ng_package_impl(ctx):
),
)
terser_sourcemap = _terser(
ctx,
umd_output,
min_output,
)
bundles.append(struct(js = min_output, map = terser_sourcemap))
packager_inputs = (
ctx.files.srcs +
ctx.files.data +
@ -715,24 +659,6 @@ _NG_PACKAGE_ATTRS = dict(PKG_NPM_ATTRS, **{
executable = True,
cfg = "host",
),
"terser": attr.label(
executable = True,
cfg = "host",
default = Label(_DEFAULT_TERSER),
),
"terser_config_file": attr.label(
doc = """A JSON file containing Terser minify() options.
This is the file you would pass to the --config-file argument in terser's CLI.
https://github.com/terser-js/terser#minify-options documents the content of the file.
If `config_file` isn't supplied, Bazel will use a default config file.
""",
allow_single_file = True,
# These defaults match how terser was run in the legacy built-in rollup_bundle rule.
# We keep them the same so it's easier for users to migrate.
default = Label(_DEFALUT_TERSER_CONFIG_FILE),
),
"rollup_config_tmpl": attr.label(
default = Label(_DEFAULT_ROLLUP_CONFIG_TMPL),
allow_single_file = True,
@ -794,7 +720,6 @@ def _ng_package_outputs(name, entry_point, entry_point_name):
outputs = {
"fesm2015": "fesm2015/%s.js" % basename,
"umd": "%s.umd.js" % basename,
"umd_min": "%s.umd.min.js" % basename,
}
for key in PKG_NPM_OUTPUTS:
# PKG_NPM_OUTPUTS is a "normal" dict-valued outputs so it looks like

View File

@ -1,12 +0,0 @@
{
"compress": {
"global_defs": {"ngDevMode": false, "ngI18nClosureMode": false},
"keep_fnames": true,
"passes": 3,
"pure_getters": true,
"reduce_funcs": true,
"reduce_vars": true,
"sequences": true
},
"mangle": true
}

View File

@ -40,24 +40,14 @@ describe('@angular/common ng_package', () => {
expect(shx.ls('-R', 'bundles').stdout.split('\n').filter(n => !!n).sort()).toEqual([
'common-http-testing.umd.js',
'common-http-testing.umd.js.map',
'common-http-testing.umd.min.js',
'common-http-testing.umd.min.js.map',
'common-http.umd.js',
'common-http.umd.js.map',
'common-http.umd.min.js',
'common-http.umd.min.js.map',
'common-testing.umd.js',
'common-testing.umd.js.map',
'common-testing.umd.min.js',
'common-testing.umd.min.js.map',
'common-upgrade.umd.js',
'common-upgrade.umd.js.map',
'common-upgrade.umd.min.js',
'common-upgrade.umd.min.js.map',
'common.umd.js',
'common.umd.js.map',
'common.umd.min.js',
'common.umd.min.js.map',
]);
});

View File

@ -137,14 +137,6 @@ describe('@angular/core ng_package', () => {
expect(shx.ls('bundles/core.umd.js.map').length).toBe(1, 'File not found');
});
it('should have a minified umd file in the /bundles directory', () => {
expect(shx.ls('bundles/core.umd.min.js').length).toBe(1, 'File not found');
});
it('should have a source map next to the minified umd file', () => {
expect(shx.ls('bundles/core.umd.min.js.map').length).toBe(1, 'File not found');
});
it('should have the version info in the header', () => {
expect(shx.cat('bundles/core.umd.js'))
.toMatch(/@license Angular v\d+\.\d+\.\d+(?!-PLACEHOLDER)/);
@ -235,14 +227,6 @@ describe('@angular/core ng_package', () => {
expect(shx.ls('bundles/core-testing.umd.js.map').length).toBe(1, 'File not found');
});
it('should have a minified umd file in the /bundles directory', () => {
expect(shx.ls('bundles/core-testing.umd.min.js').length).toBe(1, 'File not found');
});
it('should have a source map next to the minified umd file', () => {
expect(shx.ls('bundles/core-testing.umd.min.js.map').length).toBe(1, 'File not found');
});
it('should have an AMD name', () => {
expect(shx.cat('bundles/core-testing.umd.js'))
.toContain('define(\'@angular/core/testing\'');

View File

@ -11,20 +11,12 @@ arbitrary_genfiles.txt
bundles
bundles/waffels-a11y.umd.js
bundles/waffels-a11y.umd.js.map
bundles/waffels-a11y.umd.min.js
bundles/waffels-a11y.umd.min.js.map
bundles/waffels-imports.umd.js
bundles/waffels-imports.umd.js.map
bundles/waffels-imports.umd.min.js
bundles/waffels-imports.umd.min.js.map
bundles/waffels-secondary.umd.js
bundles/waffels-secondary.umd.js.map
bundles/waffels-secondary.umd.min.js
bundles/waffels-secondary.umd.min.js.map
bundles/waffels.umd.js
bundles/waffels.umd.js.map
bundles/waffels.umd.min.js
bundles/waffels.umd.min.js.map
esm2015
esm2015/a11y
esm2015/a11y/a11y.externs.js
@ -206,30 +198,6 @@ Hello
//# sourceMappingURL=waffels-a11y.umd.js.map
--- bundles/waffels-a11y.umd.min.js ---
/**
* @license Angular v0.0.0
* (c) 2010-2021 Google LLC. https://angular.io/
* License: MIT
*/
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("example/a11y",["exports","@angular/core"],o):o(((e=e||self).example=e.example||{},e.example.a11y={}),e.ng.core)}(this,(function(e,o){"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var t;(t=function t(){}).decorators=[{type:o.NgModule,args:[{}]}],
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
e.A11yModule=t,Object.defineProperty(e,"__esModule",{value:!0})}));
--- bundles/waffels-imports.umd.js ---
/**
@ -303,30 +271,6 @@ e.A11yModule=t,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=waffels-imports.umd.js.map
--- bundles/waffels-imports.umd.min.js ---
/**
* @license Angular v0.0.0
* (c) 2010-2021 Google LLC. https://angular.io/
* License: MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("example/imports",["exports","@angular/core"],t):t(((e=e||self).example=e.example||{},e.example.imports={}),e.ng.core)}(this,(function(e,t){"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var o,r;(o=function o(){}).ɵprov=t.ɵɵdefineInjectable({factory:function e(){return new o},token:o,providedIn:"root"}),o.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],(r=function r(e){this.secondService=e}).ɵprov=t.ɵɵdefineInjectable({factory:function e(){return new r(t.ɵɵinject(o))},token:r,providedIn:"root"}),r.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],r.ctorParameters=function(){return[{type:o}]},
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
e.MyService=r,e.ɵangular_packages_bazel_test_ng_package_example_imports_imports_a=o,Object.defineProperty(e,"__esModule",{value:!0})}));
--- bundles/waffels-secondary.umd.js ---
/**
@ -379,30 +323,6 @@ e.MyService=r,e.ɵangular_packages_bazel_test_ng_package_example_imports_imports
//# sourceMappingURL=waffels-secondary.umd.js.map
--- bundles/waffels-secondary.umd.min.js ---
/**
* @license Angular v0.0.0
* (c) 2010-2021 Google LLC. https://angular.io/
* License: MIT
*/
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("example/secondary",["exports","@angular/core"],o):o(((e=e||self).example=e.example||{},e.example.secondary={}),e.ng.core)}(this,(function(e,o){"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var n;(n=function n(){}).decorators=[{type:o.NgModule,args:[{}]}],
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
e.SecondaryModule=n,e.a=1,Object.defineProperty(e,"__esModule",{value:!0})}));
--- bundles/waffels.umd.js ---
/**
@ -453,30 +373,6 @@ e.SecondaryModule=n,e.a=1,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=waffels.umd.js.map
--- bundles/waffels.umd.min.js ---
/**
* @license Angular v0.0.0
* (c) 2010-2021 Google LLC. https://angular.io/
* License: MIT
*/
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("example",["exports","@angular/core"],o):o((e=e||self).example={},e.ng.core)}(this,(function(e,o){"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var t;(t=function t(){}).decorators=[{type:o.NgModule,args:[{}]}],
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
e.MyModule=t,Object.defineProperty(e,"__esModule",{value:!0})}));
--- esm2015/a11y/a11y.externs.js ---
/** @externs */

View File

@ -2,16 +2,10 @@ README.md
bundles
bundles/example-with-ts-library-portal.umd.js
bundles/example-with-ts-library-portal.umd.js.map
bundles/example-with-ts-library-portal.umd.min.js
bundles/example-with-ts-library-portal.umd.min.js.map
bundles/example-with-ts-library-utils.umd.js
bundles/example-with-ts-library-utils.umd.js.map
bundles/example-with-ts-library-utils.umd.min.js
bundles/example-with-ts-library-utils.umd.min.js.map
bundles/example-with-ts-library.umd.js
bundles/example-with-ts-library.umd.js.map
bundles/example-with-ts-library.umd.min.js
bundles/example-with-ts-library.umd.min.js.map
esm2015
esm2015/example.externs.js
esm2015/index.js
@ -110,30 +104,6 @@ License: MIT
//# sourceMappingURL=example-with-ts-library-portal.umd.js.map
--- bundles/example-with-ts-library-portal.umd.min.js ---
/**
* @license Angular v0.0.0
* (c) 2010-2021 Google LLC. https://angular.io/
* License: MIT
*/
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("example-with-ts-library/portal",["exports","@angular/core"],r):r(((e=e||self).exampleWithTsLibrary=e.exampleWithTsLibrary||{},e.exampleWithTsLibrary.portal={}),e.ng.core)}(this,(function(e,r){"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var t;(t=function t(){}).decorators=[{type:r.NgModule,args:[{}]}],
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
e.PortalModule=t,e.a=1,Object.defineProperty(e,"__esModule",{value:!0})}));
--- bundles/example-with-ts-library-utils.umd.js ---
/**
@ -175,30 +145,6 @@ e.PortalModule=t,e.a=1,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=example-with-ts-library-utils.umd.js.map
--- bundles/example-with-ts-library-utils.umd.min.js ---
/**
* @license Angular v0.0.0
* (c) 2010-2021 Google LLC. https://angular.io/
* License: MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("example-with-ts-library/utils",["exports"],t):t(((e=e||self).exampleWithTsLibrary=e.exampleWithTsLibrary||{},e.exampleWithTsLibrary.utils={}))}(this,(function(e){"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
e.dispatchFakeEvent=function t(e,i){e.dispatchEvent(i)},Object.defineProperty(e,"__esModule",{value:!0})}));
--- bundles/example-with-ts-library.umd.js ---
/**
@ -230,22 +176,6 @@ e.dispatchFakeEvent=function t(e,i){e.dispatchEvent(i)},Object.defineProperty(e,
//# sourceMappingURL=example-with-ts-library.umd.js.map
--- bundles/example-with-ts-library.umd.min.js ---
/**
* @license Angular v0.0.0
* (c) 2010-2021 Google LLC. https://angular.io/
* License: MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("example-with-ts-library",["exports"],t):t((e=e||self).exampleWithTsLibrary={})}(this,(function(e){"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/e.VERSION="0.0.0",Object.defineProperty(e,"__esModule",{value:!0})}));
--- esm2015/example.externs.js ---

View File

@ -19,7 +19,6 @@ _INTERNAL_NG_MODULE_API_EXTRACTOR = "//packages/bazel/src/api-extractor:api_extr
_INTERNAL_NG_MODULE_COMPILER = "//packages/bazel/src/ngc-wrapped"
_INTERNAL_NG_MODULE_XI18N = "//packages/bazel/src/ngc-wrapped:xi18n"
_INTERNAL_NG_PACKAGE_PACKAGER = "//packages/bazel/src/ng_package:packager"
_INTERNAL_NG_PACKAGE_DEFALUT_TERSER_CONFIG_FILE = "//packages/bazel/src/ng_package:terser_config.default.json"
_INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP_CONFIG_TMPL = "//packages/bazel/src/ng_package:rollup.config.js"
_INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP = "//packages/bazel/src/ng_package:rollup_for_ng_package"
@ -189,7 +188,6 @@ def ng_package(name, readme_md = None, license_banner = None, deps = [], **kwarg
"//conditions:default": substitutions,
}),
ng_packager = _INTERNAL_NG_PACKAGE_PACKAGER,
terser_config_file = _INTERNAL_NG_PACKAGE_DEFALUT_TERSER_CONFIG_FILE,
rollup_config_tmpl = _INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP_CONFIG_TMPL,
rollup = _INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP,
visibility = visibility,