sass-rails-source-maps icon indicating copy to clipboard operation
sass-rails-source-maps copied to clipboard

Exception during precompile when using @import glob format provided by sass-rails

Open Aerlinger opened this issue 10 years ago • 3 comments

My SCSS files are rather voluminous and therefore I use the glob format provided by sass-rails to include all SCSS files within a directory. For instance, my application.sass file looks something like this:

/*
* sprockets imports...
*/

@import "custom/shared/*";
@import "custom/*";
@import "views/**/*";

However, it seems the glob format causes an exception in sass-rails-source-maps during precompile. Specifically, this seems to happen within the evaluate_with_source_maps wrapper method. What appears to be happening is that it's reading the filename as the literal "*" string, rather than processing the collection of filenames returned by sass-rails

This was on the beta branch for sass-rails. Specifically, the context of the stack trace was:

/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/tree/visitors/perform.rb:179:in `with_environment'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/tree/visitors/perform.rb:166:in `visit_children'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/tree/visitors/base.rb:36:in `block in visit'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/tree/visitors/perform.rb:186:in `visit_root'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/tree/visitors/base.rb:36:in `visit'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/tree/visitors/perform.rb:157:in `visit'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/tree/visitors/perform.rb:8:in `visit'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/tree/root_node.rb:36:in `css_tree'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/tree/root_node.rb:29:in `render_with_sourcemap'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/engine.rb:368:in `_render_with_sourcemap'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sass-3.4.11/lib/sass/engine.rb:285:in `render_with_sourcemap'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/bundler/gems/sass-rails-source-maps-1328c96ef524/lib/sass-rails-source-maps/sass_template.rb:35:in `evaluate_with_source_maps'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sprockets-2.12.3/lib/sprockets/context.rb:197:in `block in evaluate'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `each'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `evaluate'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `new'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sprockets-2.12.3/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sprockets-2.12.3/lib/sprockets/base.rb:373:in `build_asset'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/Aerlinger/.rvm/gems/ruby-2.1.5/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'

Aerlinger avatar Feb 09 '15 02:02 Aerlinger

Forked the repo and did some debugging...

I noticed that the evaluate_with_source_maps method uses the base SassImporter module rather than Sass::Rails::SassImporter module which is overridden in the Sass::Rails gem. (See https://github.com/rails/sass-rails/blob/master/lib/sass/rails/template.rb#L36)

Looking within importer.rb in the Sass::Rails project, this module is wrapped in a local importer_class method. Using importer_class in lieu of the base SassImporter within evaluate_with_source_maps seems to resolve the issue:

options = {
        sourcemap_filename:  ::Sass::Util::sourcemap_name(eval_file),
        ...
        importer:            importer_class.new(context.pathname.to_s),
        load_paths:          context.environment.paths.map { |path| importer_class.new(path.to_s) },
        ...
      }

However, some of the paths which copy the files to the /assets folder need to be refactored to reflect this change.

Aerlinger avatar Feb 09 '15 04:02 Aerlinger

Hello @Aerlinger. Please can you try it on latest master? (50aa40de688820c7784d65e0be1e53c39d6e3b8d)

vhyza avatar Mar 27 '15 10:03 vhyza

I am having this issue at 219c5a42ce9b5ccfa356e1549e9b72d8acedd2c2 Using sass-rails 5.0.3 sass 3.4.15

soberstadt avatar Nov 23 '16 15:11 soberstadt