@@ -11,10 +11,17 @@ 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' ) ;
1718
19+ const formatHost = {
20+ getCanonicalFileName : path => path ,
21+ getCurrentDirectory : ts . sys . getCurrentDirectory ,
22+ getNewLine : ( ) => ts . sys . newLine ,
23+ } ;
24+
1825module . exports = class IncrementalTypescriptCompiler {
1926 constructor ( app , project ) {
2027 if ( project . _incrementalTsCompiler ) {
@@ -106,43 +113,72 @@ module.exports = class IncrementalTypescriptCompiler {
106113
107114 let project = this . project ;
108115 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- . replace ( / \u001b c / g, '' ) ;
117-
118- if ( text ) {
119- this . project . ui . writeLine ( text ) ;
120- }
116+ let tsc = compile ( project , { outDir, watch : true } , {
117+ reportWatchStatus : ( diagnostic ) => {
118+ let text = diagnostic . messageText ;
119+
120+ if ( text . indexOf ( 'Starting incremental compilation' ) !== - 1 ) {
121+ debugCompiler ( 'tsc detected a file change' ) ;
122+ this . willRebuild ( ) ;
123+ clearTimeout ( this . _pendingAutoresolve ) ;
124+ }
121125
122- if ( data . indexOf ( 'Starting incremental compilation' ) !== - 1 ) {
123- debugCompiler ( 'tsc detected a file change' ) ;
124- this . willRebuild ( ) ;
125- clearTimeout ( this . _pendingAutoresolve ) ;
126- }
126+ if ( text . indexOf ( 'Compilation complete' ) !== - 1 ) {
127+ debugCompiler ( 'rebuild completed' ) ;
127128
128- if ( data . indexOf ( 'Compilation complete' ) !== - 1 ) {
129- debugCompiler ( 'rebuild completed' ) ;
129+ this . didSync ( ) ;
130130
131- this . didSync ( ) ;
131+ if ( this . _didAutoresolve ) {
132+ this . _touchRebuildTrigger ( ) ;
133+ this . maxBuildCount ++ ;
134+ }
132135
133- if ( this . _didAutoresolve ) {
134- this . _touchRebuildTrigger ( ) ;
135- this . maxBuildCount ++ ;
136+ clearTimeout ( this . _pendingAutoresolve ) ;
137+ this . _didAutoresolve = false ;
136138 }
139+ } ,
137140
138- clearTimeout ( this . _pendingAutoresolve ) ;
139- this . _didAutoresolve = false ;
141+ reportDiagnostic : ( diagnostic ) => {
142+ // if (diagnostic.category !== 2) {
143+ // this.project.ui.write(ts.formatDiagnostic(diagnostic, formatHost));
144+ // }
140145 }
141146 } ) ;
142147
143- tsc . stderr . on ( 'data' , data => {
144- this . project . ui . writeError ( data . toString ( ) . trim ( ) ) ;
145- } ) ;
148+ // tsc.stdout.on('data', data => {
149+ // let text = data
150+ // .toString()
151+ // .trim()
152+ // .replace(/\u001bc/g, '');
153+
154+ // if (text) {
155+ // this.project.ui.writeLine(text);
156+ // }
157+
158+ // if (data.indexOf('Starting incremental compilation') !== -1) {
159+ // debugCompiler('tsc detected a file change');
160+ // this.willRebuild();
161+ // clearTimeout(this._pendingAutoresolve);
162+ // }
163+
164+ // if (data.indexOf('Compilation complete') !== -1) {
165+ // debugCompiler('rebuild completed');
166+
167+ // this.didSync();
168+
169+ // if (this._didAutoresolve) {
170+ // this._touchRebuildTrigger();
171+ // this.maxBuildCount++;
172+ // }
173+
174+ // clearTimeout(this._pendingAutoresolve);
175+ // this._didAutoresolve = false;
176+ // }
177+ // });
178+
179+ // tsc.stderr.on('data', data => {
180+ // this.project.ui.writeError(data.toString().trim());
181+ // });
146182 }
147183
148184 willRebuild ( ) {
0 commit comments