From 7f6b7214f53c3ebf7bbf09c22e637337708307cb Mon Sep 17 00:00:00 2001 From: Richard Macklin Date: Mon, 22 Nov 2021 09:14:13 -0800 Subject: [PATCH 1/5] Rename `rails_7` gemfile to `rails_7_sprockets` Rails 7 will formally support multiple asset pipelines, making sprockets optional: https://github.com/rails/rails/commit/fb1ab3460a676ce7def0819c2e92289ef2dcbe3b Since our rails 7 gemfile is still using sprockets, let's rename it to clarify that, which will also make the setup clearer when we add a separate `rails_7_propshaft` gemfile. --- .github/workflows/ci.yml | 2 +- Appraisals | 2 +- gemfiles/{rails_7.gemfile => rails_7_sprockets.gemfile} | 0 .../{rails_7.gemfile.lock => rails_7_sprockets.gemfile.lock} | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename gemfiles/{rails_7.gemfile => rails_7_sprockets.gemfile} (100%) rename gemfiles/{rails_7.gemfile.lock => rails_7_sprockets.gemfile.lock} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 910e34f..b89e669 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: - "3.0" gemfile: - Gemfile - - gemfiles/rails_7.gemfile + - gemfiles/rails_7_sprockets.gemfile continue-on-error: [ false ] name: ${{ format('Tests (Ruby {0}, {1})', matrix.ruby-version, matrix.gemfile) }} diff --git a/Appraisals b/Appraisals index 1837dd2..42717d4 100644 --- a/Appraisals +++ b/Appraisals @@ -1,4 +1,4 @@ -appraise "rails_7" do +appraise "rails_7_sprockets" do gem "rails", github: "rails/rails", ref: "main" gem "sprockets-rails" end diff --git a/gemfiles/rails_7.gemfile b/gemfiles/rails_7_sprockets.gemfile similarity index 100% rename from gemfiles/rails_7.gemfile rename to gemfiles/rails_7_sprockets.gemfile diff --git a/gemfiles/rails_7.gemfile.lock b/gemfiles/rails_7_sprockets.gemfile.lock similarity index 100% rename from gemfiles/rails_7.gemfile.lock rename to gemfiles/rails_7_sprockets.gemfile.lock From 3532fe36a2f2d20eaaa7d3c3742784012cc73f77 Mon Sep 17 00:00:00 2001 From: Richard Macklin Date: Mon, 22 Nov 2021 09:19:16 -0800 Subject: [PATCH 2/5] Use appraisals to generate a third gemfile that uses rails 7 & propshaft (generated via `bundle exec appraisal install`) We'll use this new Gemfile to test importmap-rails against a rails 7 application using the propshaft asset pipeline (instead of sprockets-rails) on CI. --- Appraisals | 5 + gemfiles/rails_7_propshaft.gemfile | 23 +++ gemfiles/rails_7_propshaft.gemfile.lock | 190 ++++++++++++++++++++++++ 3 files changed, 218 insertions(+) create mode 100644 gemfiles/rails_7_propshaft.gemfile create mode 100644 gemfiles/rails_7_propshaft.gemfile.lock diff --git a/Appraisals b/Appraisals index 42717d4..c0e9168 100644 --- a/Appraisals +++ b/Appraisals @@ -2,3 +2,8 @@ appraise "rails_7_sprockets" do gem "rails", github: "rails/rails", ref: "main" gem "sprockets-rails" end + +appraise "rails_7_propshaft" do + gem "rails", github: "rails/rails", ref: "main" + gem "propshaft" +end diff --git a/gemfiles/rails_7_propshaft.gemfile b/gemfiles/rails_7_propshaft.gemfile new file mode 100644 index 0000000..2c49e21 --- /dev/null +++ b/gemfiles/rails_7_propshaft.gemfile @@ -0,0 +1,23 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", ref: "main", git: "https://github.com/rails/rails.git" +gem "sqlite3" +gem "propshaft" + +group :development do + gem "appraisal" +end + +group :test do + gem "turbo-rails" + gem "stimulus-rails" + gem "byebug" + gem "rexml" + gem "capybara" + gem "selenium-webdriver" + gem "webdrivers" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_propshaft.gemfile.lock b/gemfiles/rails_7_propshaft.gemfile.lock new file mode 100644 index 0000000..fedad05 --- /dev/null +++ b/gemfiles/rails_7_propshaft.gemfile.lock @@ -0,0 +1,190 @@ +GIT + remote: https://github.com/rails/rails.git + revision: 6e1694275007b94b8112455ac53e8a345938376e + ref: main + specs: + actioncable (7.0.0.alpha2) + actionpack (= 7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (7.0.0.alpha2) + actionpack (= 7.0.0.alpha2) + activejob (= 7.0.0.alpha2) + activerecord (= 7.0.0.alpha2) + activestorage (= 7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + mail (>= 2.7.1) + actionmailer (7.0.0.alpha2) + actionpack (= 7.0.0.alpha2) + actionview (= 7.0.0.alpha2) + activejob (= 7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (7.0.0.alpha2) + actionview (= 7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + rack (~> 2.0, >= 2.2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.0.alpha2) + actionpack (= 7.0.0.alpha2) + activerecord (= 7.0.0.alpha2) + activestorage (= 7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + nokogiri (>= 1.8.5) + actionview (7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + globalid (>= 0.3.6) + activemodel (7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + activerecord (7.0.0.alpha2) + activemodel (= 7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + activestorage (7.0.0.alpha2) + actionpack (= 7.0.0.alpha2) + activejob (= 7.0.0.alpha2) + activerecord (= 7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.0.alpha2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + rails (7.0.0.alpha2) + actioncable (= 7.0.0.alpha2) + actionmailbox (= 7.0.0.alpha2) + actionmailer (= 7.0.0.alpha2) + actionpack (= 7.0.0.alpha2) + actiontext (= 7.0.0.alpha2) + actionview (= 7.0.0.alpha2) + activejob (= 7.0.0.alpha2) + activemodel (= 7.0.0.alpha2) + activerecord (= 7.0.0.alpha2) + activestorage (= 7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + bundler (>= 1.15.0) + railties (= 7.0.0.alpha2) + railties (7.0.0.alpha2) + actionpack (= 7.0.0.alpha2) + activesupport (= 7.0.0.alpha2) + method_source + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) + +PATH + remote: .. + specs: + importmap-rails (0.8.2) + rails (>= 6.0.0) + +GEM + remote: https://rubygems.org/ + specs: + addressable (2.8.0) + public_suffix (>= 2.0.2, < 5.0) + appraisal (2.4.1) + bundler + rake + thor (>= 0.14.0) + builder (3.2.4) + byebug (11.1.3) + capybara (3.36.0) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + childprocess (4.1.0) + concurrent-ruby (1.1.9) + crass (1.0.6) + erubi (1.10.0) + globalid (0.5.2) + activesupport (>= 5.0) + i18n (1.8.11) + concurrent-ruby (~> 1.0) + loofah (2.12.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.1) + mini_mime (>= 0.1.1) + marcel (1.0.2) + matrix (0.4.2) + method_source (1.0.0) + mini_mime (1.1.2) + minitest (5.14.4) + nio4r (2.5.8) + nokogiri (1.12.5-x86_64-linux) + racc (~> 1.4) + propshaft (0.3.1) + rails (>= 7.0.0.alpha2) + public_suffix (4.0.6) + racc (1.6.0) + rack (2.2.3) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.2) + loofah (~> 2.3) + rake (13.0.6) + regexp_parser (2.1.1) + rexml (3.2.5) + rubyzip (2.3.2) + selenium-webdriver (4.1.0) + childprocess (>= 0.5, < 5.0) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2) + sqlite3 (1.4.2) + stimulus-rails (0.7.2) + rails (>= 6.0.0) + thor (1.1.0) + turbo-rails (0.8.3) + rails (>= 6.0.0) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + webdrivers (5.0.0) + nokogiri (~> 1.6) + rubyzip (>= 1.3.0) + selenium-webdriver (~> 4.0) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.5.1) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + appraisal + byebug + capybara + importmap-rails! + propshaft + rails! + rexml + selenium-webdriver + sqlite3 + stimulus-rails + turbo-rails + webdrivers + +BUNDLED WITH + 2.2.30 From ca10e8ad777f3cbdfa398c7b1394644b1e506a9a Mon Sep 17 00:00:00 2001 From: Richard Macklin Date: Mon, 22 Nov 2021 09:19:38 -0800 Subject: [PATCH 3/5] Update test app to support running in an environment without sprockets Since rails 7 has made sprockets optional in https://github.com/rails/rails/commit/fb1ab3460a676ce7def0819c2e92289ef2dcbe3b our test app should support running without sprockets. This will allow us to test importmap-rails with an alternative asset pipeline such as propshaft. --- test/dummy/config/application.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 6f03a1c..9530a31 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -5,7 +5,13 @@ require "active_record/railtie" require "action_controller/railtie" require "action_view/railtie" -require "sprockets/railtie" +begin + require "sprockets/railtie" +rescue LoadError + # This is safe to ignore: it's expected that sprockets-rails won't be + # available when we're testing against an application that uses rails 7 with + # an alternative asset pipeline (e.g. propshaft). +end require "active_storage/engine" # Require the gems listed in Gemfile, including any gems From cfa4d66a2cc4941ce00e4b01bb14ff5c0074e40d Mon Sep 17 00:00:00 2001 From: Richard Macklin Date: Mon, 22 Nov 2021 09:22:19 -0800 Subject: [PATCH 4/5] Add default support for the propshaft asset pipeline We'll automatically add `Propshaft::MissingAssetError` to the `rescuable_asset_errors` if `Propshaft` is detected. This allows the test suite to pass when run against an application that uses propshaft instead of sprockets. --- lib/importmap/engine.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/importmap/engine.rb b/lib/importmap/engine.rb index 555c929..e066776 100755 --- a/lib/importmap/engine.rb +++ b/lib/importmap/engine.rb @@ -54,6 +54,9 @@ class Engine < ::Rails::Engine end initializer 'importmap.rescuable_asset_errors' do |app| + if defined?(Propshaft) + app.config.importmap.rescuable_asset_errors << Propshaft::MissingAssetError + end if defined?(Sprockets::Rails) app.config.importmap.rescuable_asset_errors << Sprockets::Rails::Helper::AssetNotFound end From 0463e7697e967fcafd2a64c39de96c7a0723b980 Mon Sep 17 00:00:00 2001 From: Richard Macklin Date: Mon, 22 Nov 2021 09:23:37 -0800 Subject: [PATCH 5/5] Expand CI matrix to run tests against a rails 7 app with propshaft New rails 7 applications can be generated with propshaft as an alternative asset pipeline to sprockets: https://github.com/rails/rails/commit/fb1ab3460a676ce7def0819c2e92289ef2dcbe3b Since we want importmap-rails to work out of the box with either of those asset pipeline options, we'll run our test suite continuously against both. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b89e669..7f5ce97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,7 @@ jobs: - "3.0" gemfile: - Gemfile + - gemfiles/rails_7_propshaft.gemfile - gemfiles/rails_7_sprockets.gemfile continue-on-error: [ false ]