feat(tsc-wrapped): add an option to ngc
to bundle metadata (#14509)
Closes #14509
This commit is contained in:

committed by
Igor Minar

parent
9a6f3d637f
commit
3b896709a9
58
tools/@angular/tsc-wrapped/src/index_writer.ts
Normal file
58
tools/@angular/tsc-wrapped/src/index_writer.ts
Normal file
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. 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
|
||||
*/
|
||||
|
||||
import {BundlePrivateEntry} from './bundler';
|
||||
|
||||
const INDEX_HEADER = `/**
|
||||
* Generated bundle index. Do not edit.
|
||||
*/
|
||||
`;
|
||||
|
||||
type MapEntry = [string, BundlePrivateEntry[]];
|
||||
|
||||
export function privateEntriesToIndex(index: string, privates: BundlePrivateEntry[]): string {
|
||||
const results: string[] = [INDEX_HEADER];
|
||||
|
||||
// Export all of the index symbols.
|
||||
results.push(`export * from '${index}';`, '');
|
||||
|
||||
// Simplify the exports
|
||||
const exports = new Map<string, BundlePrivateEntry[]>();
|
||||
|
||||
for (const entry of privates) {
|
||||
let entries = exports.get(entry.module);
|
||||
if (!entries) {
|
||||
entries = [];
|
||||
exports.set(entry.module, entries);
|
||||
}
|
||||
entries.push(entry);
|
||||
}
|
||||
|
||||
|
||||
const compareEntries = compare((e: BundlePrivateEntry) => e.name);
|
||||
const compareModules = compare((e: MapEntry) => e[0]);
|
||||
const orderedExports =
|
||||
Array.from(exports)
|
||||
.map(([module, entries]) => <MapEntry>[module, entries.sort(compareEntries)])
|
||||
.sort(compareModules);
|
||||
|
||||
for (const [module, entries] of orderedExports) {
|
||||
let symbols = entries.map(e => `${e.name} as ${e.privateName}`);
|
||||
results.push(`export {${symbols}} from '${module}';`);
|
||||
}
|
||||
|
||||
return results.join('\n');
|
||||
}
|
||||
|
||||
function compare<E, T>(select: (e: E) => T): (a: E, b: E) => number {
|
||||
return (a, b) => {
|
||||
const ak = select(a);
|
||||
const bk = select(b);
|
||||
return ak > bk ? 1 : ak < bk ? -1 : 0;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user