Skip to content

Commit 3406286

Browse files
authored
Add default support for the Propshaft asset pipeline (#61)
* Rename `rails_7` gemfile to `rails_7_sprockets` Rails 7 will formally support multiple asset pipelines, making sprockets optional: rails/rails@fb1ab34 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. * 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. * Update test app to support running in an environment without sprockets Since rails 7 has made sprockets optional in rails/rails@fb1ab34 our test app should support running without sprockets. This will allow us to test importmap-rails with an alternative asset pipeline such as propshaft. * 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. * 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: rails/rails@fb1ab34 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.
1 parent 7955cfd commit 3406286

File tree

8 files changed

+231
-3
lines changed

8 files changed

+231
-3
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ jobs:
99
- "3.0"
1010
gemfile:
1111
- Gemfile
12-
- gemfiles/rails_7.gemfile
12+
- gemfiles/rails_7_propshaft.gemfile
13+
- gemfiles/rails_7_sprockets.gemfile
1314
continue-on-error: [ false ]
1415

1516
name: ${{ format('Tests (Ruby {0}, {1})', matrix.ruby-version, matrix.gemfile) }}

Appraisals

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
appraise "rails_7" do
1+
appraise "rails_7_sprockets" do
22
gem "rails", github: "rails/rails", ref: "main"
33
gem "sprockets-rails"
44
end
5+
6+
appraise "rails_7_propshaft" do
7+
gem "rails", github: "rails/rails", ref: "main"
8+
gem "propshaft"
9+
end

gemfiles/rails_7_propshaft.gemfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "rails", ref: "main", git: "https://github.com/rails/rails.git"
6+
gem "sqlite3"
7+
gem "propshaft"
8+
9+
group :development do
10+
gem "appraisal"
11+
end
12+
13+
group :test do
14+
gem "turbo-rails"
15+
gem "stimulus-rails"
16+
gem "byebug"
17+
gem "rexml"
18+
gem "capybara"
19+
gem "selenium-webdriver"
20+
gem "webdrivers"
21+
end
22+
23+
gemspec path: "../"
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
GIT
2+
remote: https://github.com/rails/rails.git
3+
revision: 6e1694275007b94b8112455ac53e8a345938376e
4+
ref: main
5+
specs:
6+
actioncable (7.0.0.alpha2)
7+
actionpack (= 7.0.0.alpha2)
8+
activesupport (= 7.0.0.alpha2)
9+
nio4r (~> 2.0)
10+
websocket-driver (>= 0.6.1)
11+
actionmailbox (7.0.0.alpha2)
12+
actionpack (= 7.0.0.alpha2)
13+
activejob (= 7.0.0.alpha2)
14+
activerecord (= 7.0.0.alpha2)
15+
activestorage (= 7.0.0.alpha2)
16+
activesupport (= 7.0.0.alpha2)
17+
mail (>= 2.7.1)
18+
actionmailer (7.0.0.alpha2)
19+
actionpack (= 7.0.0.alpha2)
20+
actionview (= 7.0.0.alpha2)
21+
activejob (= 7.0.0.alpha2)
22+
activesupport (= 7.0.0.alpha2)
23+
mail (~> 2.5, >= 2.5.4)
24+
rails-dom-testing (~> 2.0)
25+
actionpack (7.0.0.alpha2)
26+
actionview (= 7.0.0.alpha2)
27+
activesupport (= 7.0.0.alpha2)
28+
rack (~> 2.0, >= 2.2.0)
29+
rack-test (>= 0.6.3)
30+
rails-dom-testing (~> 2.0)
31+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
32+
actiontext (7.0.0.alpha2)
33+
actionpack (= 7.0.0.alpha2)
34+
activerecord (= 7.0.0.alpha2)
35+
activestorage (= 7.0.0.alpha2)
36+
activesupport (= 7.0.0.alpha2)
37+
nokogiri (>= 1.8.5)
38+
actionview (7.0.0.alpha2)
39+
activesupport (= 7.0.0.alpha2)
40+
builder (~> 3.1)
41+
erubi (~> 1.4)
42+
rails-dom-testing (~> 2.0)
43+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
44+
activejob (7.0.0.alpha2)
45+
activesupport (= 7.0.0.alpha2)
46+
globalid (>= 0.3.6)
47+
activemodel (7.0.0.alpha2)
48+
activesupport (= 7.0.0.alpha2)
49+
activerecord (7.0.0.alpha2)
50+
activemodel (= 7.0.0.alpha2)
51+
activesupport (= 7.0.0.alpha2)
52+
activestorage (7.0.0.alpha2)
53+
actionpack (= 7.0.0.alpha2)
54+
activejob (= 7.0.0.alpha2)
55+
activerecord (= 7.0.0.alpha2)
56+
activesupport (= 7.0.0.alpha2)
57+
marcel (~> 1.0)
58+
mini_mime (>= 1.1.0)
59+
activesupport (7.0.0.alpha2)
60+
concurrent-ruby (~> 1.0, >= 1.0.2)
61+
i18n (>= 1.6, < 2)
62+
minitest (>= 5.1)
63+
tzinfo (~> 2.0)
64+
rails (7.0.0.alpha2)
65+
actioncable (= 7.0.0.alpha2)
66+
actionmailbox (= 7.0.0.alpha2)
67+
actionmailer (= 7.0.0.alpha2)
68+
actionpack (= 7.0.0.alpha2)
69+
actiontext (= 7.0.0.alpha2)
70+
actionview (= 7.0.0.alpha2)
71+
activejob (= 7.0.0.alpha2)
72+
activemodel (= 7.0.0.alpha2)
73+
activerecord (= 7.0.0.alpha2)
74+
activestorage (= 7.0.0.alpha2)
75+
activesupport (= 7.0.0.alpha2)
76+
bundler (>= 1.15.0)
77+
railties (= 7.0.0.alpha2)
78+
railties (7.0.0.alpha2)
79+
actionpack (= 7.0.0.alpha2)
80+
activesupport (= 7.0.0.alpha2)
81+
method_source
82+
rake (>= 12.2)
83+
thor (~> 1.0)
84+
zeitwerk (~> 2.5)
85+
86+
PATH
87+
remote: ..
88+
specs:
89+
importmap-rails (0.8.2)
90+
rails (>= 6.0.0)
91+
92+
GEM
93+
remote: https://rubygems.org/
94+
specs:
95+
addressable (2.8.0)
96+
public_suffix (>= 2.0.2, < 5.0)
97+
appraisal (2.4.1)
98+
bundler
99+
rake
100+
thor (>= 0.14.0)
101+
builder (3.2.4)
102+
byebug (11.1.3)
103+
capybara (3.36.0)
104+
addressable
105+
matrix
106+
mini_mime (>= 0.1.3)
107+
nokogiri (~> 1.8)
108+
rack (>= 1.6.0)
109+
rack-test (>= 0.6.3)
110+
regexp_parser (>= 1.5, < 3.0)
111+
xpath (~> 3.2)
112+
childprocess (4.1.0)
113+
concurrent-ruby (1.1.9)
114+
crass (1.0.6)
115+
erubi (1.10.0)
116+
globalid (0.5.2)
117+
activesupport (>= 5.0)
118+
i18n (1.8.11)
119+
concurrent-ruby (~> 1.0)
120+
loofah (2.12.0)
121+
crass (~> 1.0.2)
122+
nokogiri (>= 1.5.9)
123+
mail (2.7.1)
124+
mini_mime (>= 0.1.1)
125+
marcel (1.0.2)
126+
matrix (0.4.2)
127+
method_source (1.0.0)
128+
mini_mime (1.1.2)
129+
minitest (5.14.4)
130+
nio4r (2.5.8)
131+
nokogiri (1.12.5-x86_64-linux)
132+
racc (~> 1.4)
133+
propshaft (0.3.1)
134+
rails (>= 7.0.0.alpha2)
135+
public_suffix (4.0.6)
136+
racc (1.6.0)
137+
rack (2.2.3)
138+
rack-test (1.1.0)
139+
rack (>= 1.0, < 3)
140+
rails-dom-testing (2.0.3)
141+
activesupport (>= 4.2.0)
142+
nokogiri (>= 1.6)
143+
rails-html-sanitizer (1.4.2)
144+
loofah (~> 2.3)
145+
rake (13.0.6)
146+
regexp_parser (2.1.1)
147+
rexml (3.2.5)
148+
rubyzip (2.3.2)
149+
selenium-webdriver (4.1.0)
150+
childprocess (>= 0.5, < 5.0)
151+
rexml (~> 3.2, >= 3.2.5)
152+
rubyzip (>= 1.2.2)
153+
sqlite3 (1.4.2)
154+
stimulus-rails (0.7.2)
155+
rails (>= 6.0.0)
156+
thor (1.1.0)
157+
turbo-rails (0.8.3)
158+
rails (>= 6.0.0)
159+
tzinfo (2.0.4)
160+
concurrent-ruby (~> 1.0)
161+
webdrivers (5.0.0)
162+
nokogiri (~> 1.6)
163+
rubyzip (>= 1.3.0)
164+
selenium-webdriver (~> 4.0)
165+
websocket-driver (0.7.5)
166+
websocket-extensions (>= 0.1.0)
167+
websocket-extensions (0.1.5)
168+
xpath (3.2.0)
169+
nokogiri (~> 1.8)
170+
zeitwerk (2.5.1)
171+
172+
PLATFORMS
173+
x86_64-linux
174+
175+
DEPENDENCIES
176+
appraisal
177+
byebug
178+
capybara
179+
importmap-rails!
180+
propshaft
181+
rails!
182+
rexml
183+
selenium-webdriver
184+
sqlite3
185+
stimulus-rails
186+
turbo-rails
187+
webdrivers
188+
189+
BUNDLED WITH
190+
2.2.30
File renamed without changes.

lib/importmap/engine.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class Engine < ::Rails::Engine
5454
end
5555

5656
initializer 'importmap.rescuable_asset_errors' do |app|
57+
if defined?(Propshaft)
58+
app.config.importmap.rescuable_asset_errors << Propshaft::MissingAssetError
59+
end
5760
if defined?(Sprockets::Rails)
5861
app.config.importmap.rescuable_asset_errors << Sprockets::Rails::Helper::AssetNotFound
5962
end

test/dummy/config/application.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
require "active_record/railtie"
66
require "action_controller/railtie"
77
require "action_view/railtie"
8-
require "sprockets/railtie"
8+
begin
9+
require "sprockets/railtie"
10+
rescue LoadError
11+
# This is safe to ignore: it's expected that sprockets-rails won't be
12+
# available when we're testing against an application that uses rails 7 with
13+
# an alternative asset pipeline (e.g. propshaft).
14+
end
915
require "active_storage/engine"
1016

1117
# Require the gems listed in Gemfile, including any gems

0 commit comments

Comments
 (0)