From 94bc3d169f3bdb50d299ff85817975e544ad645a Mon Sep 17 00:00:00 2001 From: Alan Date: Wed, 6 Feb 2019 08:23:37 +0100 Subject: [PATCH] fix(@angular-devkit/build-angular): throw error when multiple bundles have been name the same Naming more than 1 bundle with the same name might cause undefined behavior. Fixes #13568 --- .../utilities/package-chunk-sort.ts | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/package-chunk-sort.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/package-chunk-sort.ts index d6ccf6e569ac..ee2a2e450e7e 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/package-chunk-sort.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/utilities/package-chunk-sort.ts @@ -11,23 +11,36 @@ import { normalizeExtraEntryPoints } from '../models/webpack-configs/utils'; export function generateEntryPoints( appConfig: { styles: ExtraEntryPoint[], scripts: ExtraEntryPoint[] }, ) { - const entryPoints = ['es2015-polyfills', 'polyfills', 'sw-register']; // Add all styles/scripts, except lazy-loaded ones. - [ - ...normalizeExtraEntryPoints(appConfig.styles, 'styles') + const extraEntryPoints = ( + extraEntryPoints: ExtraEntryPoint[], + defaultBundleName: string, + ): string[] => { + const entryPoints = normalizeExtraEntryPoints(extraEntryPoints, defaultBundleName) .filter(entry => !entry.lazy) - .map(entry => entry.bundleName), - ...normalizeExtraEntryPoints(appConfig.scripts, 'scripts') - .filter(entry => !entry.lazy) - .map(entry => entry.bundleName), - ].forEach(bundleName => { - if (entryPoints.indexOf(bundleName) === -1) { - entryPoints.push(bundleName); - } - }); + .map(entry => entry.bundleName); + + // remove duplicates + return [...new Set(entryPoints)]; + }; + + const entryPoints = [ + 'es2015-polyfills', + 'polyfills', + 'sw-register', + ...extraEntryPoints(appConfig.styles, 'styles'), + ...extraEntryPoints(appConfig.scripts, 'scripts'), + 'main', + ]; + + const duplicates = [...new Set( + entryPoints.filter(x => entryPoints.indexOf(x) !== entryPoints.lastIndexOf(x)), + )]; - entryPoints.push('main'); + if (duplicates.length > 0) { + throw new Error(`Multiple bundles have been named the same: '${duplicates.join(`', '`)}'.`); + } return entryPoints; }