Skip to content

Commit 3d9eaa4

Browse files
authored
fix: Purge source-map cache before reporting if cache is disabled. (#1080)
1 parent 132a074 commit 3d9eaa4

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

bin/nyc.js

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ if ([
6767

6868
nyc.writeProcessIndex()
6969

70+
nyc.maybePurgeSourceMapCache()
7071
if (argv.checkCoverage) {
7172
nyc.checkCoverage({
7273
lines: argv.lines,

index.js

+6
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ class NYC {
236236
return this._transform(code, filename)
237237
}
238238

239+
maybePurgeSourceMapCache () {
240+
if (!this.cache) {
241+
this.sourceMaps.purgeCache()
242+
}
243+
}
244+
239245
_transformFactory (cacheDir) {
240246
const instrumenter = this.instrumenter()
241247
let instrumented

lib/source-maps.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ const libSourceMaps = require('istanbul-lib-source-maps')
44
const fs = require('fs')
55
const path = require('path')
66

7-
const sourceMapCache = libSourceMaps.createSourceMapStore()
87
function SourceMaps (opts) {
98
this.cache = opts.cache
109
this.cacheDirectory = opts.cacheDirectory
1110
this.loadedMaps = {}
12-
this._sourceMapCache = sourceMapCache
11+
this._sourceMapCache = libSourceMaps.createSourceMapStore()
12+
}
13+
14+
SourceMaps.prototype.purgeCache = function () {
15+
this._sourceMapCache = libSourceMaps.createSourceMapStore()
16+
this.loadedMaps = {}
1317
}
1418

1519
SourceMaps.prototype.extractAndRegister = function (code, filename, hash) {

test/source-maps.js

-20
This file was deleted.

0 commit comments

Comments
 (0)