Patch around seemingly invalid logic in Listen v3

feature/livereload-locales-data
Thomas Reynolds 2015-08-17 14:28:15 -07:00
parent 226099d64e
commit 9886e04a95
2 changed files with 30 additions and 2 deletions

View File

@ -124,9 +124,12 @@ module Middleman
]
# config.rb
files.watch :reload,
watcher = files.watch :reload,
path: root,
only: match_against
# Hack around node_modules in root.
watcher.listener.ignore(/^node_modules/)
end
end

View File

@ -4,6 +4,26 @@ require 'middleman-core/contracts'
require 'middleman-core/contracts'
require 'backports/2.0.0/enumerable/lazy'
# Monkey patch Listen silencer so `only` works on directories too
module Listen
class Silencer
# TODO: switch type and path places - and verify
def silenced?(relative_path, type)
path = relative_path.to_s
# if only_patterns && type == :file
# return true unless only_patterns.any? { |pattern| path =~ pattern }
# end
if only_patterns
return !only_patterns.any? { |pattern| path =~ pattern }
end
ignore_patterns.any? { |pattern| path =~ pattern }
end
end
end
module Middleman
# The default source watcher implementation. Watches a directory on disk
# and responds to events on changes.
@ -29,6 +49,9 @@ module Middleman
Contract Hash
attr_reader :options
# Reference to lower level listener
attr_reader :listener
# Construct a new SourceWatcher
#
# @param [Middleman::Sources] parent The parent collection.
@ -138,9 +161,11 @@ module Middleman
config[:latency] = @latency if @latency
@listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change))
@listener.start
@listener.ignore(/^\.sass-cache/)
@listener.only(@only) unless @only.empty?
@listener.start
end
# Stop the listener.