11"use strict" ;
22var ts = require ( "typescript" ) ;
33var fs = require ( "fs" ) ;
4+ var path = require ( "path" ) ;
5+ var arg1 = process . argv . length > 2 ? process . argv [ 2 ] : "" ;
6+ var isIncremental = arg1 . indexOf ( "i" ) >= 0 ;
7+ if ( isIncremental ) {
8+ console . log ( "incremental" ) ;
9+ }
410function compile ( fileNames , options ) {
11+ console . time ( "program" ) ;
512 var program = ts . createProgram ( fileNames , options ) ;
13+ console . timeEnd ( "program" ) ;
614 var sourceFiles = program . getSourceFiles ( ) . filter ( function ( f ) { return f . fileName . lastIndexOf ( ".d.ts" ) !== f . fileName . length - 5 ; } ) ;
7- // sourceFiles.forEach(sf => console.log(" - " + sf.fileName));
815 var emitResults = [ ] ;
916 var allDiagnostics = [ ] ;
10- sourceFiles . forEach ( function ( srcFile ) { return emitResults . push ( program . emit ( srcFile ) ) ; } ) ;
17+ console . time ( "transpile" ) ;
18+ if ( isIncremental ) {
19+ sourceFiles = sourceFiles . filter ( function ( srcFile ) {
20+ try {
21+ var tsName = srcFile . fileName ;
22+ var jsName = path . join ( path . dirname ( tsName ) , path . basename ( tsName , ".ts" ) ) + ".js" ;
23+ var tsTime = fs . statSync ( tsName ) . mtime . getTime ( ) ;
24+ var jsTime = fs . statSync ( jsName ) . mtime . getTime ( ) ;
25+ return jsTime < tsTime ;
26+ }
27+ catch ( e ) {
28+ return true ;
29+ }
30+ } ) ;
31+ sourceFiles . forEach ( function ( srcFile ) {
32+ console . log ( " - " + srcFile . fileName ) ;
33+ emitResults . push ( program . emit ( srcFile ) ) ;
34+ } ) ;
35+ }
36+ else {
37+ sourceFiles . forEach ( function ( srcFile ) { return emitResults . push ( program . emit ( srcFile ) ) ; } ) ;
38+ }
39+ console . timeEnd ( "transpile" ) ;
40+ console . time ( "diagnostics" ) ;
1141 sourceFiles . forEach ( function ( srcFile ) { return allDiagnostics = allDiagnostics . concat ( ts . getPreEmitDiagnostics ( program , srcFile ) ) ; } ) ;
1242 emitResults . forEach ( function ( er ) { return allDiagnostics = allDiagnostics . concat ( er . diagnostics ) ; } ) ;
1343 allDiagnostics . forEach ( function ( diagnostic ) {
@@ -18,6 +48,7 @@ function compile(fileNames, options) {
1848 var code = diagnostic . code ;
1949 console . log ( diagnostic . file . fileName + "(" + ( line + 1 ) + "," + ( character + 1 ) + "): TS" + code + ": " + message ) ;
2050 } ) ;
51+ console . timeEnd ( "diagnostics" ) ;
2152 var exitCode = emitResults . some ( function ( er ) { return er . emitSkipped ; } ) ? 1 : 0 ;
2253 console . log ( "Process exiting with code " + exitCode + "." ) ;
2354 process . exit ( exitCode ) ;
0 commit comments