From 56780fd5e6b6822f7b6871e13d915a86eac4bcf8 Mon Sep 17 00:00:00 2001 From: Alex Ghiculescu Date: Sun, 18 Jun 2023 21:40:14 +1000 Subject: [PATCH] Respect `config.enable_reloading` (#172) Currently importmap-rails adds some file watchers even when `enable_reloading` is false. This PR fixes that. --- lib/importmap/engine.rb | 12 +++++++----- lib/importmap/map.rb | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/importmap/engine.rb b/lib/importmap/engine.rb index 2828868..c991b9c 100755 --- a/lib/importmap/engine.rb +++ b/lib/importmap/engine.rb @@ -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) diff --git a/lib/importmap/map.rb b/lib/importmap/map.rb index f87bfc7..ac0885e 100644 --- a/lib/importmap/map.rb +++ b/lib/importmap/map.rb @@ -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)