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

Fix source maps for @imported sass files w/ sassc processor #391

Merged

Conversation

TylerHorth
Copy link

Currently, source maps are generated by the sassc engine and inlined, then the sassc processor strips them out and decodes them. As a consequence to this process the source urls are not relative to the map file, and as such they are discarded. Thus we don't get content maps for any but the root level file.

The simplest solution to this problem is to forgo the inline shenanigans and use source maps natively from libsass. I updated the sassc gem with a source map getter which will allow us to do this.

engine.source_map made it into sassc version 1.10.1, unfortunately the omit_source_map_url option didn't. Without this a useless sourceMappingURL comment is added to the bottom of the debug file just before the actual url. However, I don't believe this will be a problem since the url won't resolve to anything and thus should be ignored.

The test will likely fail until #390 is merged.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @arthurnn (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@TylerHorth
Copy link
Author

Ah, the lack of omit_source_map_url in the current sassc version is causing tests to fail.

@TylerHorth
Copy link
Author

I've run into a bug with sassc still reporting bad source urls. This PR's on hold for a little bit until I figure out what's going wrong.

@TylerHorth TylerHorth force-pushed the fix/sassc-import-source-maps branch from 30986f2 to 067efa4 Compare October 5, 2016 21:44
@TylerHorth
Copy link
Author

Alright the problem was that the SourceMapProcessor resolves each source. This means that each source must be absolute, or be in the load paths. Absolute paths are fine according to the source map spec, but otherwise they must be relative to the map file. This means that SourceMapProcessor accepts some malformed maps (the issue in #390, where sources are logical paths) and fails when given some properly formed maps (when sources are relative to the map file, but not included in the list of assets paths).

The proper solution to this would probably be to modify the SourceMapProcessor to work with relative paths, and fix the processors currently outputting malformed maps (instead of the global solution in #390). To me this seems out of scope for this PR, so I have modified the sassc processor to output sources with absolute urls.

I'm not sure why the one sassc test is failing, the source maps seemed to be generating properly. I'll do some testing tomorrow.

@@ -24,7 +24,7 @@ def call(input)
engine = Autoload::SassC::Engine.new(input[:data], options)

css = Utils.module_include(Autoload::SassC::Script::Functions, @functions) do
engine.render
engine.render.gsub(/^\/\*# sourceMappingURL=.*\*\/$/, '').strip
Copy link
Author

Choose a reason for hiding this comment

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

The solves the omit_source_map_url problem until the option makes into the next sassc version.

@guilleiguaran
Copy link
Member

can you squash your commits please?

@guilleiguaran guilleiguaran self-assigned this Oct 6, 2016
@TylerHorth TylerHorth force-pushed the fix/sassc-import-source-maps branch from 6e8940a to d30efa6 Compare October 6, 2016 19:11
@TylerHorth
Copy link
Author

Rebased and fixed an incompatibility with the sources metadata attribute.

@guilleiguaran guilleiguaran merged commit 576534b into rails:master Oct 8, 2016
@guilleiguaran
Copy link
Member

Thank you very much for this!!!

@schneems
Copy link
Member

Thanks for this, you're on a roll. Let me know if you have any questions about anything. Appreciate your help.

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.

5 participants