From e2f6f2f8228efc47951e4c276d068517a7ca3437 Mon Sep 17 00:00:00 2001 From: brunosimon Date: Mon, 21 Nov 2016 13:47:31 +0100 Subject: [PATCH] :bug: Exclude files in hidden folder --- test-folder/vendors/.test/excluded-file.txt | 1 + watcher/watcher.class.js | 43 +++++++++------------ 2 files changed, 20 insertions(+), 24 deletions(-) create mode 100644 test-folder/vendors/.test/excluded-file.txt diff --git a/test-folder/vendors/.test/excluded-file.txt b/test-folder/vendors/.test/excluded-file.txt new file mode 100644 index 0000000..e381795 --- /dev/null +++ b/test-folder/vendors/.test/excluded-file.txt @@ -0,0 +1 @@ +This file shouldn't be include diff --git a/watcher/watcher.class.js b/watcher/watcher.class.js index e044fd3..df8be13 100644 --- a/watcher/watcher.class.js +++ b/watcher/watcher.class.js @@ -79,11 +79,30 @@ class Watcher */ set_watcher() { + // Create ignored regex + let regexs = [], + Minimatch = require( 'minimatch' ).Minimatch + + for( let _exclude_key in this.options.exclude ) + { + let _exclude = this.options.exclude[ _exclude_key ], + minimatch = new Minimatch( _exclude, { dot: true } ), + regex = '' + minimatch.makeRe() + + regex = regex.replace( '/^', '' ) + regex = regex.replace( '$/', '' ) + + regexs.push( regex ) + } + + let regex = new RegExp( regexs.join( '|' ) ) + // Set up this.watcher = chokidar.watch( process.cwd(), { // ignored : /[\/\\]\./, + ignored : regex, ignoreInitial: true } ) @@ -105,18 +124,6 @@ class Watcher file.can_read = false } - // Test exclusion - for( let _exclude_key in this.options.exclude ) - { - // Set up - let _exclude = this.options.exclude[ _exclude_key ], - relative_path = _path.replace( process.cwd() + '/', '' ) - - // Match excluded path - if( minimatch( relative_path, _exclude ) ) - return - } - // Retrieve stats fs.stat( _path, ( error, stats ) => { @@ -159,18 +166,6 @@ class Watcher file.can_read = false } - // Test exclusion - for( let _exclude_key in this.options.exclude ) - { - // Set up - let _exclude = this.options.exclude[ _exclude_key ], - relative_path = _path.replace( process.cwd() + '/', '' ) - - // Match excluded path - if( minimatch( relative_path, _exclude ) ) - return - } - // Retrieve stats fs.stat( _path, ( error, stats ) => {