@@ -17,7 +17,13 @@ const bundlesDir = join(buildConfig.outputDir, 'bundles');
17
17
18
18
/** Utility for creating bundles from raw ngc output. */
19
19
export 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
+ }
21
27
22
28
/** Creates all bundles for the package and all associated entry points (UMD, ES5, ES2015). */
23
29
async createBundles ( ) {
@@ -36,7 +42,7 @@ export class PackageBundler {
36
42
entryFile : this . buildPackage . entryFilePath ,
37
43
esm5EntryFile : join ( this . buildPackage . esm5OutputDir , 'index.js' ) ,
38
44
importName : `@angular/${ this . buildPackage . name } ` ,
39
- moduleName : `ng. ${ this . buildPackage . name } ` ,
45
+ moduleName : this . primaryAmdModuleName ,
40
46
esm2015Dest : join ( bundlesDir , `${ packageName } .js` ) ,
41
47
esm5Dest : join ( bundlesDir , `${ packageName } .es5.js` ) ,
42
48
umdDest : join ( bundlesDir , `${ packageName } .umd.js` ) ,
@@ -45,21 +51,20 @@ export class PackageBundler {
45
51
}
46
52
47
53
/** 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 ) {
49
55
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' ) ;
53
58
54
59
return this . bundleEntryPoint ( {
55
60
entryFile,
56
61
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` ) ,
63
68
} ) ;
64
69
}
65
70
@@ -150,7 +155,7 @@ export class PackageBundler {
150
155
// secondary entry-points from the rollup globals because we want the UMD for this package
151
156
// to include *all* of the sources for those entry-points.
152
157
if ( this . buildPackage . exportsSecondaryEntryPointsAtRoot &&
153
- config . moduleName === `ng. ${ this . buildPackage . name } ` ) {
158
+ config . moduleName === this . primaryAmdModuleName ) {
154
159
155
160
const importRegex = new RegExp ( `@angular/${ this . buildPackage . name } /.+` ) ;
156
161
external = external . filter ( e => ! importRegex . test ( e ) ) ;
@@ -181,8 +186,18 @@ export class PackageBundler {
181
186
return map ;
182
187
} , { } as { [ key : string ] : string } ) ;
183
188
}
184
- }
185
189
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
+ }
186
201
187
202
/** Configuration for creating library bundles. */
188
203
interface BundlesConfig {
0 commit comments