Skip to content

Commit 2f1af27

Browse files
author
Benjamin Coe
committed
feat: switch to using istanbul-lib-source-maps
1 parent 16a7405 commit 2f1af27

7 files changed

Lines changed: 24 additions & 377 deletions

File tree

bin/nyc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ if (argv._[0] === 'report') {
141141
require: argv.require,
142142
include: argv.include,
143143
exclude: argv.exclude,
144-
sourceMap: !!argv.sourceMap
144+
sourceMap: !!argv.sourceMap,
145+
instrumenter: argv.instrumenter
145146
}))
146147
nyc.reset()
147148

build-self-coverage.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ var fs = require('fs')
33
var path = require('path')
44

55
;[
6-
'index.js',
7-
'lib/source-map-cache.js'
6+
'index.js'
87
].forEach(function (name) {
98
var indexPath = path.join(__dirname, name)
109
var source = fs.readFileSync(indexPath, 'utf8')

index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var fs = require('fs')
33
var glob = require('glob')
44
var libCoverage = require('istanbul-lib-coverage')
55
var libReport = require('istanbul-lib-report')
6+
var libSourceMaps = require('istanbul-lib-source-maps')
67
var reports = require('istanbul-reports')
78
var mkdirp = require('mkdirp')
89
var Module = require('module')
@@ -13,7 +14,6 @@ var rimraf = require('rimraf')
1314
var onExit = require('signal-exit')
1415
var resolveFrom = require('resolve-from')
1516
var arrify = require('arrify')
16-
var SourceMapCache = require('./lib/source-map-cache')
1717
var convertSourceMap = require('convert-source-map')
1818
var md5hex = require('md5-hex')
1919
var findCacheDir = require('find-cache-dir')
@@ -65,7 +65,7 @@ function NYC (opts) {
6565
return transforms
6666
}.bind(this), {})
6767

68-
this.sourceMapCache = new SourceMapCache()
68+
this.sourceMapCache = libSourceMaps.createSourceMapStore()
6969

7070
this.hashCache = {}
7171
this.loadedMaps = null
@@ -230,7 +230,7 @@ NYC.prototype._handleSourceMap = function (cacheDir, code, hash, filename) {
230230
var mapPath = path.join(cacheDir, hash + '.map')
231231
fs.writeFileSync(mapPath, sourceMap.toJSON())
232232
} else {
233-
this.sourceMapCache.addMap(filename, sourceMap.toJSON())
233+
this.sourceMapCache.registerMap(filename, sourceMap.sourcemap)
234234
}
235235
}
236236
}
@@ -296,7 +296,7 @@ NYC.prototype.writeCoverageFile = function () {
296296
}
297297
}, this)
298298
} else {
299-
this.sourceMapCache.applySourceMaps(coverage)
299+
coverage = this.sourceMapTransform(coverage)
300300
}
301301

302302
fs.writeFileSync(
@@ -306,6 +306,13 @@ NYC.prototype.writeCoverageFile = function () {
306306
)
307307
}
308308

309+
NYC.prototype.sourceMapTransform = function (obj) {
310+
var transformed = this.sourceMapCache.transformCoverage(
311+
libCoverage.createCoverageMap(obj)
312+
)
313+
return transformed.map.data
314+
}
315+
309316
function coverageFinder () {
310317
var coverage = global.__coverage__
311318
if (typeof __coverage__ === 'object') coverage = __coverage__
@@ -388,11 +395,11 @@ NYC.prototype._loadReports = function () {
388395
}
389396
}
390397
if (loadedMaps[hash]) {
391-
_this.sourceMapCache.addMap(absFile, loadedMaps[hash])
398+
_this.sourceMapCache.registerMap(absFile, loadedMaps[hash])
392399
}
393400
}
394401
})
395-
_this.sourceMapCache.applySourceMaps(report)
402+
report = _this.sourceMapTransform(report)
396403
return report
397404
})
398405
}

lib/instrumenters/noop.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ function NOOP () {
22
return {
33
instrumentSync: function (code) {
44
return code
5+
},
6+
lastFileCoverage: function () {
7+
return null
58
}
69
}
710
}

lib/source-map-cache.js

Lines changed: 0 additions & 187 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"clean": "rimraf ./.nyc_output ./node_modules/.cache ./.self_coverage ./test/fixtures/.nyc_output ./test/fixtures/node_modules/.cache *covered.js ./lib/*covered.js",
1111
"build": "node ./build-tests",
1212
"instrument": "node ./build-self-coverage.js",
13-
"run-tests": "tap -t120 --no-cov -b ./test/build/*.js ./test/src/source-map-cache.js ./test/src/nyc-bin.js",
13+
"run-tests": "tap -t120 --no-cov -b ./test/build/*.js ./test/src/nyc-bin.js",
1414
"report": "istanbul report --include=./.self_coverage/*.json lcov text",
1515
"cover": "npm run clean && npm run build && npm run instrument && npm run run-tests && npm run report",
1616
"dev": "npm run clean && npm run build && npm run run-tests",
@@ -34,7 +34,6 @@
3434
"test/fixtures/coverage.js",
3535
"test/build/*",
3636
"test/nyc-test.js",
37-
"test/source-map-cache.js",
3837
"index.covered.js",
3938
"test/fixtures/_generateCoverage.js"
4039
]
@@ -79,11 +78,12 @@
7978
"default-require-extensions": "^1.0.0",
8079
"find-cache-dir": "^0.1.1",
8180
"find-up": "^1.1.2",
82-
"foreground-child": "^1.5.1",
81+
"foreground-child": "^1.5.3",
8382
"glob": "^7.0.3",
8483
"istanbul-lib-coverage": "^1.0.0-alpha.4",
8584
"istanbul-lib-instrument": "^1.1.0-alpha.1",
8685
"istanbul-lib-report": "^1.0.0-alpha.3",
86+
"istanbul-lib-source-maps": "^1.0.0-alpha.10",
8787
"istanbul-reports": "^1.0.0-alpha.6",
8888
"md5-hex": "^1.2.0",
8989
"micromatch": "^2.3.7",
@@ -92,7 +92,6 @@
9292
"resolve-from": "^2.0.0",
9393
"rimraf": "^2.5.0",
9494
"signal-exit": "^3.0.0",
95-
"source-map": "^0.5.3",
9695
"spawn-wrap": "^1.2.2",
9796
"test-exclude": "^1.1.0",
9897
"yargs": "^4.7.0"
@@ -110,12 +109,11 @@
110109
"newline-regex": "^0.2.1",
111110
"sanitize-filename": "^1.5.3",
112111
"sinon": "^1.15.3",
113-
"source-map-fixtures": "^2.1.0",
114-
"source-map-support": "^0.4.0",
112+
"source-map-support": "^0.4.1",
115113
"split-lines": "^1.0.0",
116114
"standard": "^7.0.1",
117115
"standard-version": "^2.2.1",
118-
"tap": "^6.0.0",
116+
"tap": "^6.1.1",
119117
"which": "^1.2.4",
120118
"zero-fill": "^2.2.3"
121119
},

0 commit comments

Comments
 (0)