@file-services/utils
Advanced tools
Comparing version 0.4.3 to 0.4.4
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createSyncFileSystem(baseFs) { | ||
const { statSync, path, mkdirSync, writeFileSync } = baseFs; | ||
const { statSync, path, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync } = baseFs; | ||
function fileExistsSync(filePath, statFn = statSync) { | ||
@@ -50,10 +50,24 @@ try { | ||
} | ||
function removeSync(entryPath) { | ||
const stats = lstatSync(entryPath); | ||
if (stats.isDirectory()) { | ||
const directoryItems = readdirSync(entryPath); | ||
for (const entryName of directoryItems) { | ||
removeSync(path.join(entryPath, entryName)); | ||
} | ||
rmdirSync(entryPath); | ||
} | ||
else if (stats.isFile() || stats.isSymbolicLink()) { | ||
unlinkSync(entryPath); | ||
} | ||
} | ||
return Object.assign({}, baseFs, { fileExistsSync, | ||
directoryExistsSync, | ||
ensureDirectorySync, | ||
populateDirectorySync }); | ||
populateDirectorySync, | ||
removeSync }); | ||
} | ||
exports.createSyncFileSystem = createSyncFileSystem; | ||
function createAsyncFileSystem(baseFs) { | ||
const { stat, path, mkdir, writeFile } = baseFs; | ||
const { stat, path, mkdir, writeFile, lstat, rmdir, unlink, readdir } = baseFs; | ||
async function fileExists(filePath, statFn = stat) { | ||
@@ -104,8 +118,25 @@ try { | ||
} | ||
async function remove(entryPath) { | ||
const stats = await lstat(entryPath); | ||
if (stats.isDirectory()) { | ||
const directoryItems = await readdir(entryPath); | ||
for (const entryName of directoryItems) { | ||
await remove(path.join(entryPath, entryName)); | ||
} | ||
await rmdir(entryPath); | ||
} | ||
else if (stats.isFile() || stats.isSymbolicLink()) { | ||
await unlink(entryPath); | ||
} | ||
else { | ||
throw new Error('incorect node type, cannot delete'); | ||
} | ||
} | ||
return Object.assign({}, baseFs, { fileExists, | ||
directoryExists, | ||
ensureDirectory, | ||
populateDirectory }); | ||
populateDirectory, | ||
remove }); | ||
} | ||
exports.createAsyncFileSystem = createAsyncFileSystem; | ||
//# sourceMappingURL=create-extended-api.js.map |
export function createSyncFileSystem(baseFs) { | ||
const { statSync, path, mkdirSync, writeFileSync } = baseFs; | ||
const { statSync, path, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync } = baseFs; | ||
function fileExistsSync(filePath, statFn = statSync) { | ||
@@ -48,9 +48,23 @@ try { | ||
} | ||
function removeSync(entryPath) { | ||
const stats = lstatSync(entryPath); | ||
if (stats.isDirectory()) { | ||
const directoryItems = readdirSync(entryPath); | ||
for (const entryName of directoryItems) { | ||
removeSync(path.join(entryPath, entryName)); | ||
} | ||
rmdirSync(entryPath); | ||
} | ||
else if (stats.isFile() || stats.isSymbolicLink()) { | ||
unlinkSync(entryPath); | ||
} | ||
} | ||
return Object.assign({}, baseFs, { fileExistsSync, | ||
directoryExistsSync, | ||
ensureDirectorySync, | ||
populateDirectorySync }); | ||
populateDirectorySync, | ||
removeSync }); | ||
} | ||
export function createAsyncFileSystem(baseFs) { | ||
const { stat, path, mkdir, writeFile } = baseFs; | ||
const { stat, path, mkdir, writeFile, lstat, rmdir, unlink, readdir } = baseFs; | ||
async function fileExists(filePath, statFn = stat) { | ||
@@ -101,7 +115,24 @@ try { | ||
} | ||
async function remove(entryPath) { | ||
const stats = await lstat(entryPath); | ||
if (stats.isDirectory()) { | ||
const directoryItems = await readdir(entryPath); | ||
for (const entryName of directoryItems) { | ||
await remove(path.join(entryPath, entryName)); | ||
} | ||
await rmdir(entryPath); | ||
} | ||
else if (stats.isFile() || stats.isSymbolicLink()) { | ||
await unlink(entryPath); | ||
} | ||
else { | ||
throw new Error('incorect node type, cannot delete'); | ||
} | ||
} | ||
return Object.assign({}, baseFs, { fileExists, | ||
directoryExists, | ||
ensureDirectory, | ||
populateDirectory }); | ||
populateDirectory, | ||
remove }); | ||
} | ||
//# sourceMappingURL=create-extended-api.js.map |
{ | ||
"name": "@file-services/utils", | ||
"description": "Common file system utility functions.", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"main": "cjs/index.js", | ||
@@ -17,6 +17,6 @@ "module": "esm/index.js", | ||
"dependencies": { | ||
"@file-services/types": "^0.4.2" | ||
"@file-services/types": "^0.4.4" | ||
}, | ||
"devDependencies": { | ||
"@file-services/test-kit": "^0.4.3" | ||
"@file-services/test-kit": "^0.4.4" | ||
}, | ||
@@ -35,3 +35,3 @@ "files": [ | ||
"sideEffects": false, | ||
"gitHead": "86cdbd09488503134ccb683d2ded0bfcb04b3ca2" | ||
"gitHead": "2581162c8cc61d5a9d4b9a8e2f488e4f86c2d22b" | ||
} |
@@ -10,3 +10,3 @@ import { | ||
export function createSyncFileSystem(baseFs: IBaseFileSystemSync): IFileSystemSync { | ||
const { statSync, path, mkdirSync, writeFileSync } = baseFs | ||
const { statSync, path, mkdirSync, writeFileSync, unlinkSync, rmdirSync, lstatSync, readdirSync } = baseFs | ||
@@ -58,2 +58,15 @@ function fileExistsSync(filePath: string, statFn = statSync): boolean { | ||
function removeSync(entryPath: string) { | ||
const stats = lstatSync(entryPath) | ||
if (stats.isDirectory()) { | ||
const directoryItems = readdirSync(entryPath) | ||
for (const entryName of directoryItems) { | ||
removeSync(path.join(entryPath, entryName)) | ||
} | ||
rmdirSync(entryPath) | ||
} else if (stats.isFile() || stats.isSymbolicLink()) { | ||
unlinkSync(entryPath) | ||
} | ||
} | ||
return { | ||
@@ -64,3 +77,4 @@ ...baseFs, | ||
ensureDirectorySync, | ||
populateDirectorySync | ||
populateDirectorySync, | ||
removeSync | ||
} | ||
@@ -70,3 +84,3 @@ } | ||
export function createAsyncFileSystem(baseFs: IBaseFileSystemAsync): IFileSystemAsync { | ||
const { stat, path, mkdir, writeFile } = baseFs | ||
const { stat, path, mkdir, writeFile, lstat, rmdir, unlink, readdir } = baseFs | ||
@@ -118,2 +132,18 @@ async function fileExists(filePath: string, statFn = stat): Promise<boolean> { | ||
async function remove(entryPath: string) { | ||
const stats = await lstat(entryPath) | ||
if (stats.isDirectory()) { | ||
const directoryItems = await readdir(entryPath) | ||
for (const entryName of directoryItems) { | ||
await remove(path.join(entryPath, entryName)) | ||
} | ||
await rmdir(entryPath) | ||
} else if (stats.isFile() || stats.isSymbolicLink()) { | ||
await unlink(entryPath) | ||
} else { | ||
throw new Error('incorect node type, cannot delete') | ||
} | ||
} | ||
return { | ||
@@ -124,4 +154,5 @@ ...baseFs, | ||
ensureDirectory, | ||
populateDirectory | ||
populateDirectory, | ||
remove | ||
} | ||
} |
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
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
71201
1171
Updated@file-services/types@^0.4.4