@file-services/cached
Advanced tools
@@ -1,2 +0,2 @@ | ||
| import type { IFileSystem } from '@file-services/types'; | ||
| import type { IFileSystem } from "@file-services/types"; | ||
| export interface ICachedFileSystem extends IFileSystem { | ||
@@ -3,0 +3,0 @@ /** |
| { | ||
| "version": 3, | ||
| "sources": ["../src/index.ts", "../src/cached-fs.ts"], | ||
| "sourcesContent": ["export * from './cached-fs';\n", "import type { IFileSystem, IFileSystemStats, CallbackFnVoid } from '@file-services/types';\nimport { createFileSystem } from '@file-services/utils';\n\nconst identity = (val: string) => val;\nconst toLowerCase = (val: string) => val.toLowerCase();\n\nexport interface ICachedFileSystem extends IFileSystem {\n /**\n *\n * @param path the file path to clear from the cache\n */\n invalidate(path: string, deep?: boolean): void;\n /**\n * invalidates all files\n */\n invalidateAll(): void;\n}\n\ninterface ISuccessCacheResult<T> {\n kind: 'success';\n value: T;\n}\n\ninterface IFailureCacheResult {\n kind: 'failure';\n error: Error;\n}\n\nexport function createCachedFs(fs: IFileSystem): ICachedFileSystem {\n const getCanonicalPath = fs.caseSensitive ? identity : toLowerCase;\n const statsCache = new Map<string, ISuccessCacheResult<IFileSystemStats | undefined> | IFailureCacheResult>();\n const realpathCache = new Map<string, string>();\n const realpathNativeCache = new Map<string, string>();\n const { promises, delimiter } = fs;\n\n const suffixTrue = delimiter + 'true';\n const suffixFalse = delimiter + 'false';\n\n const invalidateAbsolute = (absolutePath: string) => {\n const cachePath = getCanonicalPath(absolutePath);\n realpathCache.delete(cachePath);\n realpathNativeCache.delete(cachePath);\n statsCache.delete(cachePath + suffixTrue);\n statsCache.delete(cachePath + suffixFalse);\n };\n const invalidateAbsoluteByPrefix = (absolutePath: string) => {\n const prefix = getCanonicalPath(absolutePath);\n for (const key of realpathCache.keys()) {\n if (key.startsWith(prefix)) {\n realpathCache.delete(key);\n }\n }\n for (const key of realpathNativeCache.keys()) {\n if (key.startsWith(prefix)) {\n realpathNativeCache.delete(key);\n }\n }\n for (const key of statsCache.keys()) {\n if (key.startsWith(prefix)) {\n statsCache.delete(key);\n }\n }\n };\n\n function realpathSync(path: string): string {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = fs.realpathSync(path);\n realpathCache.set(cacheKey, actualPath);\n return actualPath;\n }\n\n realpathSync.native = function realpathSyncNative(path: string): string {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathNativeCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = fs.realpathSync.native(path);\n realpathNativeCache.set(cacheKey, actualPath);\n return actualPath;\n };\n\n return {\n ...createFileSystem({\n ...fs,\n copyFile: function copyFile(sourcePath: string, destinationPath: string, ...args: [CallbackFnVoid]) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return fs.copyFile(sourcePath, destinationPath, ...args);\n } as IFileSystem['copyFile'],\n copyFileSync(sourcePath, destinationPath, ...args) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return fs.copyFileSync(sourcePath, destinationPath, ...args);\n },\n mkdir: function mkdir(directoryPath: string, ...args: [CallbackFnVoid]) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.mkdir(directoryPath, ...args);\n } as IFileSystem['mkdir'],\n mkdirSync(directoryPath, ...args) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.mkdirSync(directoryPath, ...args);\n },\n rename(sourcePath, destinationPath, callback) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return fs.rename(sourcePath, destinationPath, callback);\n },\n renameSync(sourcePath, destinationPath) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return fs.renameSync(sourcePath, destinationPath);\n },\n rmdir(directoryPath, callback) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.rmdir(directoryPath, callback);\n },\n rmdirSync(directoryPath) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.rmdirSync(directoryPath);\n },\n rmSync(targetPath, options) {\n targetPath = fs.resolve(targetPath);\n invalidateAbsolute(targetPath);\n return fs.rmSync(targetPath, options);\n },\n symlinkSync(target, path, type) {\n path = fs.resolve(path);\n invalidateAbsolute(path);\n return fs.symlinkSync(target, path, type);\n },\n unlink(filePath, callback) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return fs.unlink(filePath, callback);\n },\n unlinkSync(filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return fs.unlinkSync(filePath);\n },\n writeFile: function writeFile(filePath: string, ...args: [string, CallbackFnVoid]) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return fs.writeFile(filePath, ...args);\n } as IFileSystem['writeFile'],\n writeFileSync(filePath, ...args) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return fs.writeFileSync(filePath, ...args);\n },\n statSync(path, options) {\n path = fs.resolve(path);\n const throwIfNoEntry = options?.throwIfNoEntry ?? true;\n const cacheKey = getCanonicalPath(path) + (throwIfNoEntry ? suffixTrue : suffixFalse);\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === 'failure') {\n throw cachedStats.error;\n }\n return cachedStats.value as IFileSystemStats;\n }\n try {\n const stats = fs.statSync(path, options);\n statsCache.set(cacheKey, { kind: 'success', value: stats });\n return stats as IFileSystemStats;\n } catch (e) {\n statsCache.set(cacheKey, { kind: 'failure', error: e as Error });\n throw e;\n }\n },\n stat(path, callback) {\n path = fs.resolve(path);\n // force throwIfNoEntry, as callback version doesn't support it\n const cacheKey = getCanonicalPath(path) + suffixTrue;\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === 'failure') {\n (callback as (e: Error) => void)(cachedStats.error);\n } else if (cachedStats.kind === 'success') {\n callback(null, cachedStats.value as IFileSystemStats);\n }\n } else {\n fs.stat(path, (error, stats) => {\n if (error) {\n statsCache.set(cacheKey, { kind: 'failure', error });\n } else {\n statsCache.set(cacheKey, { kind: 'success', value: stats });\n }\n\n callback(error, stats);\n });\n }\n },\n realpathSync,\n realpath(path, callback) {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n callback(null, cachedActualPath);\n } else {\n fs.realpath(path, (error, actualPath) => {\n if (!error) {\n realpathCache.set(cacheKey, actualPath);\n }\n callback(error, actualPath);\n });\n }\n },\n }),\n invalidate(path, deep = false) {\n const pathToInvalidate = fs.resolve(path);\n if (deep) {\n invalidateAbsoluteByPrefix(fs.join(pathToInvalidate, fs.sep));\n }\n return invalidateAbsolute(pathToInvalidate);\n },\n invalidateAll() {\n statsCache.clear();\n },\n promises: {\n ...promises,\n async realpath(path) {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = await promises.realpath(path);\n realpathCache.set(cacheKey, actualPath);\n return actualPath;\n },\n copyFile(sourcePath, destinationPath, ...args) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return promises.copyFile(sourcePath, destinationPath, ...args);\n },\n mkdir(directoryPath, ...args) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return promises.mkdir(directoryPath, ...args);\n },\n rename(sourcePath, destinationPath) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return promises.rename(sourcePath, destinationPath);\n },\n rmdir(directoryPath) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return promises.rmdir(directoryPath);\n },\n rm(targetPath, options) {\n targetPath = fs.resolve(targetPath);\n invalidateAbsolute(targetPath);\n return promises.rm(targetPath, options);\n },\n unlink(filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return promises.unlink(filePath);\n },\n writeFile(filePath, ...args) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return promises.writeFile(filePath, ...args);\n },\n async stat(path) {\n path = fs.resolve(path);\n // force throwIfNoEntry, as this function doesn't support it\n const cacheKey = getCanonicalPath(path) + suffixTrue;\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === 'failure') {\n throw cachedStats.error;\n }\n return cachedStats.value as IFileSystemStats;\n }\n try {\n const stats = await promises.stat(path);\n statsCache.set(cacheKey, { kind: 'success', value: stats });\n return stats;\n } catch (e) {\n statsCache.set(cacheKey, { kind: 'failure', error: e as Error });\n throw e;\n }\n },\n symlink(target, path, type) {\n path = fs.resolve(path);\n invalidateAbsolute(path);\n return promises.symlink(target, path, type);\n },\n },\n };\n}\n"], | ||
| "sourcesContent": ["export * from \"./cached-fs\";\n", "import type { IFileSystem, IFileSystemStats, CallbackFnVoid } from \"@file-services/types\";\nimport { createFileSystem } from \"@file-services/utils\";\n\nconst identity = (val: string) => val;\nconst toLowerCase = (val: string) => val.toLowerCase();\n\nexport interface ICachedFileSystem extends IFileSystem {\n /**\n *\n * @param path the file path to clear from the cache\n */\n invalidate(path: string, deep?: boolean): void;\n /**\n * invalidates all files\n */\n invalidateAll(): void;\n}\n\ninterface ISuccessCacheResult<T> {\n kind: \"success\";\n value: T;\n}\n\ninterface IFailureCacheResult {\n kind: \"failure\";\n error: Error;\n}\n\nexport function createCachedFs(fs: IFileSystem): ICachedFileSystem {\n const getCanonicalPath = fs.caseSensitive ? identity : toLowerCase;\n const statsCache = new Map<string, ISuccessCacheResult<IFileSystemStats | undefined> | IFailureCacheResult>();\n const realpathCache = new Map<string, string>();\n const realpathNativeCache = new Map<string, string>();\n const { promises, delimiter } = fs;\n\n const suffixTrue = delimiter + \"true\";\n const suffixFalse = delimiter + \"false\";\n\n const invalidateAbsolute = (absolutePath: string) => {\n const cachePath = getCanonicalPath(absolutePath);\n realpathCache.delete(cachePath);\n realpathNativeCache.delete(cachePath);\n statsCache.delete(cachePath + suffixTrue);\n statsCache.delete(cachePath + suffixFalse);\n };\n const invalidateAbsoluteByPrefix = (absolutePath: string) => {\n const prefix = getCanonicalPath(absolutePath);\n for (const key of realpathCache.keys()) {\n if (key.startsWith(prefix)) {\n realpathCache.delete(key);\n }\n }\n for (const key of realpathNativeCache.keys()) {\n if (key.startsWith(prefix)) {\n realpathNativeCache.delete(key);\n }\n }\n for (const key of statsCache.keys()) {\n if (key.startsWith(prefix)) {\n statsCache.delete(key);\n }\n }\n };\n\n function realpathSync(path: string): string {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = fs.realpathSync(path);\n realpathCache.set(cacheKey, actualPath);\n return actualPath;\n }\n\n realpathSync.native = function realpathSyncNative(path: string): string {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathNativeCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = fs.realpathSync.native(path);\n realpathNativeCache.set(cacheKey, actualPath);\n return actualPath;\n };\n\n return {\n ...createFileSystem({\n ...fs,\n copyFile: function copyFile(sourcePath: string, destinationPath: string, ...args: [CallbackFnVoid]) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return fs.copyFile(sourcePath, destinationPath, ...args);\n } as IFileSystem[\"copyFile\"],\n copyFileSync(sourcePath, destinationPath, ...args) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return fs.copyFileSync(sourcePath, destinationPath, ...args);\n },\n mkdir: function mkdir(directoryPath: string, ...args: [CallbackFnVoid]) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.mkdir(directoryPath, ...args);\n } as IFileSystem[\"mkdir\"],\n mkdirSync(directoryPath, ...args) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.mkdirSync(directoryPath, ...args);\n },\n rename(sourcePath, destinationPath, callback) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return fs.rename(sourcePath, destinationPath, callback);\n },\n renameSync(sourcePath, destinationPath) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return fs.renameSync(sourcePath, destinationPath);\n },\n rmdir(directoryPath, callback) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.rmdir(directoryPath, callback);\n },\n rmdirSync(directoryPath) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.rmdirSync(directoryPath);\n },\n rmSync(targetPath, options) {\n targetPath = fs.resolve(targetPath);\n invalidateAbsolute(targetPath);\n return fs.rmSync(targetPath, options);\n },\n symlinkSync(target, path, type) {\n path = fs.resolve(path);\n invalidateAbsolute(path);\n return fs.symlinkSync(target, path, type);\n },\n unlink(filePath, callback) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return fs.unlink(filePath, callback);\n },\n unlinkSync(filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return fs.unlinkSync(filePath);\n },\n writeFile: function writeFile(filePath: string, ...args: [string, CallbackFnVoid]) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return fs.writeFile(filePath, ...args);\n } as IFileSystem[\"writeFile\"],\n writeFileSync(filePath, ...args) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return fs.writeFileSync(filePath, ...args);\n },\n statSync(path, options) {\n path = fs.resolve(path);\n const throwIfNoEntry = options?.throwIfNoEntry ?? true;\n const cacheKey = getCanonicalPath(path) + (throwIfNoEntry ? suffixTrue : suffixFalse);\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === \"failure\") {\n throw cachedStats.error;\n }\n return cachedStats.value as IFileSystemStats;\n }\n try {\n const stats = fs.statSync(path, options);\n statsCache.set(cacheKey, { kind: \"success\", value: stats });\n return stats as IFileSystemStats;\n } catch (e) {\n statsCache.set(cacheKey, { kind: \"failure\", error: e as Error });\n throw e;\n }\n },\n stat(path, callback) {\n path = fs.resolve(path);\n // force throwIfNoEntry, as callback version doesn't support it\n const cacheKey = getCanonicalPath(path) + suffixTrue;\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === \"failure\") {\n (callback as (e: Error) => void)(cachedStats.error);\n } else if (cachedStats.kind === \"success\") {\n callback(null, cachedStats.value as IFileSystemStats);\n }\n } else {\n fs.stat(path, (error, stats) => {\n if (error) {\n statsCache.set(cacheKey, { kind: \"failure\", error });\n } else {\n statsCache.set(cacheKey, { kind: \"success\", value: stats });\n }\n\n callback(error, stats);\n });\n }\n },\n realpathSync,\n realpath(path, callback) {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n callback(null, cachedActualPath);\n } else {\n fs.realpath(path, (error, actualPath) => {\n if (!error) {\n realpathCache.set(cacheKey, actualPath);\n }\n callback(error, actualPath);\n });\n }\n },\n }),\n invalidate(path, deep = false) {\n const pathToInvalidate = fs.resolve(path);\n if (deep) {\n invalidateAbsoluteByPrefix(fs.join(pathToInvalidate, fs.sep));\n }\n return invalidateAbsolute(pathToInvalidate);\n },\n invalidateAll() {\n statsCache.clear();\n },\n promises: {\n ...promises,\n async realpath(path) {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = await promises.realpath(path);\n realpathCache.set(cacheKey, actualPath);\n return actualPath;\n },\n copyFile(sourcePath, destinationPath, ...args) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return promises.copyFile(sourcePath, destinationPath, ...args);\n },\n mkdir(directoryPath, ...args) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return promises.mkdir(directoryPath, ...args);\n },\n rename(sourcePath, destinationPath) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return promises.rename(sourcePath, destinationPath);\n },\n rmdir(directoryPath) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return promises.rmdir(directoryPath);\n },\n rm(targetPath, options) {\n targetPath = fs.resolve(targetPath);\n invalidateAbsolute(targetPath);\n return promises.rm(targetPath, options);\n },\n unlink(filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return promises.unlink(filePath);\n },\n writeFile(filePath, ...args) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return promises.writeFile(filePath, ...args);\n },\n async stat(path) {\n path = fs.resolve(path);\n // force throwIfNoEntry, as this function doesn't support it\n const cacheKey = getCanonicalPath(path) + suffixTrue;\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === \"failure\") {\n throw cachedStats.error;\n }\n return cachedStats.value as IFileSystemStats;\n }\n try {\n const stats = await promises.stat(path);\n statsCache.set(cacheKey, { kind: \"success\", value: stats });\n return stats;\n } catch (e) {\n statsCache.set(cacheKey, { kind: \"failure\", error: e as Error });\n throw e;\n }\n },\n symlink(target, path, type) {\n path = fs.resolve(path);\n invalidateAbsolute(path);\n return promises.symlink(target, path, type);\n },\n },\n };\n}\n"], | ||
| "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mBAAiC;AAEjC,IAAM,WAAW,CAAC,QAAgB;AAClC,IAAM,cAAc,CAAC,QAAgB,IAAI,YAAY;AAwB9C,SAAS,eAAe,IAAoC;AACjE,QAAM,mBAAmB,GAAG,gBAAgB,WAAW;AACvD,QAAM,aAAa,oBAAI,IAAqF;AAC5G,QAAM,gBAAgB,oBAAI,IAAoB;AAC9C,QAAM,sBAAsB,oBAAI,IAAoB;AACpD,QAAM,EAAE,UAAU,UAAU,IAAI;AAEhC,QAAM,aAAa,YAAY;AAC/B,QAAM,cAAc,YAAY;AAEhC,QAAM,qBAAqB,CAAC,iBAAyB;AACnD,UAAM,YAAY,iBAAiB,YAAY;AAC/C,kBAAc,OAAO,SAAS;AAC9B,wBAAoB,OAAO,SAAS;AACpC,eAAW,OAAO,YAAY,UAAU;AACxC,eAAW,OAAO,YAAY,WAAW;AAAA,EAC3C;AACA,QAAM,6BAA6B,CAAC,iBAAyB;AAC3D,UAAM,SAAS,iBAAiB,YAAY;AAC5C,eAAW,OAAO,cAAc,KAAK,GAAG;AACtC,UAAI,IAAI,WAAW,MAAM,GAAG;AAC1B,sBAAc,OAAO,GAAG;AAAA,MAC1B;AAAA,IACF;AACA,eAAW,OAAO,oBAAoB,KAAK,GAAG;AAC5C,UAAI,IAAI,WAAW,MAAM,GAAG;AAC1B,4BAAoB,OAAO,GAAG;AAAA,MAChC;AAAA,IACF;AACA,eAAW,OAAO,WAAW,KAAK,GAAG;AACnC,UAAI,IAAI,WAAW,MAAM,GAAG;AAC1B,mBAAW,OAAO,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AAEA,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I;AACF,gBAAM,QAAQ,MAAM,SAAS,KAAK,IAAI;AACtC,qBAAW,IAAI,UAAU,EAAE,MAAM,WAAW,OAAO,MAAM,CAAC;AAC1D,iBAAO;AAAA,QACT,SAAS,GAAG;AACV,qBAAW,IAAI,UAAU,EAAE,MAAM,WAAW,OAAO,EAAW,CAAC;AAC/D,gBAAM;AAAA,QACR;AAAA,MACF;AAAA,MACA,QAAQ,QAAQ,MAAM,MAAM;AAC1B,eAAO,GAAG,QAAQ,IAAI;AACtB,2BAAmB,IAAI;AACvB,eAAO,SAAS,QAAQ,QAAQ,MAAM,IAAI;AAAA,MAC5C;AAAA,IACF;AAAA,EACF;AACF;", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["../src/cached-fs.ts"], | ||
| "sourcesContent": ["import type { IFileSystem, IFileSystemStats, CallbackFnVoid } from '@file-services/types';\nimport { createFileSystem } from '@file-services/utils';\n\nconst identity = (val: string) => val;\nconst toLowerCase = (val: string) => val.toLowerCase();\n\nexport interface ICachedFileSystem extends IFileSystem {\n /**\n *\n * @param path the file path to clear from the cache\n */\n invalidate(path: string, deep?: boolean): void;\n /**\n * invalidates all files\n */\n invalidateAll(): void;\n}\n\ninterface ISuccessCacheResult<T> {\n kind: 'success';\n value: T;\n}\n\ninterface IFailureCacheResult {\n kind: 'failure';\n error: Error;\n}\n\nexport function createCachedFs(fs: IFileSystem): ICachedFileSystem {\n const getCanonicalPath = fs.caseSensitive ? identity : toLowerCase;\n const statsCache = new Map<string, ISuccessCacheResult<IFileSystemStats | undefined> | IFailureCacheResult>();\n const realpathCache = new Map<string, string>();\n const realpathNativeCache = new Map<string, string>();\n const { promises, delimiter } = fs;\n\n const suffixTrue = delimiter + 'true';\n const suffixFalse = delimiter + 'false';\n\n const invalidateAbsolute = (absolutePath: string) => {\n const cachePath = getCanonicalPath(absolutePath);\n realpathCache.delete(cachePath);\n realpathNativeCache.delete(cachePath);\n statsCache.delete(cachePath + suffixTrue);\n statsCache.delete(cachePath + suffixFalse);\n };\n const invalidateAbsoluteByPrefix = (absolutePath: string) => {\n const prefix = getCanonicalPath(absolutePath);\n for (const key of realpathCache.keys()) {\n if (key.startsWith(prefix)) {\n realpathCache.delete(key);\n }\n }\n for (const key of realpathNativeCache.keys()) {\n if (key.startsWith(prefix)) {\n realpathNativeCache.delete(key);\n }\n }\n for (const key of statsCache.keys()) {\n if (key.startsWith(prefix)) {\n statsCache.delete(key);\n }\n }\n };\n\n function realpathSync(path: string): string {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = fs.realpathSync(path);\n realpathCache.set(cacheKey, actualPath);\n return actualPath;\n }\n\n realpathSync.native = function realpathSyncNative(path: string): string {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathNativeCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = fs.realpathSync.native(path);\n realpathNativeCache.set(cacheKey, actualPath);\n return actualPath;\n };\n\n return {\n ...createFileSystem({\n ...fs,\n copyFile: function copyFile(sourcePath: string, destinationPath: string, ...args: [CallbackFnVoid]) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return fs.copyFile(sourcePath, destinationPath, ...args);\n } as IFileSystem['copyFile'],\n copyFileSync(sourcePath, destinationPath, ...args) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return fs.copyFileSync(sourcePath, destinationPath, ...args);\n },\n mkdir: function mkdir(directoryPath: string, ...args: [CallbackFnVoid]) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.mkdir(directoryPath, ...args);\n } as IFileSystem['mkdir'],\n mkdirSync(directoryPath, ...args) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.mkdirSync(directoryPath, ...args);\n },\n rename(sourcePath, destinationPath, callback) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return fs.rename(sourcePath, destinationPath, callback);\n },\n renameSync(sourcePath, destinationPath) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return fs.renameSync(sourcePath, destinationPath);\n },\n rmdir(directoryPath, callback) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.rmdir(directoryPath, callback);\n },\n rmdirSync(directoryPath) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.rmdirSync(directoryPath);\n },\n rmSync(targetPath, options) {\n targetPath = fs.resolve(targetPath);\n invalidateAbsolute(targetPath);\n return fs.rmSync(targetPath, options);\n },\n symlinkSync(target, path, type) {\n path = fs.resolve(path);\n invalidateAbsolute(path);\n return fs.symlinkSync(target, path, type);\n },\n unlink(filePath, callback) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return fs.unlink(filePath, callback);\n },\n unlinkSync(filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return fs.unlinkSync(filePath);\n },\n writeFile: function writeFile(filePath: string, ...args: [string, CallbackFnVoid]) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return fs.writeFile(filePath, ...args);\n } as IFileSystem['writeFile'],\n writeFileSync(filePath, ...args) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return fs.writeFileSync(filePath, ...args);\n },\n statSync(path, options) {\n path = fs.resolve(path);\n const throwIfNoEntry = options?.throwIfNoEntry ?? true;\n const cacheKey = getCanonicalPath(path) + (throwIfNoEntry ? suffixTrue : suffixFalse);\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === 'failure') {\n throw cachedStats.error;\n }\n return cachedStats.value as IFileSystemStats;\n }\n try {\n const stats = fs.statSync(path, options);\n statsCache.set(cacheKey, { kind: 'success', value: stats });\n return stats as IFileSystemStats;\n } catch (e) {\n statsCache.set(cacheKey, { kind: 'failure', error: e as Error });\n throw e;\n }\n },\n stat(path, callback) {\n path = fs.resolve(path);\n // force throwIfNoEntry, as callback version doesn't support it\n const cacheKey = getCanonicalPath(path) + suffixTrue;\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === 'failure') {\n (callback as (e: Error) => void)(cachedStats.error);\n } else if (cachedStats.kind === 'success') {\n callback(null, cachedStats.value as IFileSystemStats);\n }\n } else {\n fs.stat(path, (error, stats) => {\n if (error) {\n statsCache.set(cacheKey, { kind: 'failure', error });\n } else {\n statsCache.set(cacheKey, { kind: 'success', value: stats });\n }\n\n callback(error, stats);\n });\n }\n },\n realpathSync,\n realpath(path, callback) {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n callback(null, cachedActualPath);\n } else {\n fs.realpath(path, (error, actualPath) => {\n if (!error) {\n realpathCache.set(cacheKey, actualPath);\n }\n callback(error, actualPath);\n });\n }\n },\n }),\n invalidate(path, deep = false) {\n const pathToInvalidate = fs.resolve(path);\n if (deep) {\n invalidateAbsoluteByPrefix(fs.join(pathToInvalidate, fs.sep));\n }\n return invalidateAbsolute(pathToInvalidate);\n },\n invalidateAll() {\n statsCache.clear();\n },\n promises: {\n ...promises,\n async realpath(path) {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = await promises.realpath(path);\n realpathCache.set(cacheKey, actualPath);\n return actualPath;\n },\n copyFile(sourcePath, destinationPath, ...args) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return promises.copyFile(sourcePath, destinationPath, ...args);\n },\n mkdir(directoryPath, ...args) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return promises.mkdir(directoryPath, ...args);\n },\n rename(sourcePath, destinationPath) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return promises.rename(sourcePath, destinationPath);\n },\n rmdir(directoryPath) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return promises.rmdir(directoryPath);\n },\n rm(targetPath, options) {\n targetPath = fs.resolve(targetPath);\n invalidateAbsolute(targetPath);\n return promises.rm(targetPath, options);\n },\n unlink(filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return promises.unlink(filePath);\n },\n writeFile(filePath, ...args) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return promises.writeFile(filePath, ...args);\n },\n async stat(path) {\n path = fs.resolve(path);\n // force throwIfNoEntry, as this function doesn't support it\n const cacheKey = getCanonicalPath(path) + suffixTrue;\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === 'failure') {\n throw cachedStats.error;\n }\n return cachedStats.value as IFileSystemStats;\n }\n try {\n const stats = await promises.stat(path);\n statsCache.set(cacheKey, { kind: 'success', value: stats });\n return stats;\n } catch (e) {\n statsCache.set(cacheKey, { kind: 'failure', error: e as Error });\n throw e;\n }\n },\n symlink(target, path, type) {\n path = fs.resolve(path);\n invalidateAbsolute(path);\n return promises.symlink(target, path, type);\n },\n },\n };\n}\n"], | ||
| "sourcesContent": ["import type { IFileSystem, IFileSystemStats, CallbackFnVoid } from \"@file-services/types\";\nimport { createFileSystem } from \"@file-services/utils\";\n\nconst identity = (val: string) => val;\nconst toLowerCase = (val: string) => val.toLowerCase();\n\nexport interface ICachedFileSystem extends IFileSystem {\n /**\n *\n * @param path the file path to clear from the cache\n */\n invalidate(path: string, deep?: boolean): void;\n /**\n * invalidates all files\n */\n invalidateAll(): void;\n}\n\ninterface ISuccessCacheResult<T> {\n kind: \"success\";\n value: T;\n}\n\ninterface IFailureCacheResult {\n kind: \"failure\";\n error: Error;\n}\n\nexport function createCachedFs(fs: IFileSystem): ICachedFileSystem {\n const getCanonicalPath = fs.caseSensitive ? identity : toLowerCase;\n const statsCache = new Map<string, ISuccessCacheResult<IFileSystemStats | undefined> | IFailureCacheResult>();\n const realpathCache = new Map<string, string>();\n const realpathNativeCache = new Map<string, string>();\n const { promises, delimiter } = fs;\n\n const suffixTrue = delimiter + \"true\";\n const suffixFalse = delimiter + \"false\";\n\n const invalidateAbsolute = (absolutePath: string) => {\n const cachePath = getCanonicalPath(absolutePath);\n realpathCache.delete(cachePath);\n realpathNativeCache.delete(cachePath);\n statsCache.delete(cachePath + suffixTrue);\n statsCache.delete(cachePath + suffixFalse);\n };\n const invalidateAbsoluteByPrefix = (absolutePath: string) => {\n const prefix = getCanonicalPath(absolutePath);\n for (const key of realpathCache.keys()) {\n if (key.startsWith(prefix)) {\n realpathCache.delete(key);\n }\n }\n for (const key of realpathNativeCache.keys()) {\n if (key.startsWith(prefix)) {\n realpathNativeCache.delete(key);\n }\n }\n for (const key of statsCache.keys()) {\n if (key.startsWith(prefix)) {\n statsCache.delete(key);\n }\n }\n };\n\n function realpathSync(path: string): string {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = fs.realpathSync(path);\n realpathCache.set(cacheKey, actualPath);\n return actualPath;\n }\n\n realpathSync.native = function realpathSyncNative(path: string): string {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathNativeCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = fs.realpathSync.native(path);\n realpathNativeCache.set(cacheKey, actualPath);\n return actualPath;\n };\n\n return {\n ...createFileSystem({\n ...fs,\n copyFile: function copyFile(sourcePath: string, destinationPath: string, ...args: [CallbackFnVoid]) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return fs.copyFile(sourcePath, destinationPath, ...args);\n } as IFileSystem[\"copyFile\"],\n copyFileSync(sourcePath, destinationPath, ...args) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return fs.copyFileSync(sourcePath, destinationPath, ...args);\n },\n mkdir: function mkdir(directoryPath: string, ...args: [CallbackFnVoid]) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.mkdir(directoryPath, ...args);\n } as IFileSystem[\"mkdir\"],\n mkdirSync(directoryPath, ...args) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.mkdirSync(directoryPath, ...args);\n },\n rename(sourcePath, destinationPath, callback) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return fs.rename(sourcePath, destinationPath, callback);\n },\n renameSync(sourcePath, destinationPath) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return fs.renameSync(sourcePath, destinationPath);\n },\n rmdir(directoryPath, callback) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.rmdir(directoryPath, callback);\n },\n rmdirSync(directoryPath) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return fs.rmdirSync(directoryPath);\n },\n rmSync(targetPath, options) {\n targetPath = fs.resolve(targetPath);\n invalidateAbsolute(targetPath);\n return fs.rmSync(targetPath, options);\n },\n symlinkSync(target, path, type) {\n path = fs.resolve(path);\n invalidateAbsolute(path);\n return fs.symlinkSync(target, path, type);\n },\n unlink(filePath, callback) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return fs.unlink(filePath, callback);\n },\n unlinkSync(filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return fs.unlinkSync(filePath);\n },\n writeFile: function writeFile(filePath: string, ...args: [string, CallbackFnVoid]) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return fs.writeFile(filePath, ...args);\n } as IFileSystem[\"writeFile\"],\n writeFileSync(filePath, ...args) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return fs.writeFileSync(filePath, ...args);\n },\n statSync(path, options) {\n path = fs.resolve(path);\n const throwIfNoEntry = options?.throwIfNoEntry ?? true;\n const cacheKey = getCanonicalPath(path) + (throwIfNoEntry ? suffixTrue : suffixFalse);\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === \"failure\") {\n throw cachedStats.error;\n }\n return cachedStats.value as IFileSystemStats;\n }\n try {\n const stats = fs.statSync(path, options);\n statsCache.set(cacheKey, { kind: \"success\", value: stats });\n return stats as IFileSystemStats;\n } catch (e) {\n statsCache.set(cacheKey, { kind: \"failure\", error: e as Error });\n throw e;\n }\n },\n stat(path, callback) {\n path = fs.resolve(path);\n // force throwIfNoEntry, as callback version doesn't support it\n const cacheKey = getCanonicalPath(path) + suffixTrue;\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === \"failure\") {\n (callback as (e: Error) => void)(cachedStats.error);\n } else if (cachedStats.kind === \"success\") {\n callback(null, cachedStats.value as IFileSystemStats);\n }\n } else {\n fs.stat(path, (error, stats) => {\n if (error) {\n statsCache.set(cacheKey, { kind: \"failure\", error });\n } else {\n statsCache.set(cacheKey, { kind: \"success\", value: stats });\n }\n\n callback(error, stats);\n });\n }\n },\n realpathSync,\n realpath(path, callback) {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n callback(null, cachedActualPath);\n } else {\n fs.realpath(path, (error, actualPath) => {\n if (!error) {\n realpathCache.set(cacheKey, actualPath);\n }\n callback(error, actualPath);\n });\n }\n },\n }),\n invalidate(path, deep = false) {\n const pathToInvalidate = fs.resolve(path);\n if (deep) {\n invalidateAbsoluteByPrefix(fs.join(pathToInvalidate, fs.sep));\n }\n return invalidateAbsolute(pathToInvalidate);\n },\n invalidateAll() {\n statsCache.clear();\n },\n promises: {\n ...promises,\n async realpath(path) {\n path = fs.resolve(path);\n const cacheKey = getCanonicalPath(path);\n const cachedActualPath = realpathCache.get(cacheKey);\n if (cachedActualPath !== undefined) {\n return cachedActualPath;\n }\n const actualPath = await promises.realpath(path);\n realpathCache.set(cacheKey, actualPath);\n return actualPath;\n },\n copyFile(sourcePath, destinationPath, ...args) {\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(destinationPath);\n return promises.copyFile(sourcePath, destinationPath, ...args);\n },\n mkdir(directoryPath, ...args) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return promises.mkdir(directoryPath, ...args);\n },\n rename(sourcePath, destinationPath) {\n sourcePath = fs.resolve(sourcePath);\n destinationPath = fs.resolve(destinationPath);\n invalidateAbsolute(sourcePath);\n invalidateAbsolute(destinationPath);\n return promises.rename(sourcePath, destinationPath);\n },\n rmdir(directoryPath) {\n directoryPath = fs.resolve(directoryPath);\n invalidateAbsolute(directoryPath);\n return promises.rmdir(directoryPath);\n },\n rm(targetPath, options) {\n targetPath = fs.resolve(targetPath);\n invalidateAbsolute(targetPath);\n return promises.rm(targetPath, options);\n },\n unlink(filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n return promises.unlink(filePath);\n },\n writeFile(filePath, ...args) {\n if (filePath) {\n filePath = fs.resolve(filePath);\n invalidateAbsolute(filePath);\n }\n return promises.writeFile(filePath, ...args);\n },\n async stat(path) {\n path = fs.resolve(path);\n // force throwIfNoEntry, as this function doesn't support it\n const cacheKey = getCanonicalPath(path) + suffixTrue;\n const cachedStats = statsCache.get(cacheKey);\n if (cachedStats) {\n if (cachedStats.kind === \"failure\") {\n throw cachedStats.error;\n }\n return cachedStats.value as IFileSystemStats;\n }\n try {\n const stats = await promises.stat(path);\n statsCache.set(cacheKey, { kind: \"success\", value: stats });\n return stats;\n } catch (e) {\n statsCache.set(cacheKey, { kind: \"failure\", error: e as Error });\n throw e;\n }\n },\n symlink(target, path, type) {\n path = fs.resolve(path);\n invalidateAbsolute(path);\n return promises.symlink(target, path, type);\n },\n },\n };\n}\n"], | ||
| "mappings": ";AACA,SAAS,wBAAwB;AAEjC,IAAM,WAAW,CAAC,QAAgB;AAClC,IAAM,cAAc,CAAC,QAAgB,IAAI,YAAY;AAwB9C,SAAS,eAAe,IAAoC;AACjE,QAAM,mBAAmB,GAAG,gBAAgB,WAAW;AACvD,QAAM,aAAa,oBAAI,IAAqF;AAC5G,QAAM,gBAAgB,oBAAI,IAAoB;AAC9C,QAAM,sBAAsB,oBAAI,IAAoB;AACpD,QAAM,EAAE,UAAU,UAAU,IAAI;AAEhC,QAAM,aAAa,YAAY;AAC/B,QAAM,cAAc,YAAY;AAEhC,QAAM,qBAAqB,CAAC,iBAAyB;AACnD,UAAM,YAAY,iBAAiB,YAAY;AAC/C,kBAAc,OAAO,SAAS;AAC9B,wBAAoB,OAAO,SAAS;AACpC,eAAW,OAAO,YAAY,UAAU;AACxC,eAAW,OAAO,YAAY,WAAW;AAAA,EAC3C;AACA,QAAM,6BAA6B,CAAC,iBAAyB;AAC3D,UAAM,SAAS,iBAAiB,YAAY;AAC5C,eAAW,OAAO,cAAc,KAAK,GAAG;AACtC,UAAI,IAAI,WAAW,MAAM,GAAG;AAC1B,sBAAc,OAAO,GAAG;AAAA,MAC1B;AAAA,IACF;AACA,eAAW,OAAO,oBAAoB,KAAK,GAAG;AAC5C,UAAI,IAAI,WAAW,MAAM,GAAG;AAC1B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AAW,iBAAiB,IAAI,IAAI;AAC1C,cAAM,cAAc,WAAW,IAAI,QAAQ;AAC3C,YAAI,aAAa;AACf,cAAI,YAAY,SAAS,WAAW;AAClC,kBAAM,YAAY;AAAA,UACpB;AACA,iBAAO,YAAY;AAAA,QACrB;AACA,YAAI;AACF,gBAAM,QAAQ,MAAM,SAAS,KAAK,IAAI;AACtC,qBAAW,IAAI,UAAU,EAAE,MAAM,WAAW,OAAO,MAAM,CAAC;AAC1D,iBAAO;AAAA,QACT,SAAS,GAAG;AACV,qBAAW,IAAI,UAAU,EAAE,MAAM,WAAW,OAAO,EAAW,CAAC;AAC/D,gBAAM;AAAA,QACR;AAAA,MACF;AAAA,MACA,QAAQ,QAAQ,MAAM,MAAM;AAC1B,eAAO,GAAG,QAAQ,IAAI;AACtB,2BAAmB,IAAI;AACvB,eAAO,SAAS,QAAQ,QAAQ,MAAM,IAAI;AAAA,MAC5C;AAAA,IACF;AAAA,EACF;AACF;", | ||
| "names": [] | ||
| } |
+1
-1
@@ -1,2 +0,2 @@ | ||
| export * from './cached-fs'; | ||
| export * from "./cached-fs"; | ||
| //# sourceMappingURL=index.d.ts.map |
+3
-3
| { | ||
| "name": "@file-services/cached", | ||
| "description": "A file system wrapper that adds cache to any `IFileSystem` implementation.", | ||
| "version": "8.3.3", | ||
| "version": "9.0.0", | ||
| "main": "./dist/fs-cached.cjs", | ||
@@ -21,4 +21,4 @@ "types": "./dist/index.d.ts", | ||
| "dependencies": { | ||
| "@file-services/types": "^8.3.3", | ||
| "@file-services/utils": "^8.3.3" | ||
| "@file-services/types": "^9.0.0", | ||
| "@file-services/utils": "^9.0.0" | ||
| }, | ||
@@ -25,0 +25,0 @@ "files": [ |
+6
-6
@@ -19,15 +19,15 @@ # @file-services/cached | ||
| ```ts | ||
| import { nodeFs } from '@file-services/node'; | ||
| import { createCachedFs } from '@file-services/cached'; | ||
| import { nodeFs } from "@file-services/node"; | ||
| import { createCachedFs } from "@file-services/cached"; | ||
| const cachedFs = createCachedFs(nodeFs); | ||
| cachedFs.writeFileSync('/file.js', 'CONTENT'); | ||
| cachedFs.writeFileSync("/file.js", "CONTENT"); | ||
| // calls fs | ||
| cachedFs.statSync('/file.js'); | ||
| cachedFs.statSync("/file.js"); | ||
| // cached | ||
| cachedFs.statSync('/file.js'); | ||
| cachedFs.statSync("/file.js"); | ||
| // clears the cache | ||
| cachedFs.invalidate('/file.js'); | ||
| cachedFs.invalidate("/file.js"); | ||
| ``` | ||
@@ -34,0 +34,0 @@ |
+19
-19
@@ -1,3 +0,3 @@ | ||
| import type { IFileSystem, IFileSystemStats, CallbackFnVoid } from '@file-services/types'; | ||
| import { createFileSystem } from '@file-services/utils'; | ||
| import type { IFileSystem, IFileSystemStats, CallbackFnVoid } from "@file-services/types"; | ||
| import { createFileSystem } from "@file-services/utils"; | ||
@@ -20,3 +20,3 @@ const identity = (val: string) => val; | ||
| interface ISuccessCacheResult<T> { | ||
| kind: 'success'; | ||
| kind: "success"; | ||
| value: T; | ||
@@ -26,3 +26,3 @@ } | ||
| interface IFailureCacheResult { | ||
| kind: 'failure'; | ||
| kind: "failure"; | ||
| error: Error; | ||
@@ -38,4 +38,4 @@ } | ||
| const suffixTrue = delimiter + 'true'; | ||
| const suffixFalse = delimiter + 'false'; | ||
| const suffixTrue = delimiter + "true"; | ||
| const suffixFalse = delimiter + "false"; | ||
@@ -99,3 +99,3 @@ const invalidateAbsolute = (absolutePath: string) => { | ||
| return fs.copyFile(sourcePath, destinationPath, ...args); | ||
| } as IFileSystem['copyFile'], | ||
| } as IFileSystem["copyFile"], | ||
| copyFileSync(sourcePath, destinationPath, ...args) { | ||
@@ -110,3 +110,3 @@ destinationPath = fs.resolve(destinationPath); | ||
| return fs.mkdir(directoryPath, ...args); | ||
| } as IFileSystem['mkdir'], | ||
| } as IFileSystem["mkdir"], | ||
| mkdirSync(directoryPath, ...args) { | ||
@@ -167,3 +167,3 @@ directoryPath = fs.resolve(directoryPath); | ||
| return fs.writeFile(filePath, ...args); | ||
| } as IFileSystem['writeFile'], | ||
| } as IFileSystem["writeFile"], | ||
| writeFileSync(filePath, ...args) { | ||
@@ -182,3 +182,3 @@ if (filePath) { | ||
| if (cachedStats) { | ||
| if (cachedStats.kind === 'failure') { | ||
| if (cachedStats.kind === "failure") { | ||
| throw cachedStats.error; | ||
@@ -190,6 +190,6 @@ } | ||
| const stats = fs.statSync(path, options); | ||
| statsCache.set(cacheKey, { kind: 'success', value: stats }); | ||
| statsCache.set(cacheKey, { kind: "success", value: stats }); | ||
| return stats as IFileSystemStats; | ||
| } catch (e) { | ||
| statsCache.set(cacheKey, { kind: 'failure', error: e as Error }); | ||
| statsCache.set(cacheKey, { kind: "failure", error: e as Error }); | ||
| throw e; | ||
@@ -204,5 +204,5 @@ } | ||
| if (cachedStats) { | ||
| if (cachedStats.kind === 'failure') { | ||
| if (cachedStats.kind === "failure") { | ||
| (callback as (e: Error) => void)(cachedStats.error); | ||
| } else if (cachedStats.kind === 'success') { | ||
| } else if (cachedStats.kind === "success") { | ||
| callback(null, cachedStats.value as IFileSystemStats); | ||
@@ -213,5 +213,5 @@ } | ||
| if (error) { | ||
| statsCache.set(cacheKey, { kind: 'failure', error }); | ||
| statsCache.set(cacheKey, { kind: "failure", error }); | ||
| } else { | ||
| statsCache.set(cacheKey, { kind: 'success', value: stats }); | ||
| statsCache.set(cacheKey, { kind: "success", value: stats }); | ||
| } | ||
@@ -308,3 +308,3 @@ | ||
| if (cachedStats) { | ||
| if (cachedStats.kind === 'failure') { | ||
| if (cachedStats.kind === "failure") { | ||
| throw cachedStats.error; | ||
@@ -316,6 +316,6 @@ } | ||
| const stats = await promises.stat(path); | ||
| statsCache.set(cacheKey, { kind: 'success', value: stats }); | ||
| statsCache.set(cacheKey, { kind: "success", value: stats }); | ||
| return stats; | ||
| } catch (e) { | ||
| statsCache.set(cacheKey, { kind: 'failure', error: e as Error }); | ||
| statsCache.set(cacheKey, { kind: "failure", error: e as Error }); | ||
| throw e; | ||
@@ -322,0 +322,0 @@ } |
+1
-1
@@ -1,1 +0,1 @@ | ||
| export * from './cached-fs'; | ||
| export * from "./cached-fs"; |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
73046
0.11%+ Added
+ Added
- Removed
- Removed
Updated
Updated