@file-services/utils
Advanced tools
Comparing version 5.4.0 to 5.7.0
@@ -5,2 +5,3 @@ "use strict"; | ||
const returnsTrue = () => true; | ||
const statsNoThrowOptions = { throwIfNoEntry: false }; | ||
function createFileSystem(baseFs) { | ||
@@ -27,13 +28,4 @@ return { | ||
function fileExistsSync(filePath, statFn = statSync) { | ||
const { stackTraceLimit } = Error; | ||
try { | ||
Error.stackTraceLimit = 0; | ||
return statFn(filePath).isFile(); | ||
} | ||
catch { | ||
return false; | ||
} | ||
finally { | ||
Error.stackTraceLimit = stackTraceLimit; | ||
} | ||
var _a; | ||
return !!((_a = statFn(filePath, statsNoThrowOptions)) === null || _a === void 0 ? void 0 : _a.isFile()); | ||
} | ||
@@ -44,13 +36,4 @@ function readJsonFileSync(filePath, options) { | ||
function directoryExistsSync(directoryPath, statFn = statSync) { | ||
const { stackTraceLimit } = Error; | ||
try { | ||
Error.stackTraceLimit = 0; | ||
return statFn(directoryPath).isDirectory(); | ||
} | ||
catch { | ||
return false; | ||
} | ||
finally { | ||
Error.stackTraceLimit = stackTraceLimit; | ||
} | ||
var _a; | ||
return !!((_a = statFn(directoryPath, statsNoThrowOptions)) === null || _a === void 0 ? void 0 : _a.isDirectory()); | ||
} | ||
@@ -132,15 +115,13 @@ function ensureDirectorySync(directoryPath) { | ||
const nodePath = join(rootDirectory, nodeName); | ||
try { | ||
const nodeStats = statSync(nodePath); | ||
const nodeDesc = { name: nodeName, path: nodePath, stats: nodeStats }; | ||
if (nodeStats.isFile() && filterFile(nodeDesc)) { | ||
filePaths.push(nodePath); | ||
} | ||
else if (nodeStats.isDirectory() && filterDirectory(nodeDesc)) { | ||
findFilesSync(nodePath, options, filePaths); | ||
} | ||
const nodeStats = statSync(nodePath, statsNoThrowOptions); | ||
if (!nodeStats) { | ||
continue; | ||
} | ||
catch (e) { | ||
/**/ | ||
const nodeDesc = { name: nodeName, path: nodePath, stats: nodeStats }; | ||
if (nodeStats.isFile() && filterFile(nodeDesc)) { | ||
filePaths.push(nodePath); | ||
} | ||
else if (nodeStats.isDirectory() && filterDirectory(nodeDesc)) { | ||
findFilesSync(nodePath, options, filePaths); | ||
} | ||
} | ||
@@ -147,0 +128,0 @@ return filePaths; |
{ | ||
"name": "@file-services/utils", | ||
"description": "Common file system utility functions.", | ||
"version": "5.4.0", | ||
"version": "5.7.0", | ||
"main": "dist/index.js", | ||
"dependencies": { | ||
"@file-services/types": "^5.4.0" | ||
"@file-services/types": "^5.7.0" | ||
}, | ||
@@ -9,0 +9,0 @@ "files": [ |
@@ -17,2 +17,3 @@ import type { | ||
const returnsTrue = () => true; | ||
const statsNoThrowOptions = { throwIfNoEntry: false } as const; | ||
@@ -54,11 +55,3 @@ export function createFileSystem(baseFs: IBaseFileSystem): IFileSystem { | ||
function fileExistsSync(filePath: string, statFn = statSync): boolean { | ||
const { stackTraceLimit } = Error; | ||
try { | ||
Error.stackTraceLimit = 0; | ||
return statFn(filePath).isFile(); | ||
} catch { | ||
return false; | ||
} finally { | ||
Error.stackTraceLimit = stackTraceLimit; | ||
} | ||
return !!statFn(filePath, statsNoThrowOptions)?.isFile(); | ||
} | ||
@@ -71,11 +64,3 @@ | ||
function directoryExistsSync(directoryPath: string, statFn = statSync): boolean { | ||
const { stackTraceLimit } = Error; | ||
try { | ||
Error.stackTraceLimit = 0; | ||
return statFn(directoryPath).isDirectory(); | ||
} catch { | ||
return false; | ||
} finally { | ||
Error.stackTraceLimit = stackTraceLimit; | ||
} | ||
return !!statFn(directoryPath, statsNoThrowOptions)?.isDirectory(); | ||
} | ||
@@ -155,13 +140,12 @@ | ||
const nodePath = join(rootDirectory, nodeName); | ||
try { | ||
const nodeStats = statSync(nodePath); | ||
const nodeDesc: IFileSystemDescriptor = { name: nodeName, path: nodePath, stats: nodeStats }; | ||
if (nodeStats.isFile() && filterFile(nodeDesc)) { | ||
filePaths.push(nodePath); | ||
} else if (nodeStats.isDirectory() && filterDirectory(nodeDesc)) { | ||
findFilesSync(nodePath, options, filePaths); | ||
} | ||
} catch (e) { | ||
/**/ | ||
const nodeStats = statSync(nodePath, statsNoThrowOptions); | ||
if (!nodeStats) { | ||
continue; | ||
} | ||
const nodeDesc: IFileSystemDescriptor = { name: nodeName, path: nodePath, stats: nodeStats }; | ||
if (nodeStats.isFile() && filterFile(nodeDesc)) { | ||
filePaths.push(nodePath); | ||
} else if (nodeStats.isDirectory() && filterDirectory(nodeDesc)) { | ||
findFilesSync(nodePath, options, filePaths); | ||
} | ||
} | ||
@@ -168,0 +152,0 @@ |
@@ -68,4 +68,4 @@ import type { | ||
rmdir: callbackify(syncFs.rmdirSync), | ||
stat: callbackify(syncFs.statSync), | ||
lstat: callbackify(syncFs.lstatSync), | ||
stat: callbackify(syncFs.statSync) as unknown as IBaseFileSystemAsync['stat'], | ||
lstat: callbackify(syncFs.lstatSync) as unknown as IBaseFileSystemAsync['lstat'], | ||
realpath: callbackify(syncFs.realpathSync), | ||
@@ -72,0 +72,0 @@ rename: callbackify(syncFs.renameSync), |
Sorry, the diff of this file is not supported yet
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
59050
1077
Updated@file-services/types@^5.7.0