From 0d6d26b95a5c25cc9d6a700d700b242775d6d6b7 Mon Sep 17 00:00:00 2001 From: Gal carmi <46649273+Galcarmi@users.noreply.github.com> Date: Tue, 30 Apr 2024 11:17:47 +0300 Subject: [PATCH 1/4] fix --- lib/util/path.js | 5 +++-- package.json | 1 + yarn.lock | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/util/path.js b/lib/util/path.js index 4a65c6e3..343f5e9a 100644 --- a/lib/util/path.js +++ b/lib/util/path.js @@ -6,6 +6,7 @@ "use strict"; const path = require("path"); +const { LRUCache } = require("lru-cache"); const CHAR_HASH = "#".charCodeAt(0); const CHAR_SLASH = "/".charCodeAt(0); @@ -170,8 +171,8 @@ const join = (rootPath, request) => { }; exports.join = join; -/** @type {Map>} */ -const joinCache = new Map(); +/** @type {LRUCache>} */ +const joinCache = new LRUCache({ max: 500 }); /** * @param {string} rootPath the root path diff --git a/package.json b/package.json index f9f32020..c849b42d 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ }, "dependencies": { "graceful-fs": "^4.2.4", + "lru-cache": "^10.2.2", "tapable": "^2.2.0" }, "license": "MIT", diff --git a/yarn.lock b/yarn.lock index 7e0355bd..2f8addd9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3063,6 +3063,11 @@ log-update@^4.0.0: slice-ansi "^4.0.0" wrap-ansi "^6.2.0" +lru-cache@^10.2.2: + version "10.2.2" + resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.2.tgz#48206bc114c1252940c41b25b41af5b545aca878" + integrity sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ== + lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" From 86fd6ca0dcbce9536bdccb26251efd70177a1c73 Mon Sep 17 00:00:00 2001 From: Gal Carmi Date: Tue, 7 May 2024 17:41:21 +0300 Subject: [PATCH 2/4] fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c849b42d..af369ff5 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "enhanced-resolve", + "name": "enhanced-resolvee", "version": "5.16.0", "author": "Tobias Koppers @sokra", "description": "Offers a async require.resolve function. It's highly configurable.", From 6b55c49e6cdd76fbc2cb565055481581e360c257 Mon Sep 17 00:00:00 2001 From: Gal Carmi Date: Tue, 7 May 2024 17:42:26 +0300 Subject: [PATCH 3/4] fix --- lib/LRUCache.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/LRUCache.js diff --git a/lib/LRUCache.js b/lib/LRUCache.js new file mode 100644 index 00000000..6bf4ff01 --- /dev/null +++ b/lib/LRUCache.js @@ -0,0 +1,45 @@ +class LRUCache { + /** + * @param {number} maxSize maxSize + */ + constructor(maxSize) { + this._maxSize = maxSize; + /** @type {string[]} */ + this._doublyQueue = []; + this._cacheMap = new Map(); + } + + /** + * @param {string} item item + */ + get(item) { + if (this._cacheMap.has(item)) { + const itemData = this._doublyQueue.splice( + this._doublyQueue.indexOf(item), + 1 + ); + this._doublyQueue.unshift(item); + + if (itemData.length > 0) { + this._cacheMap.set(item, itemData[0]); + } + } + } + + /** + * @param {any} item item + * @param {any} itemData itemData + */ + set(item, itemData) { + if (this._doublyQueue.length === this._maxSize) { + const last = this._doublyQueue[this._doublyQueue.length - 1]; + this._doublyQueue.pop(); + this._cacheMap.delete(last); + } + + this._doublyQueue.unshift(item); + this._cacheMap.set(item, itemData); + } +} + +module.exports = LRUCache; From b7dcd3e97548ffd042797efadc74168cb6b81fc4 Mon Sep 17 00:00:00 2001 From: Gal Carmi Date: Tue, 7 May 2024 17:42:52 +0300 Subject: [PATCH 4/4] fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index af369ff5..c849b42d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "enhanced-resolvee", + "name": "enhanced-resolve", "version": "5.16.0", "author": "Tobias Koppers @sokra", "description": "Offers a async require.resolve function. It's highly configurable.",