DEV: Use fewer threads when watching for SCSS changes (#12393)
This commit is contained in:
parent
2a18b0b07e
commit
de05c410c5
|
@ -27,67 +27,62 @@ module Stylesheet
|
|||
end
|
||||
|
||||
def start
|
||||
|
||||
Thread.new do
|
||||
begin
|
||||
while true
|
||||
worker_loop
|
||||
end
|
||||
rescue => e
|
||||
STDERR.puts "CSS change notifier crashed #{e}"
|
||||
STDERR.puts "CSS change notifier crashed \n#{e}"
|
||||
start
|
||||
end
|
||||
end
|
||||
|
||||
root = Rails.root.to_s
|
||||
|
||||
listener_opts = { ignore: /xxxx/ }
|
||||
listener_opts = { ignore: /xxxx/, only: /\.(css|scss)$/ }
|
||||
listener_opts[:force_polling] = true if ENV['FORCE_POLLING']
|
||||
|
||||
@paths.each do |watch|
|
||||
Thread.new do
|
||||
begin
|
||||
plugins_paths = Dir.glob("#{Rails.root}/plugins/*").map do |file|
|
||||
if File.symlink?(file)
|
||||
File.expand_path(File.readlink(file), "#{Rails.root}/plugins")
|
||||
else
|
||||
file
|
||||
end
|
||||
end.compact
|
||||
|
||||
listener = Listen.to("#{root}/#{watch}", listener_opts) do |modified, added, _|
|
||||
paths = [modified, added].flatten
|
||||
paths.compact!
|
||||
paths.map! do |long|
|
||||
plugin_name = nil
|
||||
plugins_paths.each do |plugin_path|
|
||||
if long.include?("#{plugin_path}/")
|
||||
plugin_name = File.basename(plugin_path)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
target = nil
|
||||
target_match = long.match(/admin|desktop|mobile|publish/)
|
||||
if target_match&.length
|
||||
target = target_match[0]
|
||||
end
|
||||
|
||||
{
|
||||
basename: File.basename(long),
|
||||
target: target,
|
||||
plugin_name: plugin_name
|
||||
}
|
||||
end
|
||||
|
||||
process_change(paths)
|
||||
Thread.new do
|
||||
begin
|
||||
plugins_paths = Dir.glob("#{Rails.root}/plugins/*").map do |file|
|
||||
if File.symlink?(file)
|
||||
File.expand_path(File.readlink(file), "#{Rails.root}/plugins")
|
||||
else
|
||||
file
|
||||
end
|
||||
rescue => e
|
||||
STDERR.puts "Failed to listen for CSS changes at: #{watch}\n#{e}"
|
||||
end.compact
|
||||
|
||||
listener = Listen.to(*@paths, listener_opts) do |modified, added, _|
|
||||
paths = [modified, added].flatten
|
||||
paths.compact!
|
||||
paths.map! do |long|
|
||||
plugin_name = nil
|
||||
plugins_paths.each do |plugin_path|
|
||||
if long.include?("#{plugin_path}/")
|
||||
plugin_name = File.basename(plugin_path)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
target = nil
|
||||
target_match = long.match(/admin|desktop|mobile|publish/)
|
||||
if target_match&.length
|
||||
target = target_match[0]
|
||||
end
|
||||
|
||||
{
|
||||
basename: File.basename(long),
|
||||
target: target,
|
||||
plugin_name: plugin_name
|
||||
}
|
||||
end
|
||||
|
||||
process_change(paths)
|
||||
end
|
||||
listener.start
|
||||
sleep
|
||||
rescue => e
|
||||
STDERR.puts "Failed to listen for CSS changes: \n#{e}"
|
||||
end
|
||||
listener.start
|
||||
sleep
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -138,9 +133,7 @@ module Stylesheet
|
|||
|
||||
def process_change(paths)
|
||||
paths.each do |path|
|
||||
if path[:basename] =~ /\.(css|scss)$/
|
||||
@queue.push path
|
||||
end
|
||||
@queue.push path
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue