-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: respect cache flag in parent process #556
Changes from 2 commits
c93d14c
fdc59c5
c60b9e2
8f7bec7
5dc02cd
4cc24a8
24307c5
bd989a5
7db4380
c3f5bd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var convertSourceMap = require('convert-source-map') | ||
var libCoverage = require('istanbul-lib-coverage') | ||
var libSourceMaps = require('istanbul-lib-source-maps') | ||
var fs = require('fs') | ||
var path = require('path') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 will make more consistent usage of |
||
|
||
// TODO: write unit tests for source-maps, | ||
function SourceMaps (opts) { | ||
this.cacheDirectory = opts.cacheDirectory | ||
this.sourceMapCache = libSourceMaps.createSourceMapStore() | ||
this.loadedMaps = {} | ||
} | ||
|
||
SourceMaps.prototype.extractAndRegister = function (code, hash, filename) { | ||
var sourceMap = convertSourceMap.fromSource(code) || convertSourceMap.fromMapFileSource(code, path.dirname(filename)) | ||
if (sourceMap) { | ||
if (hash) { | ||
var mapPath = path.join(this.cacheDir, hash + '.map') | ||
fs.writeFileSync(mapPath, sourceMap.toJSON()) | ||
} else { | ||
this.sourceMapCache.registerMap(filename, sourceMap.sourcemap) | ||
} | ||
} | ||
return sourceMap | ||
} | ||
|
||
SourceMaps.prototype.remapCoverage = function (obj) { | ||
var transformed = this.sourceMapCache.transformCoverage( | ||
libCoverage.createCoverageMap(obj) | ||
) | ||
return transformed.map.data | ||
} | ||
|
||
SourceMaps.prototype.reloadCachedSourceMaps = function (report) { | ||
var _this = this | ||
Object.keys(report).forEach(function (absFile) { | ||
var fileReport = report[absFile] | ||
if (fileReport && fileReport.contentHash) { | ||
var hash = fileReport.contentHash | ||
if (!(hash in _this.loadedMaps)) { | ||
try { | ||
var mapPath = path.join(_this.cacheDirectory, hash + '.map') | ||
_this.loadedMaps[hash] = JSON.parse(fs.readFileSync(mapPath, 'utf8')) | ||
} catch (e) { | ||
// set to false to avoid repeatedly trying to load the map | ||
_this.loadedMaps[hash] = false | ||
} | ||
} | ||
if (_this.loadedMaps[hash]) { | ||
_this.sourceMapCache.registerMap(absFile, _this.loadedMaps[hash]) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
module.exports = SourceMaps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add a test for this statement