@@ -11,6 +11,7 @@ const path = require('path');
1111const fs = require ( 'fs' ) ;
1212const resolve = require ( 'resolve' ) ;
1313const compile = require ( './utilities/compile' ) ;
14+ const ts = require ( 'typescript' ) ;
1415
1516const debugCompiler = require ( 'debug' ) ( 'ember-cli-typescript:compiler' ) ;
1617const debugAutoresolve = require ( 'debug' ) ( 'ember-cli-typescript:autoresolve' ) ;
@@ -29,7 +30,7 @@ module.exports = class IncrementalTypescriptCompiler {
2930 this . project = project ;
3031 this . addons = this . _discoverAddons ( project , [ ] ) ;
3132 this . maxBuildCount = 1 ;
32- this . autoresolveThreshold = 500 ;
33+ this . autoresolveThreshold = 250 ;
3334
3435 this . _buildDeferred = RSVP . defer ( ) ;
3536 this . _isSynced = false ;
@@ -106,43 +107,41 @@ module.exports = class IncrementalTypescriptCompiler {
106107
107108 let project = this . project ;
108109 let outDir = this . outDir ( ) ;
109- let flags = [ '--watch' ] ;
110- let tsc = compile ( { project, outDir, flags } ) ;
111-
112- tsc . stdout . on ( 'data' , data => {
113- let text = data
114- . toString ( )
115- . trim ( )
116- // tsc screen-clearing:
117- . replace ( / \u001b c / g, '' ) ; // eslint-disable-line no-control-regex
118-
119- if ( text ) {
120- this . project . ui . writeLine ( text ) ;
121- }
122110
123- if ( data . indexOf ( 'Starting incremental compilation' ) !== - 1 ) {
124- debugCompiler ( 'tsc detected a file change' ) ;
125- this . willRebuild ( ) ;
126- clearTimeout ( this . _pendingAutoresolve ) ;
127- }
111+ compile ( project , { outDir, watch : true } , {
112+ reportWatchStatus : ( diagnostic ) => {
113+ let text = diagnostic . messageText ;
128114
129- if ( data . indexOf ( 'Compilation complete' ) !== - 1 ) {
130- debugCompiler ( 'rebuild completed' ) ;
115+ if ( text . indexOf ( 'Starting incremental compilation' ) !== - 1 ) {
116+ debugCompiler ( 'tsc detected a file change' ) ;
117+ this . willRebuild ( ) ;
118+ clearTimeout ( this . _pendingAutoresolve ) ;
119+ }
131120
132- this . didSync ( ) ;
121+ if ( text . indexOf ( 'Compilation complete' ) !== - 1 ) {
122+ debugCompiler ( 'rebuild completed' ) ;
133123
134- if ( this . _didAutoresolve ) {
135- this . _touchRebuildTrigger ( ) ;
136- this . maxBuildCount ++ ;
137- }
124+ this . didSync ( ) ;
138125
139- clearTimeout ( this . _pendingAutoresolve ) ;
140- this . _didAutoresolve = false ;
141- }
142- } ) ;
126+ if ( this . _didAutoresolve ) {
127+ this . _touchRebuildTrigger ( ) ;
128+ this . maxBuildCount ++ ;
129+ }
143130
144- tsc . stderr . on ( 'data' , data => {
145- this . project . ui . writeError ( data . toString ( ) . trim ( ) ) ;
131+ clearTimeout ( this . _pendingAutoresolve ) ;
132+ this . _didAutoresolve = false ;
133+ }
134+ } ,
135+
136+ reportDiagnostic : ( diagnostic ) => {
137+ if ( diagnostic . category !== 2 ) {
138+ this . project . ui . write ( ts . formatDiagnostic ( diagnostic , {
139+ getCanonicalFileName : path => path ,
140+ getCurrentDirectory : ts . sys . getCurrentDirectory ,
141+ getNewLine : ( ) => ts . sys . newLine ,
142+ } ) ) ;
143+ }
144+ }
146145 } ) ;
147146 }
148147
0 commit comments