Skip to content

Commit

Permalink
feat: switch to using istanbul-lib-source-maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Coe committed Jul 2, 2016
1 parent 6d8cfb4 commit 48929e6
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 377 deletions.
3 changes: 2 additions & 1 deletion bin/nyc.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ if (argv._[0] === 'report') {
require: argv.require,
include: argv.include,
exclude: argv.exclude,
sourceMap: !!argv.sourceMap
sourceMap: !!argv.sourceMap,
instrumenter: argv.instrumenter
}))
nyc.reset()

Expand Down
3 changes: 1 addition & 2 deletions build-self-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ var fs = require('fs')
var path = require('path')

;[
'index.js',
'lib/source-map-cache.js'
'index.js'
].forEach(function (name) {
var indexPath = path.join(__dirname, name)
var source = fs.readFileSync(indexPath, 'utf8')
Expand Down
19 changes: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var fs = require('fs')
var glob = require('glob')
var libCoverage = require('istanbul-lib-coverage')
var libReport = require('istanbul-lib-report')
var libSourceMaps = require('istanbul-lib-source-maps')
var reports = require('istanbul-reports')
var mkdirp = require('mkdirp')
var Module = require('module')
Expand All @@ -13,7 +14,6 @@ var rimraf = require('rimraf')
var onExit = require('signal-exit')
var resolveFrom = require('resolve-from')
var arrify = require('arrify')
var SourceMapCache = require('./lib/source-map-cache')
var convertSourceMap = require('convert-source-map')
var md5hex = require('md5-hex')
var findCacheDir = require('find-cache-dir')
Expand Down Expand Up @@ -65,7 +65,7 @@ function NYC (opts) {
return transforms
}.bind(this), {})

this.sourceMapCache = new SourceMapCache()
this.sourceMapCache = libSourceMaps.createSourceMapStore()

this.hashCache = {}
this.loadedMaps = null
Expand Down Expand Up @@ -230,7 +230,7 @@ NYC.prototype._handleSourceMap = function (cacheDir, code, hash, filename) {
var mapPath = path.join(cacheDir, hash + '.map')
fs.writeFileSync(mapPath, sourceMap.toJSON())
} else {
this.sourceMapCache.addMap(filename, sourceMap.toJSON())
this.sourceMapCache.registerMap(filename, sourceMap.sourcemap)
}
}
}
Expand Down Expand Up @@ -296,7 +296,7 @@ NYC.prototype.writeCoverageFile = function () {
}
}, this)
} else {
this.sourceMapCache.applySourceMaps(coverage)
coverage = this.sourceMapTransform(coverage)
}

fs.writeFileSync(
Expand All @@ -306,6 +306,13 @@ NYC.prototype.writeCoverageFile = function () {
)
}

NYC.prototype.sourceMapTransform = function (obj) {
var transformed = this.sourceMapCache.transformCoverage(
libCoverage.createCoverageMap(obj)
)
return transformed.map.data
}

function coverageFinder () {
var coverage = global.__coverage__
if (typeof __coverage__ === 'object') coverage = __coverage__
Expand Down Expand Up @@ -388,11 +395,11 @@ NYC.prototype._loadReports = function () {
}
}
if (loadedMaps[hash]) {
_this.sourceMapCache.addMap(absFile, loadedMaps[hash])
_this.sourceMapCache.registerMap(absFile, loadedMaps[hash])
}
}
})
_this.sourceMapCache.applySourceMaps(report)
report = _this.sourceMapTransform(report)
return report
})
}
Expand Down
3 changes: 3 additions & 0 deletions lib/instrumenters/noop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ function NOOP () {
return {
instrumentSync: function (code) {
return code
},
lastFileCoverage: function () {
return null
}
}
}
Expand Down
187 changes: 0 additions & 187 deletions lib/source-map-cache.js

This file was deleted.

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"clean": "rimraf ./.nyc_output ./node_modules/.cache ./.self_coverage ./test/fixtures/.nyc_output ./test/fixtures/node_modules/.cache *covered.js ./lib/*covered.js",
"build": "node ./build-tests",
"instrument": "node ./build-self-coverage.js",
"run-tests": "tap -t120 --no-cov -b ./test/build/*.js ./test/src/source-map-cache.js ./test/src/nyc-bin.js",
"run-tests": "tap -t120 --no-cov -b ./test/build/*.js ./test/src/nyc-bin.js",
"report": "istanbul report --include=./.self_coverage/*.json lcov text",
"cover": "npm run clean && npm run build && npm run instrument && npm run run-tests && npm run report",
"dev": "npm run clean && npm run build && npm run run-tests",
Expand All @@ -34,7 +34,6 @@
"test/fixtures/coverage.js",
"test/build/*",
"test/nyc-test.js",
"test/source-map-cache.js",
"index.covered.js",
"test/fixtures/_generateCoverage.js"
]
Expand Down Expand Up @@ -79,11 +78,12 @@
"default-require-extensions": "^1.0.0",
"find-cache-dir": "^0.1.1",
"find-up": "^1.1.2",
"foreground-child": "^1.5.1",
"foreground-child": "^1.5.3",
"glob": "^7.0.3",
"istanbul-lib-coverage": "^1.0.0-alpha.4",
"istanbul-lib-instrument": "^1.1.0-alpha.1",
"istanbul-lib-report": "^1.0.0-alpha.3",
"istanbul-lib-source-maps": "^1.0.0-alpha.10",
"istanbul-reports": "^1.0.0-alpha.6",
"md5-hex": "^1.2.0",
"micromatch": "^2.3.7",
Expand All @@ -92,7 +92,6 @@
"resolve-from": "^2.0.0",
"rimraf": "^2.5.0",
"signal-exit": "^3.0.0",
"source-map": "^0.5.3",
"spawn-wrap": "^1.2.2",
"test-exclude": "^1.1.0",
"yargs": "^4.7.0"
Expand All @@ -110,12 +109,11 @@
"newline-regex": "^0.2.1",
"sanitize-filename": "^1.5.3",
"sinon": "^1.15.3",
"source-map-fixtures": "^2.1.0",
"source-map-support": "^0.4.0",
"source-map-support": "^0.4.1",
"split-lines": "^1.0.0",
"standard": "^7.0.1",
"standard-version": "^2.2.1",
"tap": "^5.7.1",
"tap": "^6.1.1",
"which": "^1.2.4",
"zero-fill": "^2.2.3"
},
Expand Down
Loading

0 comments on commit 48929e6

Please sign in to comment.