evanw / evanw/node-source-map-support

Problem with sourceRoot when dealing with nested folder structure

Open
#31 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.2k
Forks
223
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.