From 8df11f5459c88357ccad4260c7bdae615b43603b Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Fri, 10 Sep 2021 13:32:35 -0400 Subject: [PATCH] Dummy app: Depend on `turbo-rails` through importmap (#231) * Depend on `importmap-rails` in dummy app When running tests against a dummy Rails application, use [importmap-rails][]. The contents of this commit were generated by following the [Installation][] instructions. [importmap-rails]: https://github.com/rails/importmap-rails/tree/v0.5.1 [Installation]: https://github.com/rails/importmap-rails/tree/v0.5.1#installation * Depend on `turbo-rails` through importmap The contents of this commit were generated by following the [Installation](./README.md#installation) instructions. * Depend on `@rails/actioncable` through importmap Replace the `package.json` development dependency with an importmap entry. * Remove Webpacker JavaScript entrypoints Removes Webpacker-specific helpers from the Application layout in favor of the importmap-generated helpers. --- Gemfile | 4 ++++ Gemfile.lock | 3 +++ test/dummy/app/assets/config/manifest.js | 1 + test/dummy/app/javascript/application.js | 2 ++ test/dummy/app/javascript/packs/application.js | 0 test/dummy/app/views/layouts/application.html.erb | 2 +- test/dummy/bin/importmap | 4 ++++ test/dummy/config/importmap.rb | 8 ++++++++ 8 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/dummy/app/javascript/application.js delete mode 100644 test/dummy/app/javascript/packs/application.js create mode 100755 test/dummy/bin/importmap create mode 100644 test/dummy/config/importmap.rb diff --git a/Gemfile b/Gemfile index 9d2c0764..001e9325 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,10 @@ gem 'rake' gem 'byebug' gem 'puma' +group :development, :test do + gem 'importmap-rails' +end + group :test do gem 'capybara' gem 'rexml' diff --git a/Gemfile.lock b/Gemfile.lock index 76711bcd..790fb160 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -86,6 +86,8 @@ GEM activesupport (>= 5.0) i18n (1.8.10) concurrent-ruby (~> 1.0) + importmap-rails (0.5.1) + rails (>= 6.0.0) loofah (2.12.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -168,6 +170,7 @@ PLATFORMS DEPENDENCIES byebug capybara + importmap-rails puma rake rexml diff --git a/test/dummy/app/assets/config/manifest.js b/test/dummy/app/assets/config/manifest.js index 59181933..4c9ab805 100644 --- a/test/dummy/app/assets/config/manifest.js +++ b/test/dummy/app/assets/config/manifest.js @@ -1,2 +1,3 @@ //= link_tree ../images //= link_directory ../stylesheets .css +//= link_tree ../../javascript .js diff --git a/test/dummy/app/javascript/application.js b/test/dummy/app/javascript/application.js new file mode 100644 index 00000000..e524d166 --- /dev/null +++ b/test/dummy/app/javascript/application.js @@ -0,0 +1,2 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails +import "@hotwired/turbo-rails" diff --git a/test/dummy/app/javascript/packs/application.js b/test/dummy/app/javascript/packs/application.js deleted file mode 100644 index e69de29b..00000000 diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb index 10dee8ce..3d26ca03 100644 --- a/test/dummy/app/views/layouts/application.html.erb +++ b/test/dummy/app/views/layouts/application.html.erb @@ -6,7 +6,7 @@ <%= stylesheet_link_tag 'application', media: 'all' %> <%= yield :head %> - <%= javascript_include_tag "turbo", type: "module" %> + <%= javascript_importmap_tags %> diff --git a/test/dummy/bin/importmap b/test/dummy/bin/importmap new file mode 100755 index 00000000..36502ab1 --- /dev/null +++ b/test/dummy/bin/importmap @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require_relative "../config/application" +require "importmap/commands" diff --git a/test/dummy/config/importmap.rb b/test/dummy/config/importmap.rb new file mode 100644 index 00000000..79adc1e0 --- /dev/null +++ b/test/dummy/config/importmap.rb @@ -0,0 +1,8 @@ +# Use direct uploads for Active Storage (remember to import "@rails/activestorage" in your application.js) +# pin "@rails/activestorage", to: "activestorage.esm.js" + +# Use node modules from a JavaScript CDN by running ./bin/importmap + +pin "application" +pin "@hotwired/turbo-rails", to: "turbo.js" +pin "@rails/actioncable", to: "actioncable.esm.js"