Code coverage report for lib\CachePlugin.js

Statements: 55.56% (15 / 27)      Branches: 28.57% (4 / 14)      Functions: 62.5% (5 / 8)      Lines: 56% (14 / 25)      Ignored: none     

All files » lib\ » CachePlugin.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43        1   1 483   1   1 483         483 490   483 483                             483 490 490 490      
/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
var async = require("async");
 
function CachePlugin(cache) {
	this.cache = cache || {};
}
module.exports = CachePlugin;
 
CachePlugin.prototype.apply = function(compiler) {
	Iif(Array.isArray(compiler.compilers)) {
		compiler.compilers.forEach(function(c, idx) {
			c.apply(new CachePlugin(this.cache[idx] = this.cache[idx] || {}));
		}, this);
	} else {
		compiler.plugin("compilation", function(compilation) {
			compilation.cache = this.cache;
		}.bind(this));
		compiler.plugin("run", function(compiler, callback) {
			Eif(!compiler._lastCompilationFileDependencies) return callback();
			var fs = compiler.inputFileSystem;
			fileTs = compiler.fileTimestamps = {};
			async.forEach(compiler._lastCompilationFileDependencies, function(file, callback) {
				fs.stat(file, function(err, stat) {
					if(err) {
						if(err.code === 'ENOENT') return callback();
						return callback(err);
					}
					
					fileTs[file] = stat.mtime || Infinity;
					callback();
				});
			}, callback);
		}.bind(this));
		compiler.plugin("after-compile", function(compilation, callback) {
			compilation.compiler._lastCompilationFileDependencies = compilation.fileDependencies;
			compilation.compiler._lastCompilationContextDependencies = compilation.contextDependencies;
			callback();
		}.bind(this));
	}
};