getappmap / getappmap/appmap-node

Improper handling of source maps with relative source roots

Open
#181 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
13
Forks
6
Avg merge
18h 23m
Merged PRs (30d)
8

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/hooks/instrument.ts at the transform() location referenced in the issue, then inspect the WIP source-map-relative-root branch and reproduce the TypeORM example. Verify that a relative sourceRoot is resolved against the source map URL rather than the working directory, and confirm the resulting location.path is sensible.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.