Skip to content
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: Purge source-map cache before reporting if cache is disabled. #1080

Merged
merged 2 commits into from Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/nyc.js
Expand Up @@ -67,6 +67,7 @@ if ([

nyc.writeProcessIndex()

nyc.maybePurgeSourceMapCache()
if (argv.checkCoverage) {
nyc.checkCoverage({
lines: argv.lines,
Expand Down
6 changes: 6 additions & 0 deletions index.js
Expand Up @@ -236,6 +236,12 @@ class NYC {
return this._transform(code, filename)
}

maybePurgeSourceMapCache () {
if (!this.cache) {
JaKXz marked this conversation as resolved.
Show resolved Hide resolved
this.sourceMaps.purgeCache()
}
}

_transformFactory (cacheDir) {
const instrumenter = this.instrumenter()
let instrumented
Expand Down
8 changes: 7 additions & 1 deletion lib/source-maps.js
Expand Up @@ -4,14 +4,20 @@ const libSourceMaps = require('istanbul-lib-source-maps')
const fs = require('fs')
const path = require('path')

const sourceMapCache = libSourceMaps.createSourceMapStore()
let sourceMapCache = libSourceMaps.createSourceMapStore()
coreyfarrell marked this conversation as resolved.
Show resolved Hide resolved
function SourceMaps (opts) {
this.cache = opts.cache
this.cacheDirectory = opts.cacheDirectory
this.loadedMaps = {}
this._sourceMapCache = sourceMapCache
}

SourceMaps.prototype.purgeCache = function () {
sourceMapCache = libSourceMaps.createSourceMapStore()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we'd need to throw out source maps like this, might be worth digging into things a bit more, and figuring out how we end up with incompatible source-maps in the first place.

I'm not opposed to landing this as a patch as a temporary measure, but it feels like we're continuing to complicate our source-map and caching logic, which is already a mess. I think you're right that we just need to get way more test cases in the codebase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason we need to throw out transform results (they set cache: false).

this._sourceMapCache = sourceMapCache
this.loadedMaps = {}
}

SourceMaps.prototype.extractAndRegister = function (code, filename, hash) {
var sourceMap = convertSourceMap.fromSource(code) || convertSourceMap.fromMapFileSource(code, path.dirname(filename))
if (sourceMap) {
Expand Down