Skip to content

Commit

Permalink
fixes #126, prepend sourceRoot to source file paths (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
nainslie authored and dylans committed Jan 22, 2017
1 parent ba8fe42 commit 6e40c3a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/CoverageTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,21 @@ export default class CoverageTransformer {

sourceMapDir = this.basePath || sourceMapDir;

// replace relative paths in source maps with absolute
rawSourceMap.sources = rawSourceMap.sources.map((srcPath) => (
srcPath.substr(0, 1) === '.'
? path.resolve(sourceMapDir, srcPath)
: srcPath
));

// Clean up source map paths:
// * prepend sourceRoot if it is set
// * replace relative paths in source maps with absolute
rawSourceMap.sources = rawSourceMap.sources.map((srcPath) => {
let tempVal = srcPath;
if (rawSourceMap.sourceRoot) {
tempVal = rawSourceMap.sourceRoot + srcPath;
}
if (tempVal.substr(0, 1) === '.') {
return path.resolve(sourceMapDir, tempVal);
} else {
return tempVal;
}
});

let sourceMap = new SourceMapConsumer(rawSourceMap);

/* if there are inline sources and a store to put them into, we will populate it */
Expand Down

0 comments on commit 6e40c3a

Please sign in to comment.