@@ -27,15 +27,15 @@ function normalizeGlobs(globs) {
2727 return globs ;
2828}
2929
30- module . exports = function ( globs , opts , cb ) {
30+ function watch ( globs , opts , cb ) {
3131 globs = normalizeGlobs ( globs ) ;
3232
3333 if ( typeof opts === 'function' ) {
3434 cb = opts ;
3535 opts = { } ;
3636 }
3737
38- opts = assign ( { } , opts ) ;
38+ opts = assign ( { } , watch . _defaultOptions , opts ) ;
3939 cb = cb || function ( ) { } ;
4040
4141 function resolveFilepath ( filepath ) {
@@ -57,14 +57,6 @@ module.exports = function (globs, opts, cb) {
5757 }
5858 globs = globs . map ( resolveGlob ) ;
5959
60- opts . events = opts . events || [ 'add' , 'change' , 'unlink' ] ;
61-
62- if ( opts . ignoreInitial === undefined ) {
63- opts . ignoreInitial = true ;
64- }
65-
66- opts . readDelay = opts . readDelay || 10 ;
67-
6860 var baseForced = Boolean ( opts . base ) ;
6961 var outputStream = new Duplex ( { objectMode : true , allowHalfOpen : true } ) ;
7062
@@ -164,4 +156,16 @@ module.exports = function (globs, opts, cb) {
164156 }
165157
166158 return outputStream ;
159+ }
160+
161+ // This is not part of the public API as that would lead to global state (singleton) pollution,
162+ // and allow unexpected interference between unrelated modules that make use of gulp-watch.
163+ // This can be useful for unit tests and root application configuration, though.
164+ // Avoid modifying gulp-watch's default options inside a library/reusable package, please.
165+ watch . _defaultOptions = {
166+ events : [ 'add' , 'change' , 'unlink' ] ,
167+ ignoreInitial : true ,
168+ readDelay : 10
167169} ;
170+
171+ module . exports = watch ;
0 commit comments