@@ -16,8 +16,24 @@ module.exports = function compile(project, tsOptions, callbacks) {
1616 noEmit : false
1717 } , tsOptions ) ;
1818
19+ let configPath = ts . findConfigFile ( './' , ts . sys . fileExists , 'tsconfig.json' ) ;
20+ let createProgram = ts . createEmitAndSemanticDiagnosticsBuilderProgram ;
21+ let host = ts . createWatchCompilerHost (
22+ configPath ,
23+ fullOptions ,
24+ buildWatchHooks ( ts . sys ) ,
25+ createProgram ,
26+ callbacks . reportDiagnostic ,
27+ callbacks . reportWatchStatus
28+ ) ;
29+
30+ return ts . createWatchProgram ( host ) ;
31+ } ;
32+
33+ function buildWatchHooks ( sys ) {
1934 let watchedFiles = new Map ( ) ;
20- let sys = Object . assign ( { } , ts . sys , {
35+
36+ return Object . assign ( { } , sys , {
2137 watchFile ( file , callback ) {
2238 watchedFiles . set ( file , callback ) ;
2339
@@ -31,27 +47,19 @@ module.exports = function compile(project, tsOptions, callbacks) {
3147 watchDirectory ( dir , callback ) {
3248 if ( ! fs . existsSync ( dir ) ) return ;
3349
34- let ignored = / \. \w + \/ | d i s t \/ | n o d e _ m o d u l e s \/ | t m p \/ / ;
50+ let ignored = / \/ ( \. . * ? | d i s t | n o d e _ m o d u l e s | t m p ) \/ / ;
3551 let watcher = chokidar . watch ( dir , { ignored } ) ;
3652
37- let invoke = ( type , path ) => {
53+ watcher . on ( 'all' , ( type , path ) => {
3854 path = path . replace ( / \\ / g, '/' ) ; // Normalize Windows
3955 if ( type === 'add' ) {
4056 callback ( path ) ;
4157 } else if ( watchedFiles . has ( path ) ) {
4258 watchedFiles . get ( path ) ( path , type === 'change' ? 1 : 2 ) ;
4359 }
44- } ;
45-
46- watcher . on ( 'all' , invoke ) ;
60+ } ) ;
4761
4862 return watcher ;
4963 }
5064 } ) ;
51-
52- let configPath = ts . findConfigFile ( './' , ts . sys . fileExists , 'tsconfig.json' ) ;
53- let createProgram = ts . createEmitAndSemanticDiagnosticsBuilderProgram ;
54- let host = ts . createWatchCompilerHost ( configPath , fullOptions , sys , createProgram , callbacks . reportDiagnostic , callbacks . reportWatchStatus ) ;
55-
56- return ts . createWatchProgram ( host ) ;
57- } ;
65+ }
0 commit comments