From bbff7403fbf46f9ad92240ac213df8d30ef31b64 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Sep 2018 02:56:13 +0200 Subject: update packages --- .../enhanced-resolve/lib/UnsafeCachePlugin.js | 54 +++++++++++----------- 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js') diff --git a/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js b/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js index ed07fd561..9a80b3209 100644 --- a/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js +++ b/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js @@ -2,16 +2,7 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ -var createInnerCallback = require("./createInnerCallback"); - -function UnsafeCachePlugin(source, filterPredicate, cache, withContext, target) { - this.source = source; - this.filterPredicate = filterPredicate; - this.withContext = withContext; - this.cache = cache || {}; - this.target = target; -} -module.exports = UnsafeCachePlugin; +"use strict"; function getCacheId(request, withContext) { return JSON.stringify({ @@ -22,22 +13,29 @@ function getCacheId(request, withContext) { }); } -UnsafeCachePlugin.prototype.apply = function(resolver) { - var filterPredicate = this.filterPredicate; - var cache = this.cache; - var target = this.target; - var withContext = this.withContext; - resolver.plugin(this.source, function(request, callback) { - if(!filterPredicate(request)) return callback(); - var cacheId = getCacheId(request, withContext); - var cacheEntry = cache[cacheId]; - if(cacheEntry) { - return callback(null, cacheEntry); - } - resolver.doResolve(target, request, null, createInnerCallback(function(err, result) { - if(err) return callback(err); - if(result) return callback(null, cache[cacheId] = result); - callback(); - }, callback)); - }); +module.exports = class UnsafeCachePlugin { + constructor(source, filterPredicate, cache, withContext, target) { + this.source = source; + this.filterPredicate = filterPredicate; + this.withContext = withContext; + this.cache = cache || {}; + this.target = target; + } + + apply(resolver) { + const target = resolver.ensureHook(this.target); + resolver.getHook(this.source).tapAsync("UnsafeCachePlugin", (request, resolveContext, callback) => { + if(!this.filterPredicate(request)) return callback(); + const cacheId = getCacheId(request, this.withContext); + const cacheEntry = this.cache[cacheId]; + if(cacheEntry) { + return callback(null, cacheEntry); + } + resolver.doResolve(target, request, null, resolveContext, (err, result) => { + if(err) return callback(err); + if(result) return callback(null, this.cache[cacheId] = result); + callback(); + }); + }); + } }; -- cgit v1.2.3