Fix slow server boot. It was recursing through node_modules and .git on initial boot

feature/manifest
Thomas Reynolds 2016-01-28 16:45:54 -08:00
parent 8c27d9a2e7
commit 598d72480f
3 changed files with 15 additions and 8 deletions

View File

@ -0,0 +1,2 @@
var a = jQuery.css("h1", "font-size");
console.log(a);

View File

@ -49,6 +49,8 @@ module Middleman
# Reference to lower level listener
attr_reader :listener
IGNORED_DIRECTORIES = %w(.git node_modules .sass-cache)
# Construct a new SourceWatcher
#
# @param [Middleman::Sources] parent The parent collection.
@ -182,7 +184,7 @@ module Middleman
Contract ArrayOf[Pathname]
def find_new_files!
new_files = ::Middleman::Util.all_files_under(@directory.to_s)
new_files = ::Middleman::Util.all_files_under(@directory.to_s, &method(:should_not_recurse?))
.reject { |p| @files.key?(p) }
update(new_files, []).flatten.map { |s| s[:full_path] }
@ -193,7 +195,7 @@ module Middleman
# @return [void]
Contract ArrayOf[Pathname]
def poll_once!
updated = ::Middleman::Util.all_files_under(@directory.to_s)
updated = ::Middleman::Util.all_files_under(@directory.to_s, &method(:should_not_recurse?))
removed = @files.keys.reject { |p| updated.include?(p) }
result = update(updated, removed)
@ -217,6 +219,11 @@ module Middleman
protected
Contract Pathname => Bool
def should_not_recurse?(p)
IGNORED_DIRECTORIES.include?(p.basename.to_s)
end
# The `listen` gem callback.
#
# @param [Array] modified List of modified files.

View File

@ -156,16 +156,14 @@ module Middleman
def all_files_under(path, &ignore)
path = Pathname(path)
if path.directory?
if ignore && ignore.call(path)
[]
elsif path.directory?
path.children.flat_map do |child|
all_files_under(child, &ignore)
end.compact
elsif path.file?
if block_given? && yield(path)
[]
else
[path]
end
[path]
else
[]
end