Skip to content

Commit

Permalink
Respect config.enable_reloading (#172)
Browse files Browse the repository at this point in the history
Currently importmap-rails adds some file watchers even when `enable_reloading` is false. This PR fixes that.
  • Loading branch information
ghiculescu authored Jun 18, 2023
1 parent c7b9e13 commit 56780fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions lib/importmap/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ class Engine < ::Rails::Engine
end

initializer "importmap.reloader" do |app|
Importmap::Reloader.new.tap do |reloader|
reloader.execute
app.reloaders << reloader
app.reloader.to_run { reloader.execute }
unless app.config.cache_classes
Importmap::Reloader.new.tap do |reloader|
reloader.execute
app.reloaders << reloader
app.reloader.to_run { reloader.execute }
end
end
end

initializer "importmap.cache_sweeper" do |app|
if app.config.importmap.sweep_cache
if app.config.importmap.sweep_cache && !app.config.cache_classes
app.config.importmap.cache_sweepers << app.root.join("app/javascript")
app.config.importmap.cache_sweepers << app.root.join("vendor/javascript")
app.importmap.cache_sweeper(watches: app.config.importmap.cache_sweepers)
Expand Down
2 changes: 1 addition & 1 deletion lib/importmap/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def digest(resolver:)
Digest::SHA1.hexdigest(to_json(resolver: resolver).to_s)
end

# Returns an instance ActiveSupport::EventedFileUpdateChecker configured to clear the cache of the map
# Returns an instance of ActiveSupport::EventedFileUpdateChecker configured to clear the cache of the map
# when the directories passed on initialization via `watches:` have changes. This is used in development
# and test to ensure the map caches are reset when javascript files are changed.
def cache_sweeper(watches: nil)
Expand Down

0 comments on commit 56780fd

Please sign in to comment.