Source maps can have sourceRoot property; it's defined as a string that's prepended to every entry in the sources list. The specification doesn't put any constraints on this field; consequently, this can be a relative directory (eg. ..).
In my understanding, the intended semantics is that it's to be resolved relative to the URL of the source map itself, eg. given { sourceRoot: '..', sources: 'a.js' } and source map at file:///example/source.js.map the resolved source URL should be ../a.js => file:///a.js.
appmap-node does not handle this case correctly. Consider for example typeorm-0.3.20; metadata-args/MetadataArgsStorage.js.map contains:
$ jq '{sources, sourceRoot}' node_modules/typeorm/metadata-args/MetadataArgsStorage.js.map
{
"sources": [
"../../src/metadata-args/MetadataArgsStorage.ts"
],
"sourceRoot": ".."
}
However, when instrumenting the file, relevant location.path in transform() (as determined by the debugger) reads nonsensical ../home/divide/projects/tmp/NestJS-TypeORM-Example/node_modules/typeorm/metadata-args/src/metadata-args/MetadataArgsStorage.ts (note the working directory in this run is /home/divide/projects/tmp/NestJS-TypeORM-Example/).
(The path as indicated by the source map would be incorrect in any case (file:////home/divide/projects/tmp/NestJS-TypeORM-Example/src/metadata-args/MetadataArgsStorage.ts by my reading) which seems to be a bug in typeorm build, but that's beside the point.)
Note: I started working on this issue, here's a WIP branch: https://github.com/getappmap/appmap-node/tree/wip/source-map-relative-root
Source maps can have
sourceRootproperty; it's defined as a string that's prepended to every entry in thesourceslist. The specification doesn't put any constraints on this field; consequently, this can be a relative directory (eg...).In my understanding, the intended semantics is that it's to be resolved relative to the URL of the source map itself, eg. given
{ sourceRoot: '..', sources: 'a.js' }and source map atfile:///example/source.js.mapthe resolved source URL should be../a.js=>file:///a.js.appmap-nodedoes not handle this case correctly. Consider for example typeorm-0.3.20;metadata-args/MetadataArgsStorage.js.mapcontains:However, when instrumenting the file, relevant
location.pathintransform()(as determined by the debugger) reads nonsensical../home/divide/projects/tmp/NestJS-TypeORM-Example/node_modules/typeorm/metadata-args/src/metadata-args/MetadataArgsStorage.ts(note the working directory in this run is/home/divide/projects/tmp/NestJS-TypeORM-Example/).(The path as indicated by the source map would be incorrect in any case (
file:////home/divide/projects/tmp/NestJS-TypeORM-Example/src/metadata-args/MetadataArgsStorage.tsby my reading) which seems to be a bug in typeorm build, but that's beside the point.)Note: I started working on this issue, here's a WIP branch: https://github.com/getappmap/appmap-node/tree/wip/source-map-relative-root