@@ -185,25 +185,27 @@ async function bundless(
185
185
// watching for watch mode
186
186
logger . event ( `Start watching ${ opts . configProvider . input } directory...` ) ;
187
187
188
+ // debounce transform to combine multiple changes
189
+ const handleTransform = ( ( ) => {
190
+ const pendingSet = new Set < string > ( ) ;
191
+ const startTransform = lodash . debounce ( ( ) => {
192
+ transformFiles ( [ ...pendingSet ] , opts ) ;
193
+ pendingSet . clear ( ) ;
194
+ } , WATCH_DEBOUNCE_STEP ) ;
195
+
196
+ return ( filePath : string ) => {
197
+ pendingSet . add ( filePath ) ;
198
+ startTransform ( ) ;
199
+ } ;
200
+ } ) ( ) ;
188
201
const watcher = chokidar
189
202
. watch ( opts . configProvider . input , {
190
203
cwd : opts . cwd ,
191
204
ignoreInitial : true ,
192
205
ignored : DEFAULT_BUNDLESS_IGNORES ,
193
206
} )
194
- . on ( 'add' , ( rltFilePath ) => {
195
- transformFiles ( [ rltFilePath ] , opts ) ;
196
- } )
197
- . on (
198
- 'change' ,
199
- lodash . debounce (
200
- ( filePath : string ) => {
201
- transformFiles ( [ filePath ] , opts ) ;
202
- } ,
203
- WATCH_DEBOUNCE_STEP ,
204
- { leading : true , trailing : false } ,
205
- ) ,
206
- )
207
+ . on ( 'add' , handleTransform )
208
+ . on ( 'change' , handleTransform )
207
209
. on ( 'unlink' , ( rltFilePath ) => {
208
210
const isTsFile = / \. t s x ? $ / . test ( rltFilePath ) ;
209
211
const config = opts . configProvider . getConfigForFile ( rltFilePath ) ;
0 commit comments