Skip to content

Commit

Permalink
refactor(server): refactoring of watcher (#3173)
Browse files Browse the repository at this point in the history
  • Loading branch information
lusarz authored and johnjbarton committed Oct 11, 2018
1 parent c921010 commit 871a1c9
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions lib/watcher.js
Expand Up @@ -26,7 +26,7 @@ function watchPatterns (patterns, watcher) {
pathsToWatch = Array.from(pathsToWatch)
// watch only common parents, no sub paths
pathsToWatch.forEach((path) => {
if (!pathsToWatch.some((p) => p !== path && path.substr(0, p.length + 1) === p + DIR_SEP)) {
if (!pathsToWatch.some((p) => p !== path && path.startsWith(p + DIR_SEP))) {
watcher.add(path)
log.debug('Watching "%s"', path)
}
Expand All @@ -39,22 +39,18 @@ function checkAnyPathMatch (patterns, path) {

function createIgnore (patterns, excludes) {
return function (path, stat) {
if (!stat || stat.isDirectory()) {
if (stat && !stat.isDirectory()) {
return !checkAnyPathMatch(patterns, path) || checkAnyPathMatch(excludes, path)
} else {
return false
}

return !checkAnyPathMatch(patterns, path) || checkAnyPathMatch(excludes, path)
}
}

function getWatchedPatterns (patterns) {
return patterns
.reduce((array, pattern) => {
if (pattern.watched) {
array.push(pattern.pattern)
}
return array
}, [])
.filter((pattern) => pattern.watched)
.map((pattern) => pattern.pattern)
}

exports.watch = function (patterns, excludes, fileList, usePolling, emitter) {
Expand Down

0 comments on commit 871a1c9

Please sign in to comment.