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

Wrong sourceMappingURL #201

Closed
bachew opened this issue May 30, 2017 · 7 comments
Closed

Wrong sourceMappingURL #201

bachew opened this issue May 30, 2017 · 7 comments
Labels

Comments

@bachew
Copy link

bachew commented May 30, 2017

sourceMappingURL is wrongly relative to scss file, should be relative to css file instead.

$ bin/sassc --version
sassc 0.12.3 (sass/libsass 3.4.3)
$ mkdir -p scss target/css
$ touch scss/style.scss
$ sassc -g scss/style.scss target/css/style.css
$ cat target/css/style.css
/*# sourceMappingURL=../target/css/style.css.map */

If browser tries to access ../target/css/style.css.map from target/css/style.css, it would get 404 on target/target/css/style.css.map.

Doesn't seem like C libsass's issue.

@asottile
Copy link
Member

I can reproduce this, but it doesn't seem to be related to our code (we're just a simple wrapper). I'll make a minimal reproduction and post it into that issue -- I imagine we're missing some option to the C api

(excuse my mix of c and c++ and lack of freeing, just trying to get a quick reproduction)

#include <sass/context.h>
#include <iostream>

int main() {
    struct Sass_Context *ctx;
    struct Sass_File_Context *context = sass_make_file_context(
        "input/foo.scss"
    );
    struct Sass_Options* options = sass_file_context_get_options(context);
    sass_option_set_source_map_file(options, "output/css/out.map");
    sass_compile_file_context(context);
    ctx = sass_file_context_get_context(context);
    const char* output_string = sass_context_get_output_string(ctx);
    std::cout << output_string << std::endl;
    return 0;
}
$ g++ -Ilibsass/include test.cpp libsass/lib/libsass.a -ldl
$ ./a.out 

/*# sourceMappingURL=../output/css/out.map */

@asottile
Copy link
Member

Ah, if I add this:

    sass_option_set_output_path(options, "output/css/out.css");

it suddenly works!

I'll make a PR in a bit to thread this through!

@bachew
Copy link
Author

bachew commented May 31, 2017

Thanks for the efficiency! I can't wait for pip install -U libsass

@asottile
Copy link
Member

asottile commented Jun 2, 2017

Alright, I'll see when I can get this into a release -- I've already started tracking the upstream 3.5 changes on our master branch, so maybe I should revert those temporarily and make some more 3.4.x releases (including this change?)

@bachew
Copy link
Author

bachew commented Jun 7, 2017

Which ever best for your release process, I'm OK using workaround for now:

css = shlib.read_file(css_file)
map_file = osp.basename(css_file) + '.map'
correct_mapping = '/*# sourceMappingURL={} */'.format(map_file)
css = re.sub(r'/\*\s*#\s*sourceMappingURL=.*\s*\*/', correct_mapping, css)
shlib.write_file(css_file, css)

I'll just come back to this in few weeks or a couple of months time, pretty sure I'll get this fix eventually. Thanks.

@asottile
Copy link
Member

asottile commented Jun 8, 2017

This is now part of 0.13.0 \o/

@bachew
Copy link
Author

bachew commented Oct 4, 2017

Thanks, it works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants