Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ PATH
actionpack (>= 7.0.0)
activesupport (>= 7.0.0)
rack
railties (>= 7.0.0)

GEM
remote: https://rubygems.org/
Expand Down
2 changes: 1 addition & 1 deletion lib/propshaft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ module Propshaft
require "propshaft/assembly"
require "propshaft/errors"
require "propshaft/helper"
require "propshaft/railtie"
require "propshaft/railtie" if defined?(Rails::Railtie)
4 changes: 2 additions & 2 deletions lib/propshaft/assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(config)
end

def load_path
@load_path ||= Propshaft::LoadPath.new(config.paths, compilers: compilers, version: config.version)
@load_path ||= Propshaft::LoadPath.new(config.paths, compilers: compilers, version: config.version, file_watcher: config.file_watcher)
end

def resolver
Expand Down Expand Up @@ -47,7 +47,7 @@ def compilers

def reveal(path_type = :logical_path)
path_type = path_type.presence_in(%i[ logical_path path ]) || raise(ArgumentError, "Unknown path_type: #{path_type}")

load_path.assets.collect do |asset|
asset.send(path_type)
end
Expand Down
15 changes: 13 additions & 2 deletions lib/propshaft/load_path.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
require "propshaft/asset"

class Propshaft::LoadPath
class NullFileWatcher # :nodoc:
def initialize(paths, files_to_watch, &block)
@block = block
end

def execute_if_updated
@block.call
end
end

attr_reader :paths, :compilers, :version

def initialize(paths = [], compilers:, version: nil)
def initialize(paths = [], compilers:, version: nil, file_watcher: nil)
@paths, @compilers, @version = dedup(paths), compilers, version
@file_watcher = file_watcher || NullFileWatcher
end

def find(asset_name)
Expand Down Expand Up @@ -46,7 +57,7 @@ def cache_sweeper
files_to_watch = Array(paths).collect { |dir| [ dir.to_s, exts_to_watch ] }.to_h
mutex = Mutex.new

Rails.application.config.file_watcher.new([], files_to_watch) do
@file_watcher.new([], files_to_watch) do
mutex.synchronize do
clear_cache
seed_cache
Expand Down
2 changes: 2 additions & 0 deletions lib/propshaft/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Railtie < ::Rails::Railtie
# Prioritize assets from within the application over assets of the same path from engines/gems.
config.assets.paths.sort_by!.with_index { |path, i| [path.to_s.start_with?(Rails.root.to_s) ? 0 : 1, i] }

config.assets.file_watcher ||= app.config.file_watcher

config.assets.relative_url_root ||= app.config.relative_url_root
config.assets.output_path ||=
Pathname.new(File.join(app.config.paths["public"].first, app.config.assets.prefix))
Expand Down
2 changes: 1 addition & 1 deletion lib/propshaft/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ def extract_path_and_digest(env)
end

def execute_cache_sweeper_if_updated
Rails.application.assets.load_path.cache_sweeper.execute_if_updated
@assembly.load_path.cache_sweeper.execute_if_updated
end
end
1 change: 0 additions & 1 deletion propshaft.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Gem::Specification.new do |s|
s.required_ruby_version = ">= 2.7.0"
s.add_dependency "actionpack", ">= 7.0.0"
s.add_dependency "activesupport", ">= 7.0.0"
s.add_dependency "railties", ">= 7.0.0"
s.add_dependency "rack"

s.files = Dir["lib/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
Expand Down