evanw / evanw/node-source-map-support

Problem with sourceRoot when dealing with nested folder structure

Offen
#31 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
2.2k
Forks
223
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginne mit der Untersuchung der in Pull Request #4 eingeführten Auflösung von source-map-Pfaden, insbesondere wie ein relativer sourceRoot relativ zum Speicherort jeder Map-Datei aufgelöst wird. Reproduziere das Beispiel mit verschachtelten Ordnern unter Windows und überprüfe, dass relative sourceRoot-Werte vom Map-Stamm aus aufgelöst werden, während die korrekten Pfade für foo.coffee und sub_folder/bar.coffee erhalten bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, node.js
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.