11import { makePromiseKit } from '@endo/promise-kit' ;
22import { Logger } from '@ocap/utils' ;
33import { watch } from 'chokidar' ;
4- import type { FSWatcher , MatchFunction } from 'chokidar' ;
4+ import type { FSWatcher } from 'chokidar' ;
55import { unlink } from 'fs/promises' ;
66import { resolve } from 'path' ;
77
@@ -56,9 +56,6 @@ export const makeWatchEvents = (
5656 error : ( error : Error ) => throwError ( error ) ,
5757} ) ;
5858
59- export const filterOnlyJsFiles : MatchFunction = ( file , stats ) =>
60- ( stats ?. isFile ( ) ?? false ) && file . endsWith ( '.js' ) ;
61-
6259/**
6360 * Start a watcher that bundles `.js` files in the target dir.
6461 *
@@ -77,14 +74,14 @@ export function watchDir(dir: string, logger: Logger): WatchDirReturn {
7774 const { reject : throwError , promise : errorPromise } = makePromiseKit < never > ( ) ;
7875
7976 let watcher = watch ( resolvedDir , {
80- ignoreInitial : true ,
81- ignored : [
82- '**/node_modules/**' ,
83- '**/*.test.js' ,
84- '**/*.test.ts' ,
85- '**/*.bundle' ,
86- filterOnlyJsFiles ,
87- ] ,
77+ ignoreInitial : false ,
78+ ignored : ( file , stats ) =>
79+ // Ignore node_modules
80+ file . includes ( 'node_modules' ) ||
81+ // Watch directories (and the files they contain)
82+ ( ( stats ?. isFile ( ) ?? false ) &&
83+ // But only trigger on JS files
84+ ! file . endsWith ( '.js' ) ) ,
8885 } ) ;
8986
9087 const events = makeWatchEvents ( watcher , readyResolve , throwError , logger ) ;
0 commit comments