Skip to content

Commit b7a413a

Browse files
authored
fix: add a feature which allows us to bust the cache when breaking changes are introduced (#394)
* fix: add a feature which allows us to bust the cache when breaking changes are introduced * fix: use package.version for CACHE_VERSION based on @timoxley's review * fix: ignore line that will never load, because why not
1 parent 1c2349b commit b7a413a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ var ProcessInfo
2424
try {
2525
ProcessInfo = require('./lib/process.covered.js')
2626
} catch (e) {
27+
/* istanbul ignore next */
2728
ProcessInfo = require('./lib/process.js')
2829
}
2930

31+
// bust cache whenever nyc is upgraded, this prevents
32+
// crashers caused by instrumentation updates.
33+
var CACHE_VERSION = require('./package.json').version
34+
3035
/* istanbul ignore next */
3136
if (/index\.covered\.js$/.test(__filename)) {
3237
require('./lib/self-coverage-helper')
@@ -83,13 +88,14 @@ function NYC (config) {
8388

8489
NYC.prototype._createTransform = function (ext) {
8590
var _this = this
91+
8692
return cachingTransform({
8793
salt: JSON.stringify({
8894
istanbul: require('istanbul-lib-coverage/package.json').version,
8995
nyc: require('./package.json').version
9096
}),
9197
hash: function (code, metadata, salt) {
92-
var hash = md5hex([code, metadata.filename, salt])
98+
var hash = md5hex([code, metadata.filename, salt]) + '_' + CACHE_VERSION
9399
_this.hashCache[metadata.filename] = hash
94100
return hash
95101
},

0 commit comments

Comments
 (0)