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

Remove legacy conditions #510

Merged
merged 3 commits into from
Aug 10, 2022
Merged

Conversation

skipkayhil
Copy link
Member

Summary

These are no longer necessary to due higher Ruby and Rails requirements

Comment on lines 57 to 62
class Engine < Railtie
# Skip defining append_assets_path on Rails <= 4.2
unless initializers.find { |init| init.name == :append_assets_path }
initializer :append_assets_path, :group => :all do |app|
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
end
initializer :append_assets_path, :group => :all do |app|
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could Sprockets::Railtie be upgraded to a Rails::Engine so that we don't have to reopen the Rails::Engine class? (Rails::Railtie doesn't have access to the paths used here)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can:

When we drop support to Rails 4 we can change it to instead of reopening Rails::Engine just define a Sprockets::Rails::Engine instead of a Railtie.

#215 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do that. This needs to be an initializer defined in all Rails::Engine subclasses, not only in the sprockets Engine. But we can do the same as rails/propshaft#43.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, can you elaborate on the difference? I thought rails/propshaft@66ce0f8 didn't work because Propshaft::Railtie isn't a full engine.

Copy link
Member

@rafaelfranca rafaelfranca Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is that this code is changing all engines (every single one of them) and defining an initializer insider then. If we just move that initializer to the Sprockets-Rails Engine, only it would be affected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it just clicked for me: the initializer is appending the Rails::Engine subclasses' paths to config.assets.paths. That makes complete sense now.

end
alias_method_chain :internal?, :sprockets
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this can be removed because we no longer call include Sprockets::Rails::RouteWrapper ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, exactly

It was removed from Rails in rails/rails@5172d93, and sprockets-rails
only supports Rails 5.2+

The initializer is also changed to be a simpler class method call
instead of reopening Rails::Engine, similarly to how it was changed in
rails/propshaft@c7d5542
Module#prepend was added in ruby 2.0, and the required ruby version is
2.5+

The Rails > 4 conditional will also always be true since the required
Rails version is 5.2+
Kernel#caller_locations was added in ruby 2, and the required ruby
version is 2.5

The Rails version check will also always be true since the minimum Rails
version is 5.2
@rafaelfranca rafaelfranca merged commit 60f032e into rails:master Aug 10, 2022
@skipkayhil skipkayhil deleted the rm-legacy-conditions branch August 10, 2022 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants