@@ -51,7 +51,7 @@ class FSWatcher extends EventEmitter {
5151
5252 assert ( typeof options === 'object' ) ;
5353
54- const { persistent, recursive, signal, encoding, ignore } = options ;
54+ const { persistent, recursive, signal, encoding, ignore, throwIfNoEntry } = options ;
5555
5656 // TODO(anonrig): Add non-recursive support to non-native-watcher for IBMi & AIX support.
5757 if ( recursive != null ) {
@@ -66,6 +66,10 @@ class FSWatcher extends EventEmitter {
6666 validateAbortSignal ( signal , 'options.signal' ) ;
6767 }
6868
69+ if ( throwIfNoEntry != null ) {
70+ validateBoolean ( throwIfNoEntry , 'options.throwIfNoEntry' ) ;
71+ }
72+
6973 if ( encoding != null ) {
7074 // This is required since on macOS and Windows it throws ERR_INVALID_ARG_VALUE
7175 if ( typeof encoding !== 'string' ) {
@@ -76,7 +80,7 @@ class FSWatcher extends EventEmitter {
7680 validateIgnoreOption ( ignore , 'options.ignore' ) ;
7781 this . #ignoreMatcher = createIgnoreMatcher ( ignore ) ;
7882
79- this . #options = { persistent, recursive, signal, encoding } ;
83+ this . #options = { persistent, recursive, signal, encoding, throwIfNoEntry } ;
8084 }
8185
8286 close ( ) {
@@ -222,7 +226,7 @@ class FSWatcher extends EventEmitter {
222226 this . #watchFolder( filename ) ;
223227 }
224228 } catch ( error ) {
225- if ( error . code === 'ENOENT' ) {
229+ if ( this . #options . throwIfNoEntry !== false && error . code === 'ENOENT' ) {
226230 error . filename = filename ;
227231 throw error ;
228232 }
0 commit comments