@@ -8,8 +8,8 @@ import {remapSourcemap} from './sourcemap-remap';
8
8
9
9
// There are no type definitions available for these imports.
10
10
const rollup = require ( 'rollup' ) ;
11
- const rollupNodeResolutionPlugin = require ( '@rollup/plugin-node-resolve' ) ;
12
- const rollupAlias = require ( 'rollup- plugin-alias' ) ;
11
+ const rollupNodeResolve = require ( '@rollup/plugin-node-resolve' ) ;
12
+ const rollupAlias = require ( '@ rollup/ plugin-alias' ) ;
13
13
const babel = require ( 'rollup-plugin-babel' ) ;
14
14
15
15
/** Directory where all bundles will be created in. */
@@ -20,13 +20,13 @@ export class PackageBundler {
20
20
/** Name of the AMD module for the primary entry point of the build package. */
21
21
private readonly primaryAmdModuleName : string ;
22
22
23
- constructor ( private buildPackage : BuildPackage ) {
24
- this . primaryAmdModuleName = this . getAmdModuleName ( buildPackage . name ) ;
23
+ constructor ( private _buildPackage : BuildPackage ) {
24
+ this . primaryAmdModuleName = this . _getAmdModuleName ( _buildPackage . name ) ;
25
25
}
26
26
27
27
/** Creates all bundles for the package and all associated entry points (UMD, ES5, ES2015). */
28
28
async createBundles ( ) {
29
- for ( const entryPoint of this . buildPackage . secondaryEntryPoints ) {
29
+ for ( const entryPoint of this . _buildPackage . secondaryEntryPoints ) {
30
30
await this . bundleSecondaryEntryPoint ( entryPoint ) ;
31
31
}
32
32
@@ -35,11 +35,11 @@ export class PackageBundler {
35
35
36
36
/** Bundles the primary entry-point w/ given entry file, e.g. @angular-mdc/web */
37
37
private async bundlePrimaryEntryPoint ( ) {
38
- const packageName = this . buildPackage . name ;
38
+ const packageName = this . _buildPackage . name ;
39
39
40
40
return this . bundleEntryPoint ( {
41
- entryFile : this . buildPackage . entryFilePath ,
42
- esm5EntryFile : join ( this . buildPackage . esm5OutputDir , 'index.js' ) ,
41
+ entryFile : this . _buildPackage . entryFilePath ,
42
+ esm5EntryFile : join ( this . _buildPackage . esm5OutputDir , 'index.js' ) ,
43
43
importName : `@angular-mdc/${ packageName } ` ,
44
44
moduleName : this . primaryAmdModuleName ,
45
45
esm2015Dest : join ( bundlesDir , `${ packageName } .js` ) ,
@@ -51,15 +51,15 @@ export class PackageBundler {
51
51
52
52
/** Bundles a single secondary entry-point w/ given entry file, e.g. @angular-mdc/web/button */
53
53
private async bundleSecondaryEntryPoint ( entryPointName : string ) {
54
- const packageName = this . buildPackage . name ;
55
- const entryFile = join ( this . buildPackage . outputDir , entryPointName , 'index.js' ) ;
56
- const esm5EntryFile = join ( this . buildPackage . esm5OutputDir , entryPointName , 'index.js' ) ;
54
+ const packageName = this . _buildPackage . name ;
55
+ const entryFile = join ( this . _buildPackage . outputDir , entryPointName , 'index.js' ) ;
56
+ const esm5EntryFile = join ( this . _buildPackage . esm5OutputDir , entryPointName , 'index.js' ) ;
57
57
58
58
return this . bundleEntryPoint ( {
59
59
entryFile,
60
60
esm5EntryFile,
61
61
importName : `@angular-mdc/${ packageName } /${ entryPointName } ` ,
62
- moduleName : this . getAmdModuleName ( packageName , entryPointName ) ,
62
+ moduleName : this . _getAmdModuleName ( packageName , entryPointName ) ,
63
63
esm2015Dest : join ( bundlesDir , `${ packageName } ` , `${ entryPointName } .js` ) ,
64
64
esm5Dest : join ( bundlesDir , `${ packageName } ` , `${ entryPointName } .es5.js` ) ,
65
65
umdDest : join ( bundlesDir , `${ packageName } -${ entryPointName } .umd.js` ) ,
@@ -70,7 +70,7 @@ export class PackageBundler {
70
70
/**
71
71
* Creates the ES5, ES2015, and UMD bundles for the specified entry-point.
72
72
* @param config Configuration that specifies the entry-point, module name, and output
73
- * bundle paths.
73
+ * bundle paths.
74
74
*/
75
75
private async bundleEntryPoint ( config : BundlesConfig ) {
76
76
// Build FESM-2015 bundle file.
@@ -107,7 +107,6 @@ export class PackageBundler {
107
107
await remapSourcemap ( config . esm2015Dest ) ;
108
108
await remapSourcemap ( config . esm5Dest ) ;
109
109
await remapSourcemap ( config . umdDest ) ;
110
- // await remapSourcemap(config.umdMinDest);
111
110
}
112
111
113
112
/** Creates a rollup bundle of a specified JavaScript file.*/
@@ -164,7 +163,7 @@ export class PackageBundler {
164
163
// For UMD bundles, we need to adjust the `external` bundle option in order to include
165
164
// all necessary code in the bundle.
166
165
if ( config . format === 'umd' ) {
167
- bundleOptions . plugins . push ( rollupNodeResolutionPlugin ( ) ) ;
166
+ bundleOptions . plugins . push ( rollupNodeResolve ( ) ) ;
168
167
// For all UMD bundles, we want to exclude tslib from the `external` bundle option so that
169
168
// it is inlined into the bundle.
170
169
let external = Object . keys ( rollupGlobals ) ;
@@ -173,17 +172,18 @@ export class PackageBundler {
173
172
// If each secondary entry-point is re-exported at the root, we want to exclude those
174
173
// secondary entry-points from the rollup globals because we want the UMD for the
175
174
// primary entry-point to include *all* of the sources for those entry-points.
176
- if ( this . buildPackage . exportsSecondaryEntryPointsAtRoot &&
175
+ if ( this . _buildPackage . exportsSecondaryEntryPointsAtRoot &&
177
176
config . moduleName === this . primaryAmdModuleName ) {
178
177
179
- const importRegex = new RegExp ( `@angular-mdc/${ this . buildPackage . name } /.+` ) ;
178
+ const importRegex = new RegExp ( `@angular-mdc/${ this . _buildPackage . name } /.+` ) ;
180
179
external = external . filter ( e => ! importRegex . test ( e ) ) ;
181
180
182
181
// Use the rollup-alias plugin to map imports of the form `@angular-mdc/web/button`
183
182
// to the actual file location so that rollup can resolve the imports (otherwise they
184
183
// will be treated as external dependencies and not included in the bundle).
185
- bundleOptions . plugins . push (
186
- rollupAlias ( this . getResolvedSecondaryEntryPointImportPaths ( config . dest ) ) ) ;
184
+ bundleOptions . plugins . push ( rollupAlias ( {
185
+ entries : this . _getResolvedSecondaryEntryPointImportPaths ( config . dest )
186
+ } ) ) ;
187
187
}
188
188
bundleOptions . external = external ;
189
189
}
@@ -192,24 +192,25 @@ export class PackageBundler {
192
192
}
193
193
194
194
/**
195
- * Gets mapping of import aliases (e.g. `@angular-mdc/web/button`) to the path of the es5
195
+ * Gets array of import aliases (e.g. `@angular-mdc/web/button`) with the path of the es5
196
196
* bundle output.
197
197
* @param bundleOutputDir Path to the bundle output directory.
198
- * @returns Map of alias to resolved path.
198
+ * @returns Array of alias with resolved path.
199
199
*/
200
- private getResolvedSecondaryEntryPointImportPaths ( bundleOutputDir : string ) {
201
- return this . buildPackage . secondaryEntryPoints . reduce ( ( map , p ) => {
202
- map [ `@angular-mdc/${ this . buildPackage . name } /${ p } ` ] =
203
- join ( dirname ( bundleOutputDir ) , this . buildPackage . name , `${ p } .es5.js` ) ;
204
- return map ;
205
- } , { } as { [ key : string ] : string } ) ;
200
+ private _getResolvedSecondaryEntryPointImportPaths ( bundleOutputDir : string ) {
201
+ return this . _buildPackage . secondaryEntryPoints . map ( p => {
202
+ return {
203
+ find : `@angular-mdc/${ this . _buildPackage . name } /${ p } ` ,
204
+ replacement : join ( dirname ( bundleOutputDir ) , this . _buildPackage . name , `${ p } .es5.js` )
205
+ } ;
206
+ } ) ;
206
207
}
207
208
208
209
/**
209
210
* Gets the AMD module name for a package and an optional entry point. This is consistent
210
211
* to the module name format being used in "angular/angular".
211
212
*/
212
- private getAmdModuleName ( packageName : string , entryPointName ?: string ) {
213
+ private _getAmdModuleName ( packageName : string , entryPointName ?: string ) {
213
214
let amdModuleName = `ng.${ dashCaseToCamelCase ( packageName ) } ` ;
214
215
215
216
if ( entryPointName ) {
0 commit comments