larsgrefer / dart-sass-java

Java Implementation of an embedded-sass host
MIT License
26 stars 4 forks source link

Source maps output #130

Open zalky opened 2 years ago

zalky commented 2 years ago

Hi there,

I just recently tried to generate source maps via the embedded compiler and the source maps that are being generated are different than what you get from CLI dart-sass. The actual compiled css files are correct, the issue is just with the source maps.

With this embedded compile I'm getting something like:

{
    "version":3,
    "sourceRoot":"",
    "sources": ["file:///Users/user/src/project/test/resources/_dependency.scss","file:///Users/user/src/project/test/resources/dependent.scss"],
    "names":[],
    "mappings":"AAAA,kBACE,cAGF,iBACE"
}

Whereas dart-sass CLI produces something like:

{
    "version":3,
    "sourceRoot":"",
    "sources":["_dependency.scss","dependent.scss"],
    "names":[],
    "mappings":"AACA;EACI;;;ACEJ;EACI",
    "file":"dependent.css"
}

Specifically, the output "file" is missing, but more importantly the paths are absolute, which will probably break. Does this seem right?

I based my usage on the tests in SassCompilerTest.java, basically I just setGenerateSourceMaps on the compiler, and that was it. Is there some other configuration that I'm missing, or some usage example I may have missed?

Thanks for this great library!

larsgrefer commented 2 years ago

My library does nothing to the source map content. It only tells the embedded compiler to generate a source map and then passes the source map generated by the compiler back to you.

The embedded protocol actually enforces the missing file entry:

https://github.com/sass/embedded-protocol/blob/6e4c63c9ffd899ff7df5f64c531c647f0af43fb7/embedded_sass.proto#L290-L292

For the sources URLs I'm not sure if its my library or the embedded compiler which generates the absolute pahths

zalky commented 2 years ago

Gotcha. Well the absolute paths are easy enough to relativize post-hoc. Feel free to close this if you decide it is not an issue with the library.

Thanks again!

larsgrefer commented 2 years ago

I'm not sure what to do about this, yet.

On the one hand I completely understand that the current source maps (with absolute paths) are pretty useless.

On the other hand, I don't know how to improve the situation. Neither the embedded compiler nor my host library have enough context to create better source maps.

zalky commented 1 year ago

Apologies, I didn't want to open a whole other issue for this, but just wanted to stop by and say that there is now a Clojure dart-sass-clj wrapper around your library. Thanks for making that possible!