Skip to content

Commit 576ef3b

Browse files
feat: cache realpath and realpathSync methods
1 parent 91bd21f commit 576ef3b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/CachedInputFileSystem.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,19 @@ module.exports = class CachedInputFileSystem {
577577
this.readlinkSync = /** @type {SyncFileSystem["readlinkSync"]} */ (
578578
readlinkSync
579579
);
580+
581+
this._realpathBackend = createBackend(
582+
duration,
583+
this.fileSystem.realpath,
584+
this.fileSystem.realpath,
585+
this.fileSystem
586+
);
587+
const realpath = this._realpathBackend.provide;
588+
this.realpath = /** @type {FileSystem["realpath"]} */ (realpath);
589+
const realpathSync = this._realpathBackend.provideSync;
590+
this.realpathSync = /** @type {SyncFileSystem["realpathSync"]} */ (
591+
realpathSync
592+
);
580593
}
581594

582595
/**
@@ -589,5 +602,6 @@ module.exports = class CachedInputFileSystem {
589602
this._readFileBackend.purge(what);
590603
this._readlinkBackend.purge(what);
591604
this._readJsonBackend.purge(what);
605+
this._realpathBackend.purge(what);
592606
}
593607
};

lib/Resolver.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const {
6565
* @property {(function(string, FileSystemCallback<Buffer | string>): void) & function(string, object, FileSystemCallback<Buffer | string>): void} readlink
6666
* @property {(function(string, FileSystemCallback<FileSystemStats>): void) & function(string, object, FileSystemCallback<Buffer | string>): void=} lstat
6767
* @property {(function(string, FileSystemCallback<FileSystemStats>): void) & function(string, object, FileSystemCallback<Buffer | string>): void} stat
68+
* @property {(function(string, FileSystemCallback<FileSystemStats>): void) & function(string, object, FileSystemCallback<Buffer | string>): void} realpath
6869
*/
6970

7071
/**
@@ -75,6 +76,7 @@ const {
7576
* @property {function(string, object=): Buffer | string} readlinkSync
7677
* @property {function(string, object=): FileSystemStats=} lstatSync
7778
* @property {function(string, object=): FileSystemStats} statSync
79+
* @property {function(string, object=): string | Buffer} realpathSync
7880
*/
7981

8082
/**

0 commit comments

Comments
 (0)