From d06f4f34bd5d9964e0bf57dc4926aa4cb9227866 Mon Sep 17 00:00:00 2001 From: Bram Jetten Date: Wed, 11 Aug 2021 22:39:41 +0200 Subject: [PATCH] Fix importmaps using importmap-rails (#772) * Fix importmaps using importmap-rails * Update to importmap-rails * Updated gemspec --- Gemfile.lock | 27 ++++++++------ app/assets/config/spina/manifest.js | 1 + app/assets/javascripts/spina/application.js | 2 + .../attachment_picker_controller.js | 2 +- .../spina/controllers/autofocus_controller.js | 2 +- .../spina/controllers/button_controller.js | 2 +- .../spina/controllers/confetti_controller.js | 4 +- .../spina/controllers/confirm_controller.js | 2 +- .../controllers/delegate_click_controller.js | 2 +- .../spina/controllers/exists_controller.js | 2 +- .../spina/controllers/form_controller.js | 4 +- .../spina/controllers/hotkeys_controller.js | 4 +- .../image_collection_controller.js | 4 +- .../controllers/image_fade_in_controller.js | 2 +- .../controllers/infinite_scroll_controller.js | 2 +- .../controllers/loading_button_controller.js | 2 +- .../controllers/media_picker_controller.js | 2 +- .../media_picker_modal_controller.js | 2 +- .../spina/controllers/modal_controller.js | 2 +- .../controllers/navigation_controller.js | 2 +- .../controllers/parent_pages_controller.js | 2 +- .../spina/controllers/repeater_controller.js | 4 +- .../select_placeholder_controller.js | 2 +- .../controllers/selectable_controller.js | 2 +- .../spina/controllers/shortcuts_controller.js | 2 +- .../spina/controllers/sortable_controller.js | 6 +-- .../spina/controllers/switch_controller.js | 2 +- .../spina/controllers/tabs_controller.js | 2 +- .../spina/controllers/toggle_controller.js | 2 +- .../spina/controllers/trix_controller.js | 2 +- .../spina/controllers/unique_id_controller.js | 2 +- .../javascripts/spina/importmap.json.erb | 5 --- .../spina/libraries/stimulus-reveal@1.2.4.js | 2 +- app/helpers/spina/spina_helper.rb | 13 +++---- .../layouts/spina/admin/application.html.erb | 10 ++--- lib/spina.rb | 6 ++- lib/spina/engine.rb | 15 ++++++-- lib/spina/importmap_helper.rb | 37 ------------------- lib/spina/railtie.rb | 2 +- spina.gemspec | 7 ++-- 40 files changed, 83 insertions(+), 114 deletions(-) create mode 100644 app/assets/javascripts/spina/application.js delete mode 100644 app/assets/javascripts/spina/importmap.json.erb delete mode 100644 lib/spina/importmap_helper.rb diff --git a/Gemfile.lock b/Gemfile.lock index 765939abf..275fa3243 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,15 +8,16 @@ PATH bcrypt breadcrumbs_on_rails image_processing + importmap-rails (>= 0.1.1) jsonapi-serializer kaminari - mobility (= 1.1.3) + mobility (>= 1.1.3) pg rack-rewrite (>= 1.5.0) rails (>= 6.0) sass-rails - stimulus-rails - turbo-rails + stimulus-rails (>= 0.3.0) + turbo-rails (>= 0.7.0) view_component (~> 2.32) GEM @@ -103,13 +104,15 @@ GEM factory_bot (6.2.0) activesupport (>= 5.0.0) ffi (1.15.3) - globalid (0.4.2) - activesupport (>= 4.2.0) + globalid (0.5.2) + activesupport (>= 5.0) i18n (1.8.10) concurrent-ruby (~> 1.0) image_processing (1.12.1) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) + importmap-rails (0.1.1) + rails (>= 6.0.0) json (2.5.1) jsonapi-serializer (2.2.0) activesupport (>= 4.2) @@ -129,7 +132,7 @@ GEM addressable (~> 2.7) letter_opener (1.7.0) launchy (~> 2.2) - loofah (2.10.0) + loofah (2.12.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -138,7 +141,7 @@ GEM method_source (1.0.0) mini_magick (4.11.0) mini_mime (1.1.0) - mini_portile2 (2.5.3) + mini_portile2 (2.6.1) minitest (5.14.4) minitest-reporters (1.4.3) ansi @@ -149,9 +152,9 @@ GEM i18n (>= 0.6.10, < 2) request_store (~> 1.0) mocha (1.13.0) - nio4r (2.5.7) - nokogiri (1.11.7) - mini_portile2 (~> 2.5.0) + nio4r (2.5.8) + nokogiri (1.12.3) + mini_portile2 (~> 2.6.1) racc (~> 1.4) pg (1.2.3) pry (0.14.1) @@ -225,11 +228,11 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - stimulus-rails (0.2.4) + stimulus-rails (0.3.0) rails (>= 6.0.0) thor (1.1.0) tilt (2.0.10) - turbo-rails (0.6.0) + turbo-rails (0.7.0) rails (>= 6.0.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) diff --git a/app/assets/config/spina/manifest.js b/app/assets/config/spina/manifest.js index 77fa12bcc..cb1b6fa1f 100644 --- a/app/assets/config/spina/manifest.js +++ b/app/assets/config/spina/manifest.js @@ -6,3 +6,4 @@ //= link spina/application.css +//= link spina/application.js \ No newline at end of file diff --git a/app/assets/javascripts/spina/application.js b/app/assets/javascripts/spina/application.js new file mode 100644 index 000000000..d6b19cede --- /dev/null +++ b/app/assets/javascripts/spina/application.js @@ -0,0 +1,2 @@ +import "@hotwired/turbo-rails" +import "@hotwired/stimulus-autoloader" diff --git a/app/assets/javascripts/spina/controllers/attachment_picker_controller.js b/app/assets/javascripts/spina/controllers/attachment_picker_controller.js index 67f70dfe6..843740496 100644 --- a/app/assets/javascripts/spina/controllers/attachment_picker_controller.js +++ b/app/assets/javascripts/spina/controllers/attachment_picker_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/autofocus_controller.js b/app/assets/javascripts/spina/controllers/autofocus_controller.js index fe0ce028e..77b8ad5ee 100644 --- a/app/assets/javascripts/spina/controllers/autofocus_controller.js +++ b/app/assets/javascripts/spina/controllers/autofocus_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/button_controller.js b/app/assets/javascripts/spina/controllers/button_controller.js index b2b176ac6..511404495 100644 --- a/app/assets/javascripts/spina/controllers/button_controller.js +++ b/app/assets/javascripts/spina/controllers/button_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/confetti_controller.js b/app/assets/javascripts/spina/controllers/confetti_controller.js index 81e6ae531..7cdbffaf4 100644 --- a/app/assets/javascripts/spina/controllers/confetti_controller.js +++ b/app/assets/javascripts/spina/controllers/confetti_controller.js @@ -1,5 +1,5 @@ -import { Controller } from "stimulus" -import confetti from "canvas-confetti" +import { Controller } from "@hotwired/stimulus" +import confetti from "libraries/canvas-confetti" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/confirm_controller.js b/app/assets/javascripts/spina/controllers/confirm_controller.js index 1c79232aa..b4b2f59c6 100644 --- a/app/assets/javascripts/spina/controllers/confirm_controller.js +++ b/app/assets/javascripts/spina/controllers/confirm_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/delegate_click_controller.js b/app/assets/javascripts/spina/controllers/delegate_click_controller.js index 6e4d0f16d..c8597ba3f 100644 --- a/app/assets/javascripts/spina/controllers/delegate_click_controller.js +++ b/app/assets/javascripts/spina/controllers/delegate_click_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/exists_controller.js b/app/assets/javascripts/spina/controllers/exists_controller.js index 755e8a1b3..1e73eaa43 100644 --- a/app/assets/javascripts/spina/controllers/exists_controller.js +++ b/app/assets/javascripts/spina/controllers/exists_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/form_controller.js b/app/assets/javascripts/spina/controllers/form_controller.js index e795cf9cf..8021a6b26 100644 --- a/app/assets/javascripts/spina/controllers/form_controller.js +++ b/app/assets/javascripts/spina/controllers/form_controller.js @@ -1,5 +1,5 @@ -import { Controller } from "stimulus" -import formRequestSubmitPolyfill from 'form-request-submit-polyfill' +import { Controller } from "@hotwired/stimulus" +import formRequestSubmitPolyfill from "libraries/form-request-submit-polyfill" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/hotkeys_controller.js b/app/assets/javascripts/spina/controllers/hotkeys_controller.js index fd063ab81..39c0fff77 100644 --- a/app/assets/javascripts/spina/controllers/hotkeys_controller.js +++ b/app/assets/javascripts/spina/controllers/hotkeys_controller.js @@ -1,5 +1,5 @@ -import { Controller } from "stimulus" -import hotkeys from "hotkeys" +import { Controller } from "@hotwired/stimulus" +import hotkeys from "libraries/hotkeys" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/image_collection_controller.js b/app/assets/javascripts/spina/controllers/image_collection_controller.js index 57df71f88..32e6352b1 100644 --- a/app/assets/javascripts/spina/controllers/image_collection_controller.js +++ b/app/assets/javascripts/spina/controllers/image_collection_controller.js @@ -1,5 +1,5 @@ -import { Controller } from "stimulus" -import Sortable from "sortablejs" +import { Controller } from "@hotwired/stimulus" +import Sortable from "libraries/sortablejs" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/image_fade_in_controller.js b/app/assets/javascripts/spina/controllers/image_fade_in_controller.js index b2488d23c..ae7795db5 100644 --- a/app/assets/javascripts/spina/controllers/image_fade_in_controller.js +++ b/app/assets/javascripts/spina/controllers/image_fade_in_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/infinite_scroll_controller.js b/app/assets/javascripts/spina/controllers/infinite_scroll_controller.js index eae35a1ce..496be9190 100644 --- a/app/assets/javascripts/spina/controllers/infinite_scroll_controller.js +++ b/app/assets/javascripts/spina/controllers/infinite_scroll_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/loading_button_controller.js b/app/assets/javascripts/spina/controllers/loading_button_controller.js index 1277924c2..d785fbe03 100644 --- a/app/assets/javascripts/spina/controllers/loading_button_controller.js +++ b/app/assets/javascripts/spina/controllers/loading_button_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/media_picker_controller.js b/app/assets/javascripts/spina/controllers/media_picker_controller.js index eeb2e90f6..9aeac2257 100644 --- a/app/assets/javascripts/spina/controllers/media_picker_controller.js +++ b/app/assets/javascripts/spina/controllers/media_picker_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/media_picker_modal_controller.js b/app/assets/javascripts/spina/controllers/media_picker_modal_controller.js index fb5ef3508..776767cab 100644 --- a/app/assets/javascripts/spina/controllers/media_picker_modal_controller.js +++ b/app/assets/javascripts/spina/controllers/media_picker_modal_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/modal_controller.js b/app/assets/javascripts/spina/controllers/modal_controller.js index ac3453506..440709e70 100644 --- a/app/assets/javascripts/spina/controllers/modal_controller.js +++ b/app/assets/javascripts/spina/controllers/modal_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/navigation_controller.js b/app/assets/javascripts/spina/controllers/navigation_controller.js index a74b522db..378c7e249 100644 --- a/app/assets/javascripts/spina/controllers/navigation_controller.js +++ b/app/assets/javascripts/spina/controllers/navigation_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/parent_pages_controller.js b/app/assets/javascripts/spina/controllers/parent_pages_controller.js index a1ebf239e..03569507c 100644 --- a/app/assets/javascripts/spina/controllers/parent_pages_controller.js +++ b/app/assets/javascripts/spina/controllers/parent_pages_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/repeater_controller.js b/app/assets/javascripts/spina/controllers/repeater_controller.js index 884e66bc3..ba8c2678c 100644 --- a/app/assets/javascripts/spina/controllers/repeater_controller.js +++ b/app/assets/javascripts/spina/controllers/repeater_controller.js @@ -1,5 +1,5 @@ -import { Controller } from "stimulus" -import Sortable from "sortablejs" +import { Controller } from "@hotwired/stimulus" +import Sortable from "libraries/sortablejs" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/select_placeholder_controller.js b/app/assets/javascripts/spina/controllers/select_placeholder_controller.js index c24cdb46b..7f3fd346b 100644 --- a/app/assets/javascripts/spina/controllers/select_placeholder_controller.js +++ b/app/assets/javascripts/spina/controllers/select_placeholder_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/assets/javascripts/spina/controllers/selectable_controller.js b/app/assets/javascripts/spina/controllers/selectable_controller.js index bed067c62..8373123c8 100644 --- a/app/assets/javascripts/spina/controllers/selectable_controller.js +++ b/app/assets/javascripts/spina/controllers/selectable_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/shortcuts_controller.js b/app/assets/javascripts/spina/controllers/shortcuts_controller.js index 4b3f121e0..3b96c8b8b 100644 --- a/app/assets/javascripts/spina/controllers/shortcuts_controller.js +++ b/app/assets/javascripts/spina/controllers/shortcuts_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/sortable_controller.js b/app/assets/javascripts/spina/controllers/sortable_controller.js index f258c3193..03184c87a 100644 --- a/app/assets/javascripts/spina/controllers/sortable_controller.js +++ b/app/assets/javascripts/spina/controllers/sortable_controller.js @@ -1,6 +1,6 @@ -import { Controller } from "stimulus" -import Sortable from "sortablejs" -import formRequestSubmitPolyfill from 'form-request-submit-polyfill' +import { Controller } from "@hotwired/stimulus" +import Sortable from "libraries/sortablejs" +import formRequestSubmitPolyfill from "libraries/form-request-submit-polyfill" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/switch_controller.js b/app/assets/javascripts/spina/controllers/switch_controller.js index 9c1a9e1cb..b48a31bc6 100644 --- a/app/assets/javascripts/spina/controllers/switch_controller.js +++ b/app/assets/javascripts/spina/controllers/switch_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/tabs_controller.js b/app/assets/javascripts/spina/controllers/tabs_controller.js index a556f9fb8..30d3f6cc6 100644 --- a/app/assets/javascripts/spina/controllers/tabs_controller.js +++ b/app/assets/javascripts/spina/controllers/tabs_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/toggle_controller.js b/app/assets/javascripts/spina/controllers/toggle_controller.js index d52204ddb..21879f754 100644 --- a/app/assets/javascripts/spina/controllers/toggle_controller.js +++ b/app/assets/javascripts/spina/controllers/toggle_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/trix_controller.js b/app/assets/javascripts/spina/controllers/trix_controller.js index 4748a49e3..8375cb363 100644 --- a/app/assets/javascripts/spina/controllers/trix_controller.js +++ b/app/assets/javascripts/spina/controllers/trix_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { static get targets() { diff --git a/app/assets/javascripts/spina/controllers/unique_id_controller.js b/app/assets/javascripts/spina/controllers/unique_id_controller.js index 6f14e16fb..36d860a8f 100644 --- a/app/assets/javascripts/spina/controllers/unique_id_controller.js +++ b/app/assets/javascripts/spina/controllers/unique_id_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { diff --git a/app/assets/javascripts/spina/importmap.json.erb b/app/assets/javascripts/spina/importmap.json.erb deleted file mode 100644 index 3fc610354..000000000 --- a/app/assets/javascripts/spina/importmap.json.erb +++ /dev/null @@ -1,5 +0,0 @@ -{ - "imports": { - <%= spina_importmap_with_stimulus_from Spina::Engine.root.join('app/assets/javascripts/spina/controllers'), Spina::Engine.root.join('app/assets/javascripts/spina/libraries') %> - } -} diff --git a/app/assets/javascripts/spina/libraries/stimulus-reveal@1.2.4.js b/app/assets/javascripts/spina/libraries/stimulus-reveal@1.2.4.js index a9d906e83..ef887e881 100644 --- a/app/assets/javascripts/spina/libraries/stimulus-reveal@1.2.4.js +++ b/app/assets/javascripts/spina/libraries/stimulus-reveal@1.2.4.js @@ -1,4 +1,4 @@ -import { Controller } from 'stimulus' +import { Controller } from '@hotwired/stimulus' /** * Stimulus controller to toggle element visibility diff --git a/app/helpers/spina/spina_helper.rb b/app/helpers/spina/spina_helper.rb index 608452c09..b22d132c2 100644 --- a/app/helpers/spina/spina_helper.rb +++ b/app/helpers/spina/spina_helper.rb @@ -1,16 +1,13 @@ module Spina::SpinaHelper - def spina_include_tags + def spina_importmap_tags safe_join [ - javascript_include_tag("stimulus/libraries/es-module-shims", type: "module"), - tag.script(type: "importmap-shim", src: asset_path("spina/importmap.json")), - javascript_include_tag("stimulus/libraries/stimulus", type: "module-shim"), - javascript_include_tag("spina/libraries/trix") + javascript_inline_importmap_tag(Spina.config.importmap.paths), + javascript_importmap_shim_tag, + javascript_include_tag("spina/libraries/trix"), + javascript_import_module_tag("application") ], "\n" end - def autoloader_include_tag - javascript_include_tag("stimulus/loaders/autoloader", type: "module-shim") - end end \ No newline at end of file diff --git a/app/views/layouts/spina/admin/application.html.erb b/app/views/layouts/spina/admin/application.html.erb index 0de9e1e57..0d0a7c7f2 100644 --- a/app/views/layouts/spina/admin/application.html.erb +++ b/app/views/layouts/spina/admin/application.html.erb @@ -10,19 +10,15 @@ Spina CMS - + <%= stylesheet_link_tag 'spina/application', data: {turbolinks_track: true} %> - - <%= turbo_include_tags %> - <%= spina_include_tags %> + + <%= spina_importmap_tags %> <%= yield(:head) %> <%= render Spina::Hooks::HookComponent.new(partial: "head") %> - - - <%= autoloader_include_tag %> diff --git a/lib/spina.rb b/lib/spina.rb index 2a646e1ae..80da73183 100644 --- a/lib/spina.rb +++ b/lib/spina.rb @@ -1,4 +1,3 @@ -require 'spina/importmap_helper' require 'spina/engine' require 'spina/admin_sectionable' require 'spina/railtie' @@ -21,6 +20,7 @@ module Spina :api_path, :authentication, :backend_path, + :importmap, :frontend_parent_controller, :disable_frontend_routes, :disable_decorator_load, @@ -50,6 +50,10 @@ module Spina # - config.queues.page_updates self.queues = ActiveSupport::InheritableOptions.new + # An importmap specifically meant for Spina + self.importmap = ActiveSupport::OrderedOptions.new + self.importmap.paths = Importmap::Paths.new + # Tailwind purging # Spina will by default purge all unused Tailwind classes by scanning # the files listed below. You probably don't want to override this in diff --git a/lib/spina/engine.rb b/lib/spina/engine.rb index 4294c287f..dba11f5ec 100644 --- a/lib/spina/engine.rb +++ b/lib/spina/engine.rb @@ -1,4 +1,5 @@ require 'sass-rails' +require 'importmap-rails' require 'turbo-rails' require 'stimulus-rails' require 'ancestry' @@ -37,11 +38,17 @@ class Engine < ::Rails::Engine Spina::Parts::Attachment ) end - - initializer "spina.helpers" do - Rails.application.config.assets.configure do |env| - env.context_class.class_eval { include Spina::ImportmapHelper } + + initializer "spina.importmap" do + Spina.config.importmap.paths.tap do |paths| + # Stimulus & Turbo + paths.asset "@hotwired/stimulus", path: "stimulus" + paths.asset "@hotwired/stimulus-autoloader", path: "stimulus-autoloader" + paths.asset "@hotwired/turbo-rails", path: "turbo" + + paths.assets_in Spina::Engine.root.join("app/assets/javascripts/spina"), append_base_path: true end end + end end diff --git a/lib/spina/importmap_helper.rb b/lib/spina/importmap_helper.rb deleted file mode 100644 index f18716e74..000000000 --- a/lib/spina/importmap_helper.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Spina - module ImportmapHelper - - def spina_importmap_with_stimulus_from(*paths) - [ %("stimulus": "#{asset_path("stimulus/libraries/stimulus")}"), spina_importmap_from(*paths) ].reject(&:blank?).join(",\n") - end - - def spina_importmap_from(*paths, prepend: "spina") - Array(paths).flat_map do |path| - if (absolute_path = absolute_root_of(path)).exist? - find_javascript_files_in_tree(absolute_path).collect do |filename| - module_filename = filename.relative_path_from(absolute_path) - module_name = importmap_module_name_from(module_filename) - module_path = asset_path("#{prepend}/" + absolute_path.basename.join(module_filename).to_s) - - %("#{module_name}": "#{module_path}") - end - end - end.compact.join(",\n") - end - - private - - # Strip off the extension and any versioning data for an absolute module name. - def importmap_module_name_from(filename) - filename.basename.to_s.remove(filename.extname).split("@").first - end - - def find_javascript_files_in_tree(path) - Dir[path.join("**/*.js{,m}")].collect { |file| Pathname.new(file) }.select(&:file?) - end - - def absolute_root_of(path) - (pathname = Pathname.new(path)).absolute? ? pathname : Rails.root.join(path) - end - end -end \ No newline at end of file diff --git a/lib/spina/railtie.rb b/lib/spina/railtie.rb index 71f4f0f9f..209104eb2 100644 --- a/lib/spina/railtie.rb +++ b/lib/spina/railtie.rb @@ -2,7 +2,7 @@ module Spina class Railtie < Rails::Railtie initializer "spina.assets.precompile" do |app| - app.config.assets.precompile += %w(spina/manifest spina/importmap.json) + app.config.assets.precompile += %w(spina/manifest) end ActiveSupport.on_load(:action_controller) do diff --git a/spina.gemspec b/spina.gemspec index 13822cb4e..2d854f6d9 100644 --- a/spina.gemspec +++ b/spina.gemspec @@ -33,12 +33,13 @@ Gem::Specification.new do |gem| gem.add_dependency 'ancestry' gem.add_dependency 'breadcrumbs_on_rails' gem.add_dependency 'kaminari' - gem.add_dependency 'mobility', '1.1.3' + gem.add_dependency 'mobility', '>= 1.1.3' gem.add_dependency 'rack-rewrite', '>= 1.5.0' gem.add_dependency 'attr_json' gem.add_dependency 'view_component', '~> 2.32' - gem.add_dependency 'turbo-rails' - gem.add_dependency 'stimulus-rails' + gem.add_dependency 'importmap-rails', '>= 0.1.1' + gem.add_dependency 'turbo-rails', '>= 0.7.0' + gem.add_dependency 'stimulus-rails', '>= 0.3.0' gem.add_dependency 'babosa' gem.add_dependency 'jsonapi-serializer' end