From b7a413a6c369402464db9b231692943f851846d6 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Thu, 15 Sep 2016 09:55:10 -0700 Subject: [PATCH] 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 --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d64c3787f..0df16f6c9 100755 --- a/index.js +++ b/index.js @@ -24,9 +24,14 @@ var ProcessInfo try { ProcessInfo = require('./lib/process.covered.js') } catch (e) { + /* istanbul ignore next */ ProcessInfo = require('./lib/process.js') } +// bust cache whenever nyc is upgraded, this prevents +// crashers caused by instrumentation updates. +var CACHE_VERSION = require('./package.json').version + /* istanbul ignore next */ if (/index\.covered\.js$/.test(__filename)) { require('./lib/self-coverage-helper') @@ -83,13 +88,14 @@ function NYC (config) { NYC.prototype._createTransform = function (ext) { var _this = this + return cachingTransform({ salt: JSON.stringify({ istanbul: require('istanbul-lib-coverage/package.json').version, nyc: require('./package.json').version }), hash: function (code, metadata, salt) { - var hash = md5hex([code, metadata.filename, salt]) + var hash = md5hex([code, metadata.filename, salt]) + '_' + CACHE_VERSION _this.hashCache[metadata.filename] = hash return hash },