Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prioritize app assets over engine assets #206

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/propshaft/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Railtie < ::Rails::Railtie
end

config.after_initialize do |app|
# Prioritize assets from within the application over assets of the same path from engines/gems.
config.assets.paths.sort_by! { |path| path.to_s.start_with?(Rails.root.to_s) ? 0 : 1 }

config.assets.relative_url_root ||= app.config.relative_url_root
config.assets.output_path ||=
Pathname.new(File.join(app.config.paths["public"].first, app.config.assets.prefix))
Expand Down
1 change: 1 addition & 0 deletions test/dummy/app/views/sample/load_real_assets.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
<p>Find me in app/views/sample/load_real_assets.html.erb</p>

<%= javascript_include_tag "hello_world" %>
<%= javascript_include_tag "actioncable" %>
2 changes: 1 addition & 1 deletion test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
# require "action_cable/engine"
require "action_cable/engine"
# require "sprockets/railtie"
require "rails/test_unit/railtie"

Expand Down
1 change: 1 addition & 0 deletions test/dummy/lib/assets/javascripts/actioncable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("actioncable.js")
6 changes: 6 additions & 0 deletions test/propshaft_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class PropshaftIntegrationTest < ActionDispatch::IntegrationTest
assert_select 'script[src="/assets/hello_world-888761f8.js"]'
end

test "should prioritize app assets over engine assets" do
get sample_load_real_assets_url

assert_select 'script[src="/assets/actioncable-2e7de4f9.js"]'
end

test "should find app styles via glob" do
get sample_load_real_assets_url

Expand Down