@@ -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 ( ) {
@@ -35,8 +41,8 @@ export class PackageBundler {
35
41
return this . bundleEntryPoint ( {
36
42
entryFile : this . buildPackage . entryFilePath ,
37
43
esm5EntryFile : join ( this . buildPackage . esm5OutputDir , 'index.js' ) ,
38
- importName : `@angular/${ this . buildPackage . name } ` ,
39
- moduleName : `ng. ${ this . buildPackage . name } ` ,
44
+ importName : `@angular/${ packageName } ` ,
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/${ packageName } /${ 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
@@ -154,7 +159,7 @@ export class PackageBundler {
154
159
// secondary entry-points from the rollup globals because we want the UMD for the
155
160
// primary entry-point to include *all* of the sources for those entry-points.
156
161
if ( this . buildPackage . exportsSecondaryEntryPointsAtRoot &&
157
- config . moduleName === `ng. ${ this . buildPackage . name } ` ) {
162
+ config . moduleName === this . primaryAmdModuleName ) {
158
163
159
164
const importRegex = new RegExp ( `@angular/${ this . buildPackage . name } /.+` ) ;
160
165
external = external . filter ( e => ! importRegex . test ( e ) ) ;
@@ -185,8 +190,26 @@ export class PackageBundler {
185
190
return map ;
186
191
} , { } as { [ key : string ] : string } ) ;
187
192
}
188
- }
189
193
194
+ /**
195
+ * Gets the AMD module name for a package and an optional entry point. This is consistent
196
+ * to the module name format being used in "angular/angular".
197
+ */
198
+ private getAmdModuleName ( packageName : string , entryPointName ?: string ) {
199
+ // For example, the AMD module name for the "@angular/material-examples" package should be
200
+ // "ng.materialExamples". We camel-case the package name in case it contains dashes.
201
+ let amdModuleName = `ng.${ dashCaseToCamelCase ( packageName ) } ` ;
202
+
203
+ if ( entryPointName ) {
204
+ // For example, the "@angular/material/bottom-sheet" entry-point should be converted into
205
+ // the following AMD module name: "ng.material.bottomSheet". Similar to the package name,
206
+ // the entry-point name needs to be camel-cased in case it contains dashes.
207
+ amdModuleName += `.${ dashCaseToCamelCase ( entryPointName ) } ` ;
208
+ }
209
+
210
+ return amdModuleName ;
211
+ }
212
+ }
190
213
191
214
/** Configuration for creating library bundles. */
192
215
interface BundlesConfig {
0 commit comments