@@ -4,18 +4,35 @@ exports.getTscProcess = getTscProcess;
4
4
var spawn = require ( 'child_process' ) . spawn ;
5
5
var fs = require ( 'fs' ) ;
6
6
var path = require ( 'path' ) ;
7
+ var semver = require ( 'semver' ) ;
7
8
var tsc = null ;
8
9
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
+
9
26
function runTypeScriptCompiler ( logger , projectDir , options ) {
10
27
return new Promise ( function ( resolve , reject ) {
11
28
options = options || { } ;
12
29
13
30
var peerTypescriptPath = path . join ( __dirname , '../../typescript' ) ;
14
31
var tscPath = path . join ( peerTypescriptPath , 'lib/tsc.js' ) ;
32
+ var typeScriptVersion = getTypeScriptVersion ( peerTypescriptPath ) ;
33
+
15
34
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 } ` ) ;
19
36
} else {
20
37
throw Error ( 'TypeScript installation local to project was not found. Install by executing `npm install typescript`.' ) ;
21
38
}
@@ -35,13 +52,21 @@ function runTypeScriptCompiler(logger, projectDir, options) {
35
52
nodeArgs . push ( '--inlineSourceMap' , '--inlineSources' ) ;
36
53
}
37
54
55
+ if ( this . shouldPreserveWatchOutput ( typeScriptVersion ) ) {
56
+ nodeArgs . push ( '--preserveWatchOutput' ) ;
57
+ }
58
+
38
59
logger . trace ( process . execPath , nodeArgs . join ( ' ' ) ) ;
39
60
tsc = spawn ( process . execPath , nodeArgs ) ;
40
61
41
62
var isResolved = false ;
42
63
tsc . stdout . on ( 'data' , function ( data ) {
43
64
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
+ }
45
70
if ( options . watch && stringData . toLowerCase ( ) . indexOf ( "compilation complete. watching for file changes." ) !== - 1 && ! isResolved ) {
46
71
isResolved = true ;
47
72
resolve ( ) ;
0 commit comments