jashkenas / coffeescript

Unfancy JavaScript
https://coffeescript.org/
MIT License
16.5k stars 1.99k forks source link

Coffeescript compiler generates incorrect sourceRoot / sources in the presence of symlinks in the filesystem #4250

Closed dgoldstein0 closed 7 years ago

dgoldstein0 commented 8 years ago

Spent a few hours today tracking this down... right now I'm planning to work around this by resolving to real paths before constructing my coffeescript compile command, but I figured I should document the bug in hopes that maybe it'll help someone or eventually get fixed.

I set up the following directory structure:

now the command

$ coffee --compile --map --output ~/dontserve/static/javascript/compiled ~/dontserve/static/coffee/asdf.coffee

Generates the following (correct) sourcemap:

{
  "version": 3,
  "file": "asdf.js",
  "sourceRoot": "../../..",
  "sources": [
    "static/coffee/asdf.coffee"
  ],
  "names": [],
  "mappings": ";AAAA;EAAA,MAAA,CAAO,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CAAP,EAAwB,SAAC,CAAD,EAAI,CAAJ,EAAO,CAAP;AACtB,WAAO,CAAA,GAAI,CAAJ,GAAQ;EADO,CAAxB;AAAA"
}

Whereas the alternate command - which only differs by using the symlinked locations:

$ coffee --compile --map --output ~/a/static/javascript/compiled ~/a/static/coffee/asdf.coffee

produces the sourcemap

{
  "version": 3,
  "file": "asdf.js",
  "sourceRoot": "../../../../dontserve",
  "sources": [
    "../a/static/coffee/asdf.coffee"
  ],
  "names": [],
  "mappings": ";AAAA;EAAA,MAAA,CAAO,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,CAAP,EAAwB,SAAC,CAAD,EAAI,CAAJ,EAAO,CAAP;AACtB,WAAO,CAAA,GAAI,CAAJ,GAAQ;EADO,CAAxB;AAAA"
}

It would appear that coffee is somehow resolving symlinks in the --output argument, without doing the same for the input file paths. This is a problem because neither a or dontserve do not appear on my webserver - the root path contains static.

My only workaround for the moment is to resolve paths with symlinks in them to their canonical paths before invoking coffee. Requiring this seems fragile though.

GeoffreyBooth commented 7 years ago

The sourcemap generation code has been refactored since this issue was posted. If there is still an issue in the current 2-branch compiler, please update this issue or open a new one.

dgoldstein0 commented 7 years ago

I worked around the issue a long time ago by resolving paths before I fed them to coffee. Given that, and that I'm using code 1.10 still, and that I'm ditching coffee in favor of typescript, I'm not going to bother testing if it's fixed or not.

On Wed, Apr 26, 2017, 7:23 PM Geoffrey Booth notifications@github.com wrote:

The sourcemap generation code has been refactored since this issue was posted. If there is still an issue in the current 2-branch compiler, please update this issue or open a new one.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jashkenas/coffeescript/issues/4250#issuecomment-297593342, or mute the thread https://github.com/notifications/unsubscribe-auth/ABBnd-8wltlfQ1VSuFKfAvdZdcaZkhxAks5rz_wtgaJpZM4IFE73 .