fix(bazel): ng_package rule creates incorrect UMD module exports (#35792)

The `ng_package` rule currently creates incorrect UMD module exports
if an entry-point has a module name with numbers included.

For example, consider an entry-point called `@angular/cdk/a11y`. The UMD
module name should be `ng.cdk.a11y`. Instead, `ng_package` currently generates
an UMD module export called `ng.cdk.a11Y`.

This is because the logic for converting dash-case to camel case is
invalid as it uses Starlark's `title()` method. The title method
converts text to title case while we actually just want to capitalize
the first letter of a dash-case segment.

Fixes angular/components#18652.

PR Close #35792
This commit is contained in:
Paul Gschwendtner 2020-03-02 11:28:18 +01:00 committed by atscott
parent d4fa9744e4
commit 5c2a90814b
2 changed files with 7 additions and 7 deletions

View File

@ -77,7 +77,7 @@ def _convert_dash_case_to_camel_case(s):
parts = s.split("-") parts = s.split("-")
# First letter in the result is always unchanged # First letter in the result is always unchanged
return s[0] + "".join([p.title() for p in parts])[1:] return s[0] + "".join([p.capitalize() for p in parts])[1:]
# Convert from a package name on npm to an identifier that's a legal global symbol # Convert from a package name on npm to an identifier that's a legal global symbol
# @angular/core -> ng.core # @angular/core -> ng.core
@ -640,7 +640,7 @@ _NG_PACKAGE_ATTRS = dict(PKG_NPM_ATTRS, **{
"entry_point": attr.label( "entry_point": attr.label(
doc = """The starting point of the application, passed as the `--input` flag to rollup. doc = """The starting point of the application, passed as the `--input` flag to rollup.
If the entry JavaScript file belongs to the same package (as the BUILD file), If the entry JavaScript file belongs to the same package (as the BUILD file),
you can simply reference it by its relative name to the package directory: you can simply reference it by its relative name to the package directory:
``` ```
@ -668,7 +668,7 @@ _NG_PACKAGE_ATTRS = dict(PKG_NPM_ATTRS, **{
The rule will use the corresponding `.js` output of the ts_library rule as the entry point. The rule will use the corresponding `.js` output of the ts_library rule as the entry point.
If the entry point target is a rule, it should produce a single JavaScript entry file that will be passed to the nodejs_binary rule. If the entry point target is a rule, it should produce a single JavaScript entry file that will be passed to the nodejs_binary rule.
For example: For example:
``` ```

View File

@ -170,7 +170,7 @@ Hello
(function (global, factory) { (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) :
typeof define === 'function' && define.amd ? define('example/a11y', ['exports', '@angular/core'], factory) : typeof define === 'function' && define.amd ? define('example/a11y', ['exports', '@angular/core'], factory) :
(global = global || self, factory((global.example = global.example || {}, global.example.a11Y = {}), global.ng.core)); (global = global || self, factory((global.example = global.example || {}, global.example.a11y = {}), global.ng.core));
}(this, (function (exports, core) { 'use strict'; }(this, (function (exports, core) { 'use strict';
/*! ***************************************************************************** /*! *****************************************************************************
@ -413,7 +413,7 @@ Hello
* (c) 2010-2020 Google LLC. https://angular.io/ * (c) 2010-2020 Google LLC. https://angular.io/
* License: MIT * License: MIT
*/ */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("example/a11y",["exports","@angular/core"],t):t(((e=e||self).example=e.example||{},e.example.a11Y={}),e.ng.core)}(this,(function(e,t){"use strict"; !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("example/a11y",["exports","@angular/core"],t):t(((e=e||self).example=e.example||{},e.example.a11y={}),e.ng.core)}(this,(function(e,t){"use strict";
/*! ***************************************************************************** /*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved. Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@ -1072,7 +1072,7 @@ export class A11yModule {
A11yModule.decorators = [ A11yModule.decorators = [
{ type: NgModule, args: [{},] } { type: NgModule, args: [{},] }
]; ];
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2V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2VzQ29udGVudCI6WyIvKipcbiAqIEBsaWNlbnNlXG4gKiBDb3B5cmlnaHQgR29vZ2xlIEluYy4gQWxsIFJpZ2h0cyBSZXNlcnZlZC5cbiAqXG4gKiBVc2Ugb2YgdGhpcyBzb3VyY2UgY29kZSBpcyBnb3Zlcm5lZCBieSBhbiBNSVQtc3R5bGUgbGljZW5zZSB0aGF0IGNhbiBiZVxuICogZm91bmQgaW4gdGhlIExJQ0VOU0UgZmlsZSBhdCBodHRwczovL2FuZ3VsYXIuaW8vbGljZW5zZVxuICovXG5cbmltcG9ydCB7TmdNb2R1bGV9IGZyb20gJ0Bhbmd1bGFyL2NvcmUnO1xuXG5ATmdNb2R1bGUoe30pXG5leHBvcnQgY2xhc3MgQTExeU1vZHVsZSB7XG59XG4iXX0=
--- esm2015/example.externs.js --- --- esm2015/example.externs.js ---
@ -1230,7 +1230,7 @@ var A11yModule = /** @class */ (function () {
return A11yModule; return A11yModule;
}()); }());
export { A11yModule }; export { A11yModule };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2JhemVsL3Rlc3QvbmdfcGFja2FnZS9leGFtcGxlL2ExMXkvcHVibGljLWFwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7O0FBRUgsT0FBTyxFQUFDLFFBQVEsRUFBQyxNQUFNLGVBQWUsQ0FBQztBQUd2QztJQUFBO0lBQXlCLENBQUM7SUFBYixVQUFVO1FBRHRCLFFBQVEsQ0FBQyxFQUFFLENBQUM7T0FDQSxVQUFVLENBQUc7SUFBRCxpQkFBQztDQUFBLEFBQTFCLElBQTBCO1NBQWIsVUFBVSIsInNvdXJjZXNDb250ZW50Ijpb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