File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ var wp = new Watchpack({
4949 // ignored: "string" - a glob pattern for files or folders that should not be watched
5050 // ignored: ["string", "string"] - multiple glob patterns that should be ignored
5151 // ignored: /regexp/ - a regular expression for files or folders that should not be watched
52+ // ignored: (entry) => boolean - an arbirary function which must return truthy to ignore an entry
5253 // All subdirectories are ignored too
5354});
5455
Original file line number Diff line number Diff line change @@ -31,13 +31,15 @@ const stringToRegexp = ignored => {
3131 return matchingStart ;
3232} ;
3333
34- const ignoredToRegexp = ignored => {
34+ const ignoredToRegexpLike = ignored => {
3535 if ( Array . isArray ( ignored ) ) {
3636 return new RegExp ( ignored . map ( i => stringToRegexp ( i ) ) . join ( "|" ) ) ;
3737 } else if ( typeof ignored === "string" ) {
3838 return new RegExp ( stringToRegexp ( ignored ) ) ;
3939 } else if ( ignored instanceof RegExp ) {
4040 return ignored ;
41+ } else if ( ignored instanceof Function ) {
42+ return { test : ignored } ;
4143 } else if ( ignored ) {
4244 throw new Error ( `Invalid option for 'ignored': ${ ignored } ` ) ;
4345 } else {
@@ -48,7 +50,7 @@ const ignoredToRegexp = ignored => {
4850const normalizeOptions = options => {
4951 return {
5052 followSymlinks : ! ! options . followSymlinks ,
51- ignored : ignoredToRegexp ( options . ignored ) ,
53+ ignored : ignoredToRegexpLike ( options . ignored ) ,
5254 poll : options . poll
5355 } ;
5456} ;
Original file line number Diff line number Diff line change @@ -118,6 +118,32 @@ describe("Watchpack", function() {
118118 } ) ;
119119 } ) ;
120120
121+ it ( "should not watch a single ignored file (function)" , function ( done ) {
122+ var w = new Watchpack ( {
123+ aggregateTimeout : 300 ,
124+ ignored : ( entry ) => entry . includes ( "a" )
125+ } ) ;
126+ var changeEvents = 0 ;
127+ var aggregatedEvents = 0 ;
128+ w . on ( "change" , ( ) => {
129+ changeEvents ++ ;
130+ } ) ;
131+ w . on ( "aggregated" , ( ) => {
132+ aggregatedEvents ++ ;
133+ } ) ;
134+ w . watch ( [ path . join ( fixtures , "a" ) ] , [ ] ) ;
135+ testHelper . tick ( ( ) => {
136+ testHelper . file ( "a" ) ;
137+ testHelper . tick ( 1000 , ( ) => {
138+ changeEvents . should . be . eql ( 0 ) ;
139+ aggregatedEvents . should . be . eql ( 0 ) ;
140+ testHelper . getNumberOfWatchers ( ) . should . be . eql ( 0 ) ;
141+ w . close ( ) ;
142+ done ( ) ;
143+ } ) ;
144+ } ) ;
145+ } ) ;
146+
121147 it ( "should watch multiple files" , function ( done ) {
122148 var w = new Watchpack ( {
123149 aggregateTimeout : 1000
You can’t perform that action at this time.
0 commit comments