-
Notifications
You must be signed in to change notification settings - Fork 2k
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
CLI: SourceMap sources path should be relative #3296
Comments
@am11: It looks like you're using iced-coffee-script here. Can you confirm that this bug exists on jashkenas/coffee-script@master as well? |
@michaelficarra, Yes. I installed npm using > node "node_modules\coffee-script\bin\coffee"
--bare --map
--output "C:\\projects\test\website_root\javascript\"
--compile "C:\\projects\test\website_root\coffee\work.coffee" |
@michaelficarra, I have added proposed solution. Hopefully, it will help you guys in some way. :) |
About 1/4th done. Also correct some usages & properties. Fixes madskristensen#480, madskristensen#387
Agreed; this is a problem. |
FYI, we're trying to get source maps to "just work" in the CoffeeScript plugin for the Broccoli build tool (joliss/broccoli-coffee#9), and this bug is blocking us. Would love to see this fixed! |
Let's fix it! |
Yay! |
I just had to do some pretty awkward stuff in my coffee build script (involving copying my whole source directory into my static js folder and changing working directory) to get the source mapping feature to work. Being able to override the root path and base path would have saved me a couple of headaches. Has there been any progress in that regard? |
See also #3075. |
I just tested this, and I’m unable to reproduce (which isn’t all that surprising, as it’s four years later): ➜ coffee -v
CoffeeScript version 2.0.0-beta4
➜ mkdir -p website_root/assets website_root/coffee website_root/js
➜ echo 'console.log Date.now()' > ./website_root/coffee/work.coffee
➜ coffee --bare --map --output ./website_root/js --compile ./website_root/coffee/work.coffee
➜ cat ./website_root/js/work.js.map
{
"version": 3,
"file": "work.js",
"sourceRoot": "../..",
"sources": [
"website_root/coffee/work.coffee"
],
"names": [],
"mappings": ";AAAA,OAAO,CAAC,GAAR,CAAY,IAAI,CAAC,GAAL,CAAA,CAAZ"
} Note the relative path in the If this is still an issue and someone can write some steps to reproduce, please post those steps in a comment and I’ll reopen. At this point we don’t plan to add any more command-line flags, so there won’t be an option to get |
Relative to the location of compiled map and
.coffee
or absolute URL on disk, when compiled with Node.Consider the following structure:
It was result of this command:
Now, the
sources[]
inside the.map
file looks like:While expected result is:
relative path
or absolute path
or optional switch for either:
Note: LESS provides
--source-map-basepath={relative or absolute path}
argument and you can supply desired path to .map file as well. That might worth checking out in this situation.Proposed Solution:
LESS provides six compiler arguments to deal with source map in general, out of which four effects on file paths, viz;
(first four)
I personally find it very confusing and one may not get it unless experiment with it for a while.
Having said that, considering our aim is to keep the end result consistent, that is; the related .coffee, .map and .js can be saved at different locations, we can fix it by providing "value" in existing compiler switch;
--map[=FileNameWithPath]
. After that, calculate the following relative paths:.css
to.map
; for sourceMap comment in CSS file..map
to.css
; for the value of "file" member / property* in.map
JSON..map
to each.less
file; for sources array in.map
JSON.This is how we calculated relative paths in .NET independent of FileSystem API. We can write a similar method in JavaScript.
For Windows, there is C++ file system function to resolve relative paths;
PathRelativePathTo()
inshlwapi.dll
. I am sure for other OS and languages, there must be a similar low-level implementation to calculate the shortest path between two files on disc.For further references please check the LESS implementation and see this discussion for various approaches to solve relative URL issues: madskristensen/WebEssentials2013#134.
The text was updated successfully, but these errors were encountered: