File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ module Importmap
7
7
class Engine < ::Rails ::Engine
8
8
config . importmap = ActiveSupport ::OrderedOptions . new
9
9
config . importmap . sweep_cache = Rails . env . development? || Rails . env . test?
10
+ config . importmap . rescuable_asset_errors = [ ]
10
11
11
12
config . autoload_once_paths = %W( #{ root } /app/helpers )
12
13
@@ -49,5 +50,11 @@ class Engine < ::Rails::Engine
49
50
helper Importmap ::ImportmapTagsHelper
50
51
end
51
52
end
53
+
54
+ initializer 'importmap.rescuable_asset_errors' do |app |
55
+ if defined? ( Sprockets ::Rails )
56
+ app . config . importmap . rescuable_asset_errors << Sprockets ::Rails ::Helper ::AssetNotFound
57
+ end
58
+ end
52
59
end
53
60
end
Original file line number Diff line number Diff line change @@ -87,13 +87,21 @@ def clear_cache
87
87
@cached_preloaded_module_paths = nil
88
88
end
89
89
90
+ def rescuable_asset_error? ( error )
91
+ Rails . application . config . importmap . rescuable_asset_errors . any? { |e | error . is_a? ( e ) }
92
+ end
93
+
90
94
def resolve_asset_paths ( paths , resolver :)
91
95
paths . transform_values do |mapping |
92
96
begin
93
97
resolver . asset_path ( mapping . path )
94
- rescue Sprockets ::Rails ::Helper ::AssetNotFound
95
- Rails . logger . warn "Importmap skipped missing path: #{ mapping . path } "
96
- nil
98
+ rescue => e
99
+ if rescuable_asset_error? ( e )
100
+ Rails . logger . warn "Importmap skipped missing path: #{ mapping . path } "
101
+ nil
102
+ else
103
+ raise e
104
+ end
97
105
end
98
106
end . compact
99
107
end
You can’t perform that action at this time.
0 commit comments