Skip to content

Commit

Permalink
fix!: consistently resolve paths to absolute form (#72)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: paths are now consistently absolute.
  • Loading branch information
bcoe committed Nov 17, 2019
1 parent dc71bd9 commit 55f4116
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 253 deletions.
2 changes: 2 additions & 0 deletions .github/release-please.yml
@@ -0,0 +1,2 @@
releaseType: node
handleGHRelease: true
19 changes: 0 additions & 19 deletions lib/pathutils.js

This file was deleted.

23 changes: 14 additions & 9 deletions lib/v8-to-istanbul.js
@@ -1,7 +1,6 @@
const { isAbsolute, relativeTo } = require('./pathutils')
const assert = require('assert')
const convertSourceMap = require('convert-source-map')
const { dirname, join } = require('path')
const { dirname, isAbsolute, join, resolve } = require('path')
const CovBranch = require('./branch')
const CovFunction = require('./function')
const CovSource = require('./source')
Expand Down Expand Up @@ -46,13 +45,7 @@ module.exports = class V8ToIstanbul {
console.warn('v8-to-istanbul: source-mappings from one to many files not yet supported')
this.source = new CovSource(rawSource, this.wrapperLength)
} else {
if (rawSourceMap.sourcemap.sourceRoot && isAbsolute(rawSourceMap.sourcemap.sourceRoot)) {
// TODO: we should also make source-root work with relative paths, but this needs
// to be combined with the relativeTo logic which takes into account process.cwd().
this.path = join(rawSourceMap.sourcemap.sourceRoot.replace('file://', ''), rawSourceMap.sourcemap.sources[0].replace('file://', ''))
} else {
this.path = relativeTo(rawSourceMap.sourcemap.sources[0].replace('file://', ''), this.path)
}
this._rewritePath(rawSourceMap)
this.sourceMap = await new SourceMapConsumer(rawSourceMap.sourcemap)

let originalRawSource
Expand All @@ -70,6 +63,18 @@ module.exports = class V8ToIstanbul {
}
}

_rewritePath (rawSourceMap) {
const sourceRoot = rawSourceMap.sourcemap.sourceRoot ? rawSourceMap.sourcemap.sourceRoot.replace('file://', '') : ''
const sourcePath = rawSourceMap.sourcemap.sources[0].replace('file://', '')
const candidatePath = join(sourceRoot, sourcePath)

if (isAbsolute(candidatePath)) {
this.path = candidatePath
} else {
this.path = resolve(dirname(this.path), sourcePath)
}
}

applyCoverage (blocks) {
blocks.forEach(block => {
block.ranges.forEach((range, i) => {
Expand Down

0 comments on commit 55f4116

Please sign in to comment.