From 576ef3be3d576a692a5ca2f48b620101b7a1c369 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Tue, 5 Mar 2024 17:53:34 +0300 Subject: [PATCH] feat: cache `realpath` and `realpathSync` methods --- lib/CachedInputFileSystem.js | 14 ++++++++++++++ lib/Resolver.js | 2 ++ 2 files changed, 16 insertions(+) diff --git a/lib/CachedInputFileSystem.js b/lib/CachedInputFileSystem.js index 022e72c0..4129fa04 100644 --- a/lib/CachedInputFileSystem.js +++ b/lib/CachedInputFileSystem.js @@ -577,6 +577,19 @@ module.exports = class CachedInputFileSystem { this.readlinkSync = /** @type {SyncFileSystem["readlinkSync"]} */ ( readlinkSync ); + + this._realpathBackend = createBackend( + duration, + this.fileSystem.realpath, + this.fileSystem.realpath, + this.fileSystem + ); + const realpath = this._realpathBackend.provide; + this.realpath = /** @type {FileSystem["realpath"]} */ (realpath); + const realpathSync = this._realpathBackend.provideSync; + this.realpathSync = /** @type {SyncFileSystem["realpathSync"]} */ ( + realpathSync + ); } /** @@ -589,5 +602,6 @@ module.exports = class CachedInputFileSystem { this._readFileBackend.purge(what); this._readlinkBackend.purge(what); this._readJsonBackend.purge(what); + this._realpathBackend.purge(what); } }; diff --git a/lib/Resolver.js b/lib/Resolver.js index 8806bb1c..0580a424 100644 --- a/lib/Resolver.js +++ b/lib/Resolver.js @@ -65,6 +65,7 @@ const { * @property {(function(string, FileSystemCallback): void) & function(string, object, FileSystemCallback): void} readlink * @property {(function(string, FileSystemCallback): void) & function(string, object, FileSystemCallback): void=} lstat * @property {(function(string, FileSystemCallback): void) & function(string, object, FileSystemCallback): void} stat + * @property {(function(string, FileSystemCallback): void) & function(string, object, FileSystemCallback): void} realpath */ /** @@ -75,6 +76,7 @@ const { * @property {function(string, object=): Buffer | string} readlinkSync * @property {function(string, object=): FileSystemStats=} lstatSync * @property {function(string, object=): FileSystemStats} statSync + * @property {function(string, object=): string | Buffer} realpathSync */ /**