Skip to content

Commit

Permalink
feat: cache realpath and realpathSync methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Mar 5, 2024
1 parent 91bd21f commit 576ef3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/CachedInputFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

/**
Expand All @@ -589,5 +602,6 @@ module.exports = class CachedInputFileSystem {
this._readFileBackend.purge(what);
this._readlinkBackend.purge(what);
this._readJsonBackend.purge(what);
this._realpathBackend.purge(what);
}
};
2 changes: 2 additions & 0 deletions lib/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const {
* @property {(function(string, FileSystemCallback<Buffer | string>): void) & function(string, object, FileSystemCallback<Buffer | string>): void} readlink
* @property {(function(string, FileSystemCallback<FileSystemStats>): void) & function(string, object, FileSystemCallback<Buffer | string>): void=} lstat
* @property {(function(string, FileSystemCallback<FileSystemStats>): void) & function(string, object, FileSystemCallback<Buffer | string>): void} stat
* @property {(function(string, FileSystemCallback<FileSystemStats>): void) & function(string, object, FileSystemCallback<Buffer | string>): void} realpath
*/

/**
Expand All @@ -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
*/

/**
Expand Down

0 comments on commit 576ef3b

Please sign in to comment.