@@ -16,6 +16,7 @@ function watchify (b, opts) {
16
16
var delay = typeof opts . delay === 'number' ? opts . delay : 600 ;
17
17
var changingDeps = { } ;
18
18
var pending = false ;
19
+ var updating = false ;
19
20
20
21
var wopts = { persistent : true } ;
21
22
if ( opts . ignoreWatch ) {
@@ -93,6 +94,11 @@ function watchify (b, opts) {
93
94
watchFile ( mfile , dep ) ;
94
95
} ) ;
95
96
} ) ;
97
+ b . on ( 'bundle' , function ( bundle ) {
98
+ bundle . on ( 'error' , onend ) ;
99
+ bundle . on ( 'end' , onend ) ;
100
+ function onend ( ) { updating = false }
101
+ } ) ;
96
102
97
103
function watchFile ( file , dep ) {
98
104
dep = dep || file ;
@@ -119,20 +125,25 @@ function watchify (b, opts) {
119
125
function invalidate ( id ) {
120
126
if ( cache ) delete cache [ id ] ;
121
127
if ( pkgcache ) delete pkgcache [ id ] ;
128
+ changingDeps [ id ] = true ;
129
+ if ( updating ) return ;
130
+
122
131
if ( fwatchers [ id ] ) {
123
132
fwatchers [ id ] . forEach ( function ( w ) {
124
133
w . close ( ) ;
125
134
} ) ;
126
135
delete fwatchers [ id ] ;
127
136
delete fwatcherFiles [ id ] ;
128
137
}
129
- changingDeps [ id ] = true ;
130
138
131
139
// wait for the disk/editor to quiet down first:
132
140
if ( ! pending ) setTimeout ( function ( ) {
133
141
pending = false ;
134
- b . emit ( 'update' , Object . keys ( changingDeps ) ) ;
135
- changingDeps = { } ;
142
+ if ( ! updating ) {
143
+ b . emit ( 'update' , Object . keys ( changingDeps ) ) ;
144
+ updating = true ;
145
+ changingDeps = { } ;
146
+ }
136
147
} , delay ) ;
137
148
pending = true ;
138
149
}
0 commit comments