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

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

View file

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