@file-services/cached
Advanced tools
Comparing version 7.0.1 to 7.2.0
@@ -11,2 +11,3 @@ "use strict"; | ||
const realpathCache = new Map(); | ||
const realpathNativeCache = new Map(); | ||
const { promises, delimiter } = fs; | ||
@@ -18,2 +19,3 @@ const suffixTrue = delimiter + 'true'; | ||
realpathCache.delete(cachePath); | ||
realpathNativeCache.delete(cachePath); | ||
statsCache.delete(cachePath + suffixTrue); | ||
@@ -29,2 +31,7 @@ statsCache.delete(cachePath + suffixFalse); | ||
} | ||
for (const key of realpathNativeCache.keys()) { | ||
if (key.startsWith(prefix)) { | ||
realpathNativeCache.delete(key); | ||
} | ||
} | ||
for (const key of statsCache.keys()) { | ||
@@ -36,2 +43,24 @@ if (key.startsWith(prefix)) { | ||
}; | ||
function realpathSync(path) { | ||
path = fs.resolve(path); | ||
const cacheKey = getCanonicalPath(path); | ||
const cachedActualPath = realpathCache.get(cacheKey); | ||
if (cachedActualPath !== undefined) { | ||
return cachedActualPath; | ||
} | ||
const actualPath = fs.realpathSync(path); | ||
realpathCache.set(cacheKey, actualPath); | ||
return actualPath; | ||
} | ||
realpathSync.native = function realpathSyncNative(path) { | ||
path = fs.resolve(path); | ||
const cacheKey = getCanonicalPath(path); | ||
const cachedActualPath = realpathNativeCache.get(cacheKey); | ||
if (cachedActualPath !== undefined) { | ||
return cachedActualPath; | ||
} | ||
const actualPath = fs.realpathSync.native(path); | ||
realpathNativeCache.set(cacheKey, actualPath); | ||
return actualPath; | ||
}; | ||
return { | ||
@@ -165,13 +194,3 @@ ...(0, utils_1.createFileSystem)({ | ||
}, | ||
realpathSync(path) { | ||
path = fs.resolve(path); | ||
const cacheKey = getCanonicalPath(path); | ||
const cachedActualPath = realpathCache.get(cacheKey); | ||
if (cachedActualPath !== undefined) { | ||
return cachedActualPath; | ||
} | ||
const actualPath = fs.realpathSync(path); | ||
realpathCache.set(cacheKey, actualPath); | ||
return actualPath; | ||
}, | ||
realpathSync, | ||
realpath(path, callback) { | ||
@@ -178,0 +197,0 @@ path = fs.resolve(path); |
{ | ||
"name": "@file-services/cached", | ||
"description": "A file system wrapper that adds cache to any `IFileSystem` implementation.", | ||
"version": "7.0.1", | ||
"version": "7.2.0", | ||
"main": "dist/index.js", | ||
@@ -12,4 +12,4 @@ "scripts": { | ||
"dependencies": { | ||
"@file-services/types": "^7.0.1", | ||
"@file-services/utils": "^7.0.1" | ||
"@file-services/types": "^7.2.0", | ||
"@file-services/utils": "^7.2.0" | ||
}, | ||
@@ -16,0 +16,0 @@ "files": [ |
@@ -33,2 +33,3 @@ import type { IFileSystem, IFileSystemStats, CallbackFnVoid } from '@file-services/types'; | ||
const realpathCache = new Map<string, string>(); | ||
const realpathNativeCache = new Map<string, string>(); | ||
const { promises, delimiter } = fs; | ||
@@ -42,2 +43,3 @@ | ||
realpathCache.delete(cachePath); | ||
realpathNativeCache.delete(cachePath); | ||
statsCache.delete(cachePath + suffixTrue); | ||
@@ -53,2 +55,7 @@ statsCache.delete(cachePath + suffixFalse); | ||
} | ||
for (const key of realpathNativeCache.keys()) { | ||
if (key.startsWith(prefix)) { | ||
realpathNativeCache.delete(key); | ||
} | ||
} | ||
for (const key of statsCache.keys()) { | ||
@@ -61,2 +68,26 @@ if (key.startsWith(prefix)) { | ||
function realpathSync(path: string): string { | ||
path = fs.resolve(path); | ||
const cacheKey = getCanonicalPath(path); | ||
const cachedActualPath = realpathCache.get(cacheKey); | ||
if (cachedActualPath !== undefined) { | ||
return cachedActualPath; | ||
} | ||
const actualPath = fs.realpathSync(path); | ||
realpathCache.set(cacheKey, actualPath); | ||
return actualPath; | ||
} | ||
realpathSync.native = function realpathSyncNative(path: string): string { | ||
path = fs.resolve(path); | ||
const cacheKey = getCanonicalPath(path); | ||
const cachedActualPath = realpathNativeCache.get(cacheKey); | ||
if (cachedActualPath !== undefined) { | ||
return cachedActualPath; | ||
} | ||
const actualPath = fs.realpathSync.native(path); | ||
realpathNativeCache.set(cacheKey, actualPath); | ||
return actualPath; | ||
}; | ||
return { | ||
@@ -186,13 +217,3 @@ ...createFileSystem({ | ||
}, | ||
realpathSync(path) { | ||
path = fs.resolve(path); | ||
const cacheKey = getCanonicalPath(path); | ||
const cachedActualPath = realpathCache.get(cacheKey); | ||
if (cachedActualPath !== undefined) { | ||
return cachedActualPath; | ||
} | ||
const actualPath = fs.realpathSync(path); | ||
realpathCache.set(cacheKey, actualPath); | ||
return actualPath; | ||
}, | ||
realpathSync, | ||
realpath(path, callback) { | ||
@@ -199,0 +220,0 @@ path = fs.resolve(path); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39134
639
9
Updated@file-services/types@^7.2.0
Updated@file-services/utils@^7.2.0