Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

upgrade sass-rails gem to 5.0 gives deprecation warning

We upgraded to sass-rails version 5.0.0 and are getting this deprecation warning:

DEPRECATION WARNING: Extra .css in SCSS file is unnecessary. Rename /Users/foo/Projects/foo/app/assets/stylesheets/foo.css.scss to /Users/foo/Projects/foo/app/assets/stylesheets/foo.scss. (called from _app_views_layouts_application_html_erb__1560597815210891605_70190441246060 at /Users/foo/Projects/foo/app/views/layouts/application.html.erb:13)

Anyone know whats going on with this? Does the gem really want me to rename all of my stylesheet assets from:

app/assets/stylesheets/foo.css.scss

to:

app/assets/stylesheets/foo.scss

?

Seems to run against years of Rails convention to me. Perhaps there is a way to suppress the deprecation warning?

like image 492
ipd Avatar asked Dec 18 '14 00:12

ipd


2 Answers

This handled it for me:

#!/bin/sh
for file in $(find ./app/assets/stylesheets/ -name "*.css.scss")
do
    git mv $file `echo $file | sed s/\.css//`
done
like image 141
jmaxyz Avatar answered Oct 20 '22 05:10

jmaxyz


Yes you need to rename your .css.scss to just .scss, as .css.scss will not be supported in sprockets 4.

If you want to suppress the deprecation temporary you can the following to config/initializer/deprecations.rb

Rails.application.config.after_initialize do
  old_behaviour = ActiveSupport::Deprecation.behavior
  ActiveSupport::Deprecation.behavior = ->(message, callstack) {
    unless message.starts_with?('DEPRECATION WARNING: Extra .css in SCSS file is unnecessary.',
                                'DEPRECATION WARNING: Extra .css in SASS file is unnecessary.')
      old_behaviour.each { |behavior| behavior[message,callstack] }
    end
  }
end

Or you can monkey patch to not to generate the message like this:

module DisableCssDeprecation
  def deprecate_extra_css_extension(engine)
    if engine && filename = engine.options[:filename]
      if filename.end_with?('.css.scss','.css.sass')
        engine
      else
        super
      end 
    end
  end
end

module Sass ; module Rails ; class SassImporter
  prepend DisableCssDeprecation
end ; end ; end
like image 43
mfazekas Avatar answered Oct 20 '22 07:10

mfazekas