Sha256: 865a643c2b126a89e6b4ef2be086c4615e04815d45a2a6f1c8552cd0227fdd00

Contents?: true

Size: 986 Bytes

Versions: 62

Compression:

Stored size: 986 Bytes

Contents

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
function UnsafeCachePlugin(regExps, cache) {
	this.regExps = regExps || [/./];
	if(this.regExps === true) this.regExps = [/./];
	else if(!Array.isArray(this.regExps)) this.regExps = [this.regExps];
	this.cache = cache || {};
}
module.exports = UnsafeCachePlugin;

UnsafeCachePlugin.prototype.apply = function(resolver) {
	var oldResolve = resolver.resolve;
	var regExps = this.regExps;
	var cache = this.cache;
	resolver.resolve = function resolve(context, request, callback) {
		var id = context + "->" + request;
		if(cache[id]) {
			// From cache
			return callback(null, cache[id]);
		}
		oldResolve.call(resolver, context, request, function(err, result) {
			if(err) return callback(err);
			var doCache = regExps.some(function(regExp) {
				return regExp.test(result.path);
			});
			if(!doCache) return callback(null, result);
			callback(null, cache[id] = result);
		});
	};
};

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
smock-0.1.268 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.267 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.266 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.265 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.264 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.263 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.262 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.261 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.260 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.259 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.258 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.256 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.255 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.254 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.253 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.252 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.251 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.250 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.249 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js
smock-0.1.247 node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js