evanw / evanw/node-source-map-support

Problem with sourceRoot when dealing with nested folder structure

Aperta
#31 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
2.2k
Fork
223
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Say that I have a project like this:

```
%project_root%
├─coffee
│ └─sub_folder
│ │ └─bar.coffee
│ └─foo.coffee
├─js
│ └─sub_folder
│ │ └─bar.js
│ └─foo.js
├─map
│ └─sub_folder
│ │ └─bar.js.map
│ └─foo.js.map
```

If an error was thrown in `bar.coffee`, the source path would be wrong. There're several cases (tested on Windows, project folder is on drive `X:`):

| `sourceRoot` Value | Source path in error messages for `foo.coffee` | Source path in error messages for `sub_folder/bar.coffee` |
| --- | --- | --- |
| Not set | `%project_root%/map/foo.coffee` | `%project_root%/map/sub_folder/bar.coffee` |
| `/src` | `x:/src/foo.coffee` | `x:/src/sub_folder/bar.coffee` |
| `./src` | `%project_root%/map/src/foo.coffee` | `%project_root%/map/src/sub_folder/bar.coffee` |
| `../src` | `%project_root%/src/foo.coffee` | `%project_root%/map/src/sub_folder/bar.coffee` |
| `__dirname + /src` | %project_root%/src/foo.coffee`|`%project_root%/src/sub_folder/bar.coffee` | |

As you can see, only hard-code the absolute path of `%project_root%` will give us the correct behavior. But it is not very useful since those paths may not be valid on another system.

I think a possible solution would be to resolve `sourceRoot` path relative to map root instead of [each map file's location](https://github.com/evanw/node-source-map-support/pull/4/files#diff-f332e9a051ea7f7b602a3d633c506d30R30) (introduced by #4), when the `sourceRoot` is a relative path.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.