Merge pull request #1218 from bhollis/ignore
Prevent the file watcher from recursively enumerating into paths that it should ignore
This commit is contained in:
commit
4efefedb6f
3 changed files with 33 additions and 26 deletions
|
@ -7,12 +7,12 @@ module Middleman
|
||||||
module FileWatcher
|
module FileWatcher
|
||||||
|
|
||||||
IGNORE_LIST = [
|
IGNORE_LIST = [
|
||||||
/^bin\//,
|
/^bin(\/|$)/,
|
||||||
/^\.bundle\//,
|
/^\.bundle(\/|$)/,
|
||||||
/^vendor\//,
|
/^vendor(\/|$)/,
|
||||||
/^\.sass-cache\//,
|
/^\.sass-cache(\/|$)/,
|
||||||
/^\.cache\//,
|
/^\.cache(\/|$)/,
|
||||||
/^\.git\//,
|
/^\.git(\/|$)/,
|
||||||
/^\.gitignore$/,
|
/^\.gitignore$/,
|
||||||
/\.DS_Store/,
|
/\.DS_Store/,
|
||||||
/^\.rbenv-.*$/,
|
/^\.rbenv-.*$/,
|
||||||
|
@ -38,7 +38,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
app.after_configuration do
|
app.after_configuration do
|
||||||
config[:file_watcher_ignore] << %r{^#{config[:build_dir]}\/}
|
config[:file_watcher_ignore] << %r{^#{config[:build_dir]}(\/|$)}
|
||||||
end
|
end
|
||||||
|
|
||||||
# After config, load everything else
|
# After config, load everything else
|
||||||
|
@ -99,7 +99,6 @@ module Middleman
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def did_change(path)
|
def did_change(path)
|
||||||
path = Pathname(path)
|
path = Pathname(path)
|
||||||
return if ignored?(path)
|
|
||||||
logger.debug "== File Change: #{path}"
|
logger.debug "== File Change: #{path}"
|
||||||
@known_paths << path
|
@known_paths << path
|
||||||
self.run_callbacks(path, :changed)
|
self.run_callbacks(path, :changed)
|
||||||
|
@ -111,7 +110,6 @@ module Middleman
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def did_delete(path)
|
def did_delete(path)
|
||||||
path = Pathname(path)
|
path = Pathname(path)
|
||||||
return if ignored?(path)
|
|
||||||
logger.debug "== File Deletion: #{path}"
|
logger.debug "== File Deletion: #{path}"
|
||||||
@known_paths.delete(path)
|
@known_paths.delete(path)
|
||||||
self.run_callbacks(path, :deleted)
|
self.run_callbacks(path, :deleted)
|
||||||
|
@ -131,7 +129,7 @@ module Middleman
|
||||||
glob = (path + '**').to_s
|
glob = (path + '**').to_s
|
||||||
subset = @known_paths.select { |p| p.fnmatch(glob) }
|
subset = @known_paths.select { |p| p.fnmatch(glob) }
|
||||||
|
|
||||||
::Middleman::Util.all_files_under(path).each do |filepath|
|
::Middleman::Util.all_files_under(path, &method(:ignored?)).each do |filepath|
|
||||||
next if only_new && subset.include?(filepath)
|
next if only_new && subset.include?(filepath)
|
||||||
|
|
||||||
subset.delete(filepath)
|
subset.delete(filepath)
|
||||||
|
@ -156,7 +154,6 @@ module Middleman
|
||||||
@known_paths.include?(p)
|
@known_paths.include?(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
# Whether this path is ignored
|
# Whether this path is ignored
|
||||||
# @param [Pathname] path
|
# @param [Pathname] path
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
|
@ -165,6 +162,8 @@ module Middleman
|
||||||
app.config[:file_watcher_ignore].any? { |r| path =~ r }
|
app.config[:file_watcher_ignore].any? { |r| path =~ r }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
# Notify callbacks for a file given an array of callbacks
|
# Notify callbacks for a file given an array of callbacks
|
||||||
#
|
#
|
||||||
# @param [Pathname] path The file that was changed
|
# @param [Pathname] path The file that was changed
|
||||||
|
|
|
@ -133,10 +133,12 @@ module Middleman
|
||||||
@webrick.stop
|
@webrick.stop
|
||||||
else
|
else
|
||||||
added_and_modified.each do |path|
|
added_and_modified.each do |path|
|
||||||
|
next if app.files.ignored?(path)
|
||||||
app.files.did_change(path)
|
app.files.did_change(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
removed.each do |path|
|
removed.each do |path|
|
||||||
|
next if app.files.ignored?(path)
|
||||||
app.files.did_delete(path)
|
app.files.did_delete(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -113,21 +113,27 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get a recusive list of files inside a set of paths.
|
# Get a recusive list of files inside a path.
|
||||||
# Works with symlinks.
|
# Works with symlinks.
|
||||||
#
|
#
|
||||||
# @param paths Some paths string or Pathname
|
# @param path Some path string or Pathname
|
||||||
# @return [Array] An array of filenames
|
# @param ignore A proc/block that returns true if a given path should be ignored - if a path
|
||||||
def all_files_under(*paths)
|
# is ignored, nothing below it will be searched either.
|
||||||
paths.flat_map do |p|
|
# @return [Array<Pathname>] An array of Pathnames for each file (no directories)
|
||||||
path = Pathname(p)
|
def all_files_under(path, &ignore)
|
||||||
|
path = Pathname(path)
|
||||||
|
|
||||||
if path.directory?
|
return [] if ignore && ignore.call(path)
|
||||||
all_files_under(*path.children)
|
|
||||||
elsif path.file?
|
if path.directory?
|
||||||
path
|
path.children.flat_map do |child|
|
||||||
end
|
all_files_under(child, &ignore)
|
||||||
end.compact
|
end.compact
|
||||||
|
elsif path.file?
|
||||||
|
[path]
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Given a source path (referenced either absolutely or relatively)
|
# Given a source path (referenced either absolutely or relatively)
|
||||||
|
|
Loading…
Add table
Reference in a new issue