@@ -6,10 +6,9 @@ import rollup, { setWatcher } from '../rollup/index';
66import {
77 InputOptions ,
88 ModuleJSON ,
9- OutputChunk ,
109 OutputOptions ,
1110 RollupBuild ,
12- RollupSingleFileBuild ,
11+ RollupWatcher ,
1312 RollupWatchOptions
1413} from '../rollup/types' ;
1514import ensureArray from '../utils/ensureArray' ;
@@ -20,27 +19,38 @@ import { addTask, deleteTask } from './fileWatchers';
2019
2120const DELAY = 200 ;
2221
23- export class Watcher extends EventEmitter {
22+ export class Watcher {
23+ emitter : RollupWatcher ;
2424 private buildTimeout : NodeJS . Timer ;
2525 private running : boolean ;
2626 private rerun : boolean = false ;
2727 private tasks : Task [ ] ;
2828 private succeeded : boolean = false ;
2929
3030 constructor ( configs : RollupWatchOptions [ ] ) {
31- super ( ) ;
31+ this . emitter = new class extends EventEmitter implements RollupWatcher {
32+ close : ( ) => void ;
33+ constructor ( close : ( ) => void ) {
34+ super ( ) ;
35+ this . close = close ;
36+ }
37+ } ( this . close . bind ( this ) ) ;
3238 this . tasks = ensureArray ( configs ) . map ( config => new Task ( this , config ) ) ;
3339 this . running = true ;
3440 process . nextTick ( ( ) => this . run ( ) ) ;
3541 }
3642
43+ emit ( event : string , value : any ) {
44+ this . emitter . emit ( event , value ) ;
45+ }
46+
3747 close ( ) {
3848 if ( this . buildTimeout ) clearTimeout ( this . buildTimeout ) ;
3949 this . tasks . forEach ( task => {
4050 task . close ( ) ;
4151 } ) ;
4252
43- this . removeAllListeners ( ) ;
53+ this . emitter . removeAllListeners ( ) ;
4454 }
4555
4656 invalidate ( ) {
@@ -194,7 +204,7 @@ export class Task {
194204 } ) ;
195205 }
196206
197- setWatcher ( this . watcher ) ;
207+ setWatcher ( this . watcher . emitter ) ;
198208 return rollup ( options )
199209 . then ( result => {
200210 if ( this . closed ) return ;
@@ -218,11 +228,11 @@ export class Task {
218228
219229 return Promise . all (
220230 this . outputs . map ( output => {
221- return < Promise < OutputChunk | Record < string , OutputChunk > > > result . write ( output ) ;
231+ return result . write ( output ) ;
222232 } )
223233 ) . then ( ( ) => result ) ;
224234 } )
225- . then ( ( result : RollupSingleFileBuild | RollupBuild ) => {
235+ . then ( ( result : RollupBuild ) => {
226236 this . watcher . emit ( 'event' , {
227237 code : 'BUNDLE_END' ,
228238 input : this . inputOptions . input ,
@@ -266,5 +276,5 @@ export class Task {
266276}
267277
268278export default function watch ( configs : RollupWatchOptions [ ] ) {
269- return new Watcher ( configs ) ;
279+ return new Watcher ( configs ) . emitter ;
270280}
0 commit comments