1
1
import { join } from 'path' ;
2
- import { main as tsc } from '@angular/tsc-wrapped' ;
3
2
import { buildConfig } from './build-config' ;
4
3
import { getSecondaryEntryPointsForPackage } from './secondary-entry-points' ;
5
4
import { buildPrimaryEntryPointBundles , buildSecondaryEntryPointBundles } from './build-bundles' ;
6
-
5
+ import { main as ngc } from '@angular/tsc-wrapped' ;
7
6
8
7
const { packagesDir, outputDir} = buildConfig ;
9
8
@@ -31,15 +30,21 @@ export class BuildPackage {
31
30
private tsconfigTests : string ;
32
31
33
32
/** Secondary entry points for the package. */
34
- get secondaryEntryPoints ( ) : string [ ] {
33
+ get secondaryEntryPoints ( ) : string [ ] [ ] {
35
34
if ( ! this . _secondaryEntryPoints ) {
36
35
this . _secondaryEntryPoints = getSecondaryEntryPointsForPackage ( this ) ;
37
36
}
38
37
39
38
return this . _secondaryEntryPoints ;
40
39
}
40
+ private _secondaryEntryPoints : string [ ] [ ] ;
41
41
42
- private _secondaryEntryPoints : string [ ] ;
42
+ /** Flat list of secondary entry-points for the build package. */
43
+ get flatSecondaryEntryPoints ( ) : string [ ] {
44
+ return this . secondaryEntryPoints . reduce ( ( entryPoints : string [ ] , entryPointLevel : string [ ] ) => {
45
+ return [ ...entryPoints , ...entryPointLevel ] ;
46
+ } , [ ] ) ;
47
+ }
43
48
44
49
constructor ( public packageName : string , public dependencies : BuildPackage [ ] = [ ] ) {
45
50
this . packageRoot = join ( packagesDir , packageName ) ;
@@ -55,9 +60,12 @@ export class BuildPackage {
55
60
async compile ( ) {
56
61
await this . _compileEntryPoint ( buildTsconfigName ) ;
57
62
58
- // Walk through every secondary entry point and build the TypeScript sources sequentially.
59
- for ( const entryPoint of this . secondaryEntryPoints ) {
60
- await this . _compileEntryPoint ( buildTsconfigName , entryPoint ) ;
63
+ // Secondary entry points are built in batches. Meaning that some packages will be built
64
+ // in parallel while other packages have to be built sequentially.
65
+ for ( const entryPointsLevel of this . secondaryEntryPoints ) {
66
+ await Promise . all ( entryPointsLevel . map ( entryPoint => {
67
+ return this . _compileEntryPoint ( buildTsconfigName , entryPoint ) ;
68
+ } ) ) ;
61
69
}
62
70
}
63
71
@@ -70,17 +78,19 @@ export class BuildPackage {
70
78
async createBundles ( ) {
71
79
await buildPrimaryEntryPointBundles ( this . entryFilePath , this . packageName ) ;
72
80
73
- for ( const entryPoint of this . secondaryEntryPoints ) {
74
- const entryPointEntryFilePath = join ( this . packageOut , entryPoint , 'index.js' ) ;
75
- await buildSecondaryEntryPointBundles ( entryPointEntryFilePath , this . packageName , entryPoint ) ;
81
+ for ( const entryPointLevel of this . secondaryEntryPoints ) {
82
+ await Promise . all ( entryPointLevel . map ( entryPoint => {
83
+ const entryPointEntryPath = join ( this . packageOut , entryPoint , 'index.js' ) ;
84
+ return buildSecondaryEntryPointBundles ( entryPointEntryPath , this . packageName , entryPoint ) ;
85
+ } ) ) ;
76
86
}
77
87
}
78
88
79
89
/** Compiles the TypeScript sources of a primary or secondary entry point. */
80
- private async _compileEntryPoint ( tsconfigName : string , secondaryEntryPoint ?: string ) {
90
+ private _compileEntryPoint ( tsconfigName : string , secondaryEntryPoint ?: string ) {
81
91
const entryPointPath = join ( this . packageRoot , secondaryEntryPoint || '' ) ;
82
92
const entryPointTsconfigPath = join ( entryPointPath , tsconfigName ) ;
83
93
84
- await tsc ( entryPointTsconfigPath , { basePath : entryPointPath } ) ;
94
+ return ngc ( entryPointTsconfigPath , { basePath : entryPointPath } ) ;
85
95
}
86
96
}
0 commit comments