@@ -17,7 +17,13 @@ const bundlesDir = join(buildConfig.outputDir, 'bundles');
1717
1818/** Utility for creating bundles from raw ngc output. */
1919export class PackageBundler {
20- constructor ( private buildPackage : BuildPackage ) { }
20+
21+ /** Name of the AMD module for the primary entry point of the build package. */
22+ private readonly primaryAmdModuleName : string ;
23+
24+ constructor ( private buildPackage : BuildPackage ) {
25+ this . primaryAmdModuleName = this . getAmdModuleName ( buildPackage . name ) ;
26+ }
2127
2228 /** Creates all bundles for the package and all associated entry points (UMD, ES5, ES2015). */
2329 async createBundles ( ) {
@@ -36,7 +42,7 @@ export class PackageBundler {
3642 entryFile : this . buildPackage . entryFilePath ,
3743 esm5EntryFile : join ( this . buildPackage . esm5OutputDir , 'index.js' ) ,
3844 importName : `@angular/${ this . buildPackage . name } ` ,
39- moduleName : `ng. ${ this . buildPackage . name } ` ,
45+ moduleName : this . primaryAmdModuleName ,
4046 esm2015Dest : join ( bundlesDir , `${ packageName } .js` ) ,
4147 esm5Dest : join ( bundlesDir , `${ packageName } .es5.js` ) ,
4248 umdDest : join ( bundlesDir , `${ packageName } .umd.js` ) ,
@@ -45,21 +51,20 @@ export class PackageBundler {
4551 }
4652
4753 /** Bundles a single secondary entry-point w/ given entry file, e.g. @angular/cdk/a11y */
48- private async bundleSecondaryEntryPoint ( entryPoint : string ) {
54+ private async bundleSecondaryEntryPoint ( entryPointName : string ) {
4955 const packageName = this . buildPackage . name ;
50- const entryFile = join ( this . buildPackage . outputDir , entryPoint , 'index.js' ) ;
51- const esm5EntryFile = join ( this . buildPackage . esm5OutputDir , entryPoint , 'index.js' ) ;
52- const dashedEntryName = dashCaseToCamelCase ( entryPoint ) ;
56+ const entryFile = join ( this . buildPackage . outputDir , entryPointName , 'index.js' ) ;
57+ const esm5EntryFile = join ( this . buildPackage . esm5OutputDir , entryPointName , 'index.js' ) ;
5358
5459 return this . bundleEntryPoint ( {
5560 entryFile,
5661 esm5EntryFile,
57- importName : `@angular/${ this . buildPackage . name } /${ dashedEntryName } ` ,
58- moduleName : `ng. ${ packageName } . ${ dashedEntryName } ` ,
59- esm2015Dest : join ( bundlesDir , `${ packageName } ` , `${ entryPoint } .js` ) ,
60- esm5Dest : join ( bundlesDir , `${ packageName } ` , `${ entryPoint } .es5.js` ) ,
61- umdDest : join ( bundlesDir , `${ packageName } -${ entryPoint } .umd.js` ) ,
62- umdMinDest : join ( bundlesDir , `${ packageName } -${ entryPoint } .umd.min.js` ) ,
62+ importName : `@angular/${ this . buildPackage . name } /${ entryPointName } ` ,
63+ moduleName : this . getAmdModuleName ( packageName , entryPointName ) ,
64+ esm2015Dest : join ( bundlesDir , `${ packageName } ` , `${ entryPointName } .js` ) ,
65+ esm5Dest : join ( bundlesDir , `${ packageName } ` , `${ entryPointName } .es5.js` ) ,
66+ umdDest : join ( bundlesDir , `${ packageName } -${ entryPointName } .umd.js` ) ,
67+ umdMinDest : join ( bundlesDir , `${ packageName } -${ entryPointName } .umd.min.js` ) ,
6368 } ) ;
6469 }
6570
@@ -150,7 +155,7 @@ export class PackageBundler {
150155 // secondary entry-points from the rollup globals because we want the UMD for this package
151156 // to include *all* of the sources for those entry-points.
152157 if ( this . buildPackage . exportsSecondaryEntryPointsAtRoot &&
153- config . moduleName === `ng. ${ this . buildPackage . name } ` ) {
158+ config . moduleName === this . primaryAmdModuleName ) {
154159
155160 const importRegex = new RegExp ( `@angular/${ this . buildPackage . name } /.+` ) ;
156161 external = external . filter ( e => ! importRegex . test ( e ) ) ;
@@ -181,8 +186,18 @@ export class PackageBundler {
181186 return map ;
182187 } , { } as { [ key : string ] : string } ) ;
183188 }
184- }
185189
190+ /** Gets the AMD module name for a package and an optional entry point. */
191+ private getAmdModuleName ( packageName : string , entryPointName ?: string ) {
192+ let amdModuleName = `ng.${ dashCaseToCamelCase ( packageName ) } ` ;
193+
194+ if ( entryPointName ) {
195+ amdModuleName += `.${ dashCaseToCamelCase ( entryPointName ) } ` ;
196+ }
197+
198+ return amdModuleName ;
199+ }
200+ }
186201
187202/** Configuration for creating library bundles. */
188203interface BundlesConfig {
0 commit comments