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

Fixing sprockets 3 deprecation in a gem (method register_engine is deprecated) #554

Open
Schwad opened this issue Apr 24, 2018 · 1 comment

Comments

@Schwad
Copy link

Schwad commented Apr 24, 2018

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: oceanshq/jquery-tmpl-rails@de7a598

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. I am not the gem maintainer but am trying to put this PR together myself as we rely on this gem.

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' and would rather not.
@Schwad
Copy link
Author

Schwad commented Apr 24, 2018

I am trying to see how it has been done elsewhere and I think I may have found a commit for js-routes that implemented these changes along with support for 2 + 4.... railsware/js-routes@2c6c227#diff-1eb2fc1e42a530917862e373dd71049f

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

No branches or pull requests

1 participant