@@ -23,18 +23,15 @@ TypeScriptCompiler = class TypeScriptCompiler {
23
23
24
24
inputFiles = this . excludeFiles ( inputFiles ) ;
25
25
26
- let archMap = { } , filesMap = { } ;
26
+ let filesMap = { } , archMap = { } ;
27
27
inputFiles . forEach ( ( inputFile , index ) => {
28
- if ( inputFile . isConfig ( ) ) return ;
29
-
30
- let arch = inputFile . getArch ( ) ;
31
- let archFiles = archMap [ arch ] ;
32
- if ( ! archFiles ) {
33
- archFiles = [ ] ;
34
- archMap [ arch ] = archFiles ;
35
- }
36
- archFiles . push ( inputFile ) ;
37
28
filesMap [ this . getExtendedPath ( inputFile ) ] = index ;
29
+ archMap [ inputFile . getArch ( ) ] = [ ] ;
30
+ } ) ;
31
+
32
+ _ . keys ( archMap ) . forEach ( arch => {
33
+ let archFiles = this . getArchFiles ( inputFiles , arch ) ;
34
+ archMap [ arch ] = archFiles ;
38
35
} ) ;
39
36
40
37
let getFileContent = filePath => {
@@ -51,20 +48,21 @@ TypeScriptCompiler = class TypeScriptCompiler {
51
48
let useCache = this . tsconfig . useCache ;
52
49
let buildOptions = { compilerOptions, typings, useCache } ;
53
50
54
- let dcompile = Logger . newDebug ( 'compilation' ) ;
51
+ let pcompile = Logger . newProfiler ( 'compilation' ) ;
55
52
_ . keys ( archMap ) . forEach ( ( arch , cb ) => {
56
53
let archFiles = archMap [ arch ] ;
57
54
let filePaths = archFiles . map ( inputFile => this . getExtendedPath ( inputFile ) ) ;
58
- dcompile . log ( 'process files: %s' , filePaths ) ;
55
+ Logger . log ( 'process files: %s' , filePaths ) ;
59
56
buildOptions . arch = arch ;
60
-
61
- let dbuild = Logger . newDebug ( 'tsBuild' ) ;
57
+ let pbuild = Logger . newProfiler ( 'tsBuild' ) ;
62
58
let tsBuild = new TSBuild ( filePaths , getFileContent , buildOptions ) ;
59
+ pbuild . end ( ) ;
63
60
61
+ let pfiles = Logger . newProfiler ( 'tsEmitFiles' ) ;
64
62
let future = new Future ;
65
- async . each ( archFiles , ( inputFile , cb ) => {
66
- if ( inputFile . isDeclaration ( ) ) { cb ( ) ; return ; } ;
67
-
63
+ // Don't emit typings.
64
+ archFiles = archFiles . filter ( inputFile => ! inputFile . isDeclaration ( ) ) ;
65
+ async . eachLimit ( archFiles , this . maxParallelism , ( inputFile , cb ) => {
68
66
let co = compilerOptions ;
69
67
let source = inputFile . getContentsAsString ( ) ;
70
68
let inputFilePath = inputFile . getPathInPackage ( ) ;
@@ -81,28 +79,27 @@ TypeScriptCompiler = class TypeScriptCompiler {
81
79
let filePath = this . getExtendedPath ( inputFile ) ;
82
80
let moduleName = this . getFileModuleName ( inputFile , co ) ;
83
81
84
- let demit = Logger . newDebug ( 'tsEmit' ) ;
82
+ let pemit = Logger . newProfiler ( 'tsEmit' ) ;
85
83
let result = tsBuild . emit ( filePath , moduleName ) ;
86
84
this . processDiagnostics ( inputFile , result . diagnostics , co ) ;
87
- demit . end ( ) ;
85
+ pemit . end ( ) ;
88
86
89
87
toBeAdded . data = result . code ;
90
88
let module = compilerOptions . module ;
91
89
toBeAdded . bare = toBeAdded . bare || module === 'none' ;
92
90
toBeAdded . hash = result . hash ;
93
91
toBeAdded . sourceMap = result . sourceMap ;
94
-
95
92
inputFile . addJavaScript ( toBeAdded ) ;
96
93
97
94
cb ( ) ;
98
95
} , future . resolver ( ) ) ;
99
96
100
- future . wait ( ) ;
97
+ pfiles . end ( ) ;
101
98
102
- dbuild . end ( ) ;
99
+ future . wait ( ) ;
103
100
} ) ;
104
101
105
- dcompile . end ( ) ;
102
+ pcompile . end ( ) ;
106
103
}
107
104
108
105
extendFiles ( inputFiles , mixins ) {
@@ -193,19 +190,43 @@ TypeScriptCompiler = class TypeScriptCompiler {
193
190
excludeFiles ( inputFiles ) {
194
191
let resultFiles = inputFiles ;
195
192
196
- let dexclude = Logger . newDebug ( 'exclude' ) ;
193
+ let pexclude = Logger . newProfiler ( 'exclude' ) ;
197
194
for ( let ex of this . tsconfig . exclude ) {
198
195
resultFiles = resultFiles . filter ( inputFile => {
199
196
let path = inputFile . getPathInPackage ( ) ;
200
- dexclude . log ( 'exclude pattern %s: %s' , ex , path ) ;
197
+ Logger . assert ( 'exclude pattern %s: %s' , ex , path ) ;
201
198
return ! minimatch ( path , ex ) ;
202
199
} ) ;
203
200
}
204
- dexclude . end ( ) ;
201
+ pexclude . end ( ) ;
205
202
206
203
return resultFiles ;
207
204
}
208
205
206
+ getArchFiles ( inputFiles , arch ) {
207
+ let archFiles = inputFiles . filter ( ( inputFile , index ) => {
208
+ if ( inputFile . isConfig ( ) ) return false ;
209
+
210
+ return inputFile . getArch ( ) === arch ;
211
+ } ) ;
212
+
213
+ // Include only typings that current arch needs,
214
+ // typings/main is for the server only and
215
+ // typings/browser - for the client.
216
+ let excludes = arch . startsWith ( 'web' ) ?
217
+ [ 'typings/main/**' , 'typings/main.d.ts' ] :
218
+ [ 'typings/browser/**' , 'typings/browser.d.ts' ] ;
219
+
220
+ for ( let ex of excludes ) {
221
+ archFiles = archFiles . filter ( inputFile => {
222
+ let path = inputFile . getPathInPackage ( ) ;
223
+ return ! minimatch ( path , ex ) ;
224
+ } ) ;
225
+ }
226
+
227
+ return archFiles ;
228
+ }
229
+
209
230
getTypings ( filePaths ) {
210
231
check ( filePaths , Array ) ;
211
232
0 commit comments