Skip to content

Commit f8219bf

Browse files
committed
Prevent ES Module processing from affecting non-RailsAdmin assets
Refs. #3488
1 parent 8891c28 commit f8219bf

File tree

7 files changed

+31
-43
lines changed

7 files changed

+31
-43
lines changed

lib/rails_admin/engine.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class Engine < Rails::Engine
4343
rails_admin/application.css
4444
]
4545
app.config.assets.paths << RailsAdmin::Engine.root.join('src')
46-
require 'rails_admin/support/esmodule_preprocessor'
47-
Sprockets.register_preprocessor 'application/javascript', RailsAdmin::ESModulePreprocessor
46+
require 'rails_admin/support/es_module_processor'
47+
Sprockets.register_bundle_processor 'application/javascript', RailsAdmin::Support::ESModuleProcessor
4848
when :importmap
4949
self.importmap = Importmap::Map.new.draw(app.root.join('config/importmap.rails_admin.rb'))
5050
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
module RailsAdmin
4+
module Support
5+
class ESModuleProcessor
6+
def self.instance
7+
@instance ||= new
8+
end
9+
10+
def self.call(input)
11+
instance.call(input)
12+
end
13+
14+
def initialize; end
15+
16+
def call(input)
17+
return unless input[:name] == 'rails_admin/application'
18+
19+
input[:data].gsub(/^((?:import|export) .+)$/) { "// #{Regexp.last_match(1)}" }
20+
end
21+
end
22+
end
23+
end

lib/rails_admin/support/esmodule_preprocessor.rb

-37
This file was deleted.

spec/dummy_app/app/assets/javascripts/application.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
1111
// GO AFTER THE REQUIRES BELOW.
1212
//
13-
//= require rails-ujs
13+
//= require rails-ujs.esm
1414
//= require turbo
15-
//= require_tree .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= depend_on_asset('rails-ujs').to_s.gsub(/context = this/, 'context = (this || globalThis)') %>

spec/dummy_app/app/views/layouts/application.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<%= javascript_importmap_tags %>
1010
<% else %>
1111
<%= stylesheet_link_tag "application", media: "all" %>
12-
<%= javascript_include_tag "application" %>
12+
<%= javascript_include_tag "application", type: 'module' %>
1313
<% end %>
1414
<%= csrf_meta_tags %>
1515
</head>

src/rails_admin/i18n.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default {
1+
var I18n = {
22
locale: null,
33
translations: null,
44
init(locale, translations) {
@@ -14,3 +14,5 @@ export default {
1414
return this.translations[key] || humanize;
1515
},
1616
};
17+
18+
export { I18n as default };

0 commit comments

Comments
 (0)