@@ -4,18 +4,35 @@ exports.getTscProcess = getTscProcess;
44var spawn = require ( 'child_process' ) . spawn ;
55var fs = require ( 'fs' ) ;
66var path = require ( 'path' ) ;
7+ var semver = require ( 'semver' ) ;
78var tsc = null ;
89
10+ function getTypeScriptVersion ( typeScriptPath ) {
11+ try {
12+ return require ( path . join ( typeScriptPath , 'package.json' ) ) . version ;
13+ } catch ( err ) { }
14+
15+ return null ;
16+ }
17+
18+ function shouldPreserveWatchOutput ( typeScriptVersion ) {
19+ try {
20+ return semver . gte ( typeScriptVersion , "2.8.1" ) ;
21+ } catch ( err ) { }
22+
23+ return false ;
24+ }
25+
926function runTypeScriptCompiler ( logger , projectDir , options ) {
1027 return new Promise ( function ( resolve , reject ) {
1128 options = options || { } ;
1229
1330 var peerTypescriptPath = path . join ( __dirname , '../../typescript' ) ;
1431 var tscPath = path . join ( peerTypescriptPath , 'lib/tsc.js' ) ;
32+ var typeScriptVersion = getTypeScriptVersion ( peerTypescriptPath ) ;
33+
1534 if ( fs . existsSync ( tscPath ) ) {
16- try {
17- logger . info ( 'Found peer TypeScript ' + require ( path . join ( peerTypescriptPath , 'package.json' ) ) . version ) ;
18- } catch ( err ) { }
35+ logger . info ( `Found peer TypeScript ${ typeScriptVersion } ` ) ;
1936 } else {
2037 throw Error ( 'TypeScript installation local to project was not found. Install by executing `npm install typescript`.' ) ;
2138 }
@@ -35,13 +52,21 @@ function runTypeScriptCompiler(logger, projectDir, options) {
3552 nodeArgs . push ( '--inlineSourceMap' , '--inlineSources' ) ;
3653 }
3754
55+ if ( this . shouldPreserveWatchOutput ( typeScriptVersion ) ) {
56+ nodeArgs . push ( '--preserveWatchOutput' ) ;
57+ }
58+
3859 logger . trace ( process . execPath , nodeArgs . join ( ' ' ) ) ;
3960 tsc = spawn ( process . execPath , nodeArgs ) ;
4061
4162 var isResolved = false ;
4263 tsc . stdout . on ( 'data' , function ( data ) {
4364 var stringData = data . toString ( ) ;
44- logger . info ( stringData ) ;
65+ // Prevent console clear. Fixed the behaviour for typescript 2.7.1 and 2.7.2. Should be deleted after dropping support for 2.7.x version.
66+ // https://github.com/Microsoft/TypeScript/blob/master/src/compiler/sys.ts#L623
67+ if ( stringData !== "\x1Bc" ) {
68+ logger . info ( stringData ) ;
69+ }
4570 if ( options . watch && stringData . toLowerCase ( ) . indexOf ( "compilation complete. watching for file changes." ) !== - 1 && ! isResolved ) {
4671 isResolved = true ;
4772 resolve ( ) ;
0 commit comments