Patch around seemingly invalid logic in Listen v3
This commit is contained in:
parent
226099d64e
commit
9886e04a95
|
@ -124,9 +124,12 @@ module Middleman
|
||||||
]
|
]
|
||||||
|
|
||||||
# config.rb
|
# config.rb
|
||||||
files.watch :reload,
|
watcher = files.watch :reload,
|
||||||
path: root,
|
path: root,
|
||||||
only: match_against
|
only: match_against
|
||||||
|
|
||||||
|
# Hack around node_modules in root.
|
||||||
|
watcher.listener.ignore(/^node_modules/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,26 @@ require 'middleman-core/contracts'
|
||||||
require 'middleman-core/contracts'
|
require 'middleman-core/contracts'
|
||||||
require 'backports/2.0.0/enumerable/lazy'
|
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
|
module Middleman
|
||||||
# The default source watcher implementation. Watches a directory on disk
|
# The default source watcher implementation. Watches a directory on disk
|
||||||
# and responds to events on changes.
|
# and responds to events on changes.
|
||||||
|
@ -29,6 +49,9 @@ module Middleman
|
||||||
Contract Hash
|
Contract Hash
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
|
|
||||||
|
# Reference to lower level listener
|
||||||
|
attr_reader :listener
|
||||||
|
|
||||||
# Construct a new SourceWatcher
|
# Construct a new SourceWatcher
|
||||||
#
|
#
|
||||||
# @param [Middleman::Sources] parent The parent collection.
|
# @param [Middleman::Sources] parent The parent collection.
|
||||||
|
@ -138,9 +161,11 @@ module Middleman
|
||||||
config[:latency] = @latency if @latency
|
config[:latency] = @latency if @latency
|
||||||
|
|
||||||
@listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change))
|
@listener = ::Listen.to(@directory.to_s, config, &method(:on_listener_change))
|
||||||
@listener.start
|
|
||||||
|
|
||||||
|
@listener.ignore(/^\.sass-cache/)
|
||||||
@listener.only(@only) unless @only.empty?
|
@listener.only(@only) unless @only.empty?
|
||||||
|
|
||||||
|
@listener.start
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stop the listener.
|
# Stop the listener.
|
||||||
|
|
Loading…
Reference in a new issue