Fixing sprockets deprecation: method `register_engine` is deprecated

957 Views Asked by At

Versions

  • Ruby 2.4.3
  • Rails 5.1.3
  • sprockets 3.7.3
  • jquery-tmpl-rails 1.1.0

Issue:

The latest version of jquery-tmpl-rails triggers a sprockets deprecation warning of:

DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.
Please register a mime type using `register_mime_type` then
use `register_compressor` or `register_transformer`.

https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors 
(called from block (2 levels) in <class:Railtie> at /my/path/to/gems/jquery-tmpl-rails-ef6f58001d41/lib/jquery-tmpl-rails/engine.rb:10)

Attempts at resolution:

Following the deprecation warning, the problem within the gem simply resides here: https://github.com/jimmycuadra/jquery-tmpl-rails/blob/master/lib/jquery-tmpl-rails/engine.rb#L10

Which is currently:

app.assets.register_engine(".tmpl", JqueryTemplate)

I then visited the sprockets guide for handling deprecations, extensibility and compliance with sprockets 2,3,4. https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors

I made my best attempt at rectifying the problem with a commit on this fork here: https://github.com/oceanshq/jquery-tmpl-rails/commit/de7a59894f512efb3c1eba432da3517f21d921a2

Which was:

asset.register_mime_type 'application/javascript', extensions: ['.tmpl'], charset: :unicode
asset.register_preprocessor 'application/javascript', JqueryTemplate

However, this attempt simply deals out breakages when trying to run the web application at all or test it on the CI. So obviously I've missed something.

Questions

  • Is there a simple syntactical approach I am missing here?
  • It was unclear to me in the docs, although register_engine is deprecated in Sprockets 3, is it actually possible to migrate from register_engine while staying in Sprockets 3?
  • If we are remaining on Sprockets 3 for the foreseeable future, is it kosher to silence this? Generally I work viewing deprecations as 'bugs that need fixing'
0

There are 0 best solutions below