@@ -2,7 +2,7 @@ import { build } from './build';
2
2
import { BuildContext , TaskInfo } from './util/interfaces' ;
3
3
import { BuildError , Logger } from './util/logger' ;
4
4
import { fillConfigDefaults , generateContext , getUserConfigFile , replacePathVars , setIonicEnvironment } from './util/config' ;
5
- import { normalize } from 'path' ;
5
+ import { join , normalize } from 'path' ;
6
6
import * as chalk from 'chalk' ;
7
7
import * as chokidar from 'chokidar' ;
8
8
@@ -61,40 +61,34 @@ function startWatcher(index: number, watcher: Watcher, context: BuildContext, wa
61
61
return ;
62
62
}
63
63
64
- let taskPromise = Promise . resolve ( ) ;
65
- let nextTask : any = null ;
66
-
67
64
const chokidarWatcher = chokidar . watch ( < any > watcher . paths , watcher . options ) ;
68
65
69
66
chokidarWatcher . on ( 'all' , ( event : string , filePath : string ) => {
70
67
setIonicEnvironment ( context . isProd ) ;
71
68
69
+ filePath = join ( context . rootDir , filePath ) ;
70
+
71
+ context . isUpdate = true ;
72
+ context . fileChanged = filePath ;
73
+
72
74
Logger . debug ( `watch callback start, id: ${ watchCount } , isProd: ${ context . isProd } , event: ${ event } , path: ${ filePath } ` ) ;
73
75
74
76
function taskDone ( ) {
75
77
Logger . info ( chalk . green ( 'watch ready' ) ) ;
76
78
}
77
79
78
- nextTask = watcher . callback . bind ( null , event , filePath , context ) ;
79
- taskPromise . then ( ( ) => {
80
- Logger . debug ( `watch callback complete, id: ${ watchCount } , isProd: ${ context . isProd } , event: ${ event } , path: ${ filePath } ` ) ;
81
- taskPromise = nextTask ( ) ;
82
- taskPromise
83
- . then ( taskDone , taskDone )
84
- . catch ( taskDone ) ;
85
- nextTask = null ;
86
- watchCount ++ ;
87
-
88
- } ) . catch ( err => {
89
- Logger . debug ( `watch callback error, id: ${ watchCount } , isProd: ${ context . isProd } , event: ${ event } , path: ${ filePath } ` ) ;
90
- Logger . debug ( `${ err } ` ) ;
91
- taskPromise = nextTask ( ) ;
92
- taskPromise
93
- . then ( taskDone , taskDone )
94
- . catch ( taskDone ) ;
95
- nextTask = null ;
96
- watchCount ++ ;
97
- } ) ;
80
+ watcher . callback ( event , filePath , context )
81
+ . then ( ( ) => {
82
+ Logger . debug ( `watch callback complete, id: ${ watchCount } , isProd: ${ context . isProd } , event: ${ event } , path: ${ filePath } ` ) ;
83
+ watchCount ++ ;
84
+ taskDone ( ) ;
85
+ } )
86
+ . catch ( err => {
87
+ Logger . debug ( `watch callback error, id: ${ watchCount } , isProd: ${ context . isProd } , event: ${ event } , path: ${ filePath } ` ) ;
88
+ Logger . debug ( `${ err } ` ) ;
89
+ watchCount ++ ;
90
+ taskDone ( ) ;
91
+ } ) ;
98
92
} ) ;
99
93
100
94
chokidarWatcher . on ( 'ready' , ( ) => {
@@ -156,7 +150,7 @@ export interface Watcher {
156
150
cwd ?: string ;
157
151
} ;
158
152
callback ?: {
159
- ( event : string , filePath : string , context : BuildContext ) : void ;
153
+ ( event : string , filePath : string , context : BuildContext ) : Promise < any > ;
160
154
} ;
161
155
}
162
156
0 commit comments