@file-services/utils
Advanced tools
Comparing version 8.3.3 to 9.0.0
@@ -1,2 +0,2 @@ | ||
import type { IBaseFileSystemAsync, IBaseFileSystemSync, IFileSystemAsync, IFileSystemSync, IBaseFileSystem, IFileSystem, IFileSystemExtendedSyncActions, IFileSystemExtendedPromiseActions } from '@file-services/types'; | ||
import type { IBaseFileSystemAsync, IBaseFileSystemSync, IFileSystemAsync, IFileSystemSync, IBaseFileSystem, IFileSystem, IFileSystemExtendedSyncActions, IFileSystemExtendedPromiseActions } from "@file-services/types"; | ||
export declare function createFileSystem(baseFs: IBaseFileSystem): IFileSystem; | ||
@@ -3,0 +3,0 @@ export declare function createSyncFileSystem(baseFs: IBaseFileSystemSync): IFileSystemSync; |
@@ -1,4 +0,4 @@ | ||
export * from './create-extended-api'; | ||
export * from './set-multi-map'; | ||
export * from './sync-to-async-fs'; | ||
export * from "./create-extended-api"; | ||
export * from "./set-multi-map"; | ||
export * from "./sync-to-async-fs"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import type { IBaseFileSystemSync, IBaseFileSystemAsync } from '@file-services/types'; | ||
import type { IBaseFileSystemSync, IBaseFileSystemAsync } from "@file-services/types"; | ||
export declare function syncToAsyncFs(syncFs: IBaseFileSystemSync): IBaseFileSystemAsync; | ||
//# sourceMappingURL=sync-to-async-fs.d.ts.map |
{ | ||
"name": "@file-services/utils", | ||
"description": "Common file system utility functions.", | ||
"version": "8.3.3", | ||
"version": "9.0.0", | ||
"main": "./dist/fs-utils.cjs", | ||
@@ -16,3 +16,3 @@ "types": "./dist/index.d.ts", | ||
"dependencies": { | ||
"@file-services/types": "^8.3.3" | ||
"@file-services/types": "^9.0.0" | ||
}, | ||
@@ -19,0 +19,0 @@ "files": [ |
@@ -14,3 +14,3 @@ import type { | ||
IFileSystemExtendedPromiseActions, | ||
} from '@file-services/types'; | ||
} from "@file-services/types"; | ||
@@ -51,3 +51,3 @@ const returnsTrue = () => true; | ||
function readJsonFileSync(filePath: string, options?: BufferEncoding | { encoding: BufferEncoding } | null): unknown { | ||
return JSON.parse(readFileSync(filePath, options || 'utf8')) as unknown; | ||
return JSON.parse(readFileSync(filePath, options || "utf8")) as unknown; | ||
} | ||
@@ -68,5 +68,5 @@ | ||
const code = (e as { code?: string })?.code; | ||
if (code === 'EISDIR') { | ||
if (code === "EISDIR") { | ||
return; | ||
} else if (code === 'EEXIST') { | ||
} else if (code === "EEXIST") { | ||
if (directoryExistsSync(directoryPath)) { | ||
@@ -77,3 +77,3 @@ return; | ||
} | ||
} else if (code === 'ENOTDIR' || !code) { | ||
} else if (code === "ENOTDIR" || !code) { | ||
throw e; | ||
@@ -92,3 +92,3 @@ } | ||
const code = (e as { code?: string })?.code; | ||
const isDirectoryExistsError = code === 'EISDIR' || (code === 'EEXIST' && directoryExistsSync(directoryPath)); | ||
const isDirectoryExistsError = code === "EISDIR" || (code === "EEXIST" && directoryExistsSync(directoryPath)); | ||
if (!isDirectoryExistsError) { | ||
@@ -101,3 +101,3 @@ throw e; | ||
function populateDirectorySync(directoryPath: string, contents: IDirectoryContents): string[] { | ||
function populateDirectorySync(directoryPath: string, contents: IDirectoryContents<string | Uint8Array>): string[] { | ||
const filePaths: string[] = []; | ||
@@ -107,3 +107,3 @@ ensureDirectorySync(directoryPath); | ||
const nodePath = join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
if (typeof nodeValue === "string" || nodeValue instanceof Uint8Array) { | ||
ensureDirectorySync(dirname(nodePath)); | ||
@@ -207,3 +207,3 @@ writeFileSync(nodePath, nodeValue); | ||
export function createExtendedFileSystemPromiseActions( | ||
baseFs: IBaseFileSystemAsync | ||
baseFs: IBaseFileSystemAsync, | ||
): IFileSystemExtendedPromiseActions { | ||
@@ -235,5 +235,5 @@ const { | ||
filePath: string, | ||
options?: BufferEncoding | { encoding: BufferEncoding } | null | ||
options?: BufferEncoding | { encoding: BufferEncoding } | null, | ||
): Promise<unknown> { | ||
return JSON.parse(await readFile(filePath, options || 'utf8')) as unknown; | ||
return JSON.parse(await readFile(filePath, options || "utf8")) as unknown; | ||
} | ||
@@ -246,5 +246,5 @@ | ||
const code = (e as { code?: string })?.code; | ||
if (code === 'EISDIR') { | ||
if (code === "EISDIR") { | ||
return; | ||
} else if (code === 'EEXIST') { | ||
} else if (code === "EEXIST") { | ||
if (await directoryExists(directoryPath)) { | ||
@@ -255,3 +255,3 @@ return; | ||
} | ||
} else if (code === 'ENOTDIR' || !code) { | ||
} else if (code === "ENOTDIR" || !code) { | ||
throw e; | ||
@@ -271,3 +271,3 @@ } | ||
const isDirectoryExistsError = | ||
code === 'EISDIR' || (code === 'EEXIST' && (await directoryExists(directoryPath))); | ||
code === "EISDIR" || (code === "EEXIST" && (await directoryExists(directoryPath))); | ||
if (!isDirectoryExistsError) { | ||
@@ -280,3 +280,6 @@ throw e; | ||
async function populateDirectory(directoryPath: string, contents: IDirectoryContents): Promise<string[]> { | ||
async function populateDirectory( | ||
directoryPath: string, | ||
contents: IDirectoryContents<string | Uint8Array>, | ||
): Promise<string[]> { | ||
const filePaths: string[] = []; | ||
@@ -286,3 +289,3 @@ await ensureDirectory(directoryPath); | ||
const nodePath = join(directoryPath, nodeName); | ||
if (typeof nodeValue === 'string') { | ||
if (typeof nodeValue === "string" || nodeValue instanceof Uint8Array) { | ||
await ensureDirectory(dirname(nodePath)); | ||
@@ -301,3 +304,3 @@ await writeFile(nodePath, nodeValue); | ||
options: IWalkOptions = {}, | ||
filePaths: string[] = [] | ||
filePaths: string[] = [], | ||
): Promise<string[]> { | ||
@@ -304,0 +307,0 @@ const { filterFile = returnsTrue, filterDirectory = returnsTrue } = options; |
@@ -1,3 +0,3 @@ | ||
export * from './create-extended-api'; | ||
export * from './set-multi-map'; | ||
export * from './sync-to-async-fs'; | ||
export * from "./create-extended-api"; | ||
export * from "./set-multi-map"; | ||
export * from "./sync-to-async-fs"; |
@@ -6,3 +6,3 @@ import type { | ||
CallbackFnVoid, | ||
} from '@file-services/types'; | ||
} from "@file-services/types"; | ||
@@ -18,3 +18,3 @@ export function syncToAsyncFs(syncFs: IBaseFileSystemSync): IBaseFileSystemAsync { | ||
return syncFs.readFileSync(...args); | ||
} as IBaseFileSystemPromiseActions['readFile'], | ||
} as IBaseFileSystemPromiseActions["readFile"], | ||
async writeFile(...args) { | ||
@@ -28,3 +28,3 @@ return syncFs.writeFileSync(...args); | ||
return syncFs.readdirSync(...args); | ||
} as IBaseFileSystemPromiseActions['readdir'], | ||
} as IBaseFileSystemPromiseActions["readdir"], | ||
async mkdir(directoryPath, ...args) { | ||
@@ -70,11 +70,11 @@ return syncFs.mkdirSync(directoryPath, ...args); | ||
}, | ||
readFile: callbackify(syncFs.readFileSync) as IBaseFileSystemAsync['readFile'], | ||
writeFile: callbackify(syncFs.writeFileSync) as IBaseFileSystemAsync['writeFile'], | ||
copyFile: callbackify(syncFs.copyFileSync) as IBaseFileSystemAsync['copyFile'], | ||
readFile: callbackify(syncFs.readFileSync) as IBaseFileSystemAsync["readFile"], | ||
writeFile: callbackify(syncFs.writeFileSync) as IBaseFileSystemAsync["writeFile"], | ||
copyFile: callbackify(syncFs.copyFileSync) as IBaseFileSystemAsync["copyFile"], | ||
unlink: callbackify(syncFs.unlinkSync), | ||
readdir: callbackify(syncFs.readdirSync) as IBaseFileSystemAsync['readdir'], | ||
mkdir: callbackify(syncFs.mkdirSync) as unknown as IBaseFileSystemAsync['mkdir'], | ||
readdir: callbackify(syncFs.readdirSync) as IBaseFileSystemAsync["readdir"], | ||
mkdir: callbackify(syncFs.mkdirSync) as unknown as IBaseFileSystemAsync["mkdir"], | ||
rmdir: callbackify(syncFs.rmdirSync), | ||
stat: callbackify(syncFs.statSync) as unknown as IBaseFileSystemAsync['stat'], | ||
lstat: callbackify(syncFs.lstatSync) as unknown as IBaseFileSystemAsync['lstat'], | ||
stat: callbackify(syncFs.statSync) as unknown as IBaseFileSystemAsync["stat"], | ||
lstat: callbackify(syncFs.lstatSync) as unknown as IBaseFileSystemAsync["lstat"], | ||
realpath: callbackify(syncFs.realpathSync), | ||
@@ -89,4 +89,4 @@ rename: callbackify(syncFs.renameSync), | ||
const callback = args.pop() as (error: Error | null, value: R) => void; | ||
if (typeof callback !== 'function') { | ||
throw new Error('callback is not a function'); | ||
if (typeof callback !== "function") { | ||
throw new Error("callback is not a function"); | ||
} | ||
@@ -93,0 +93,0 @@ try { |
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
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
106170
1449
+ Added@file-services/types@9.4.1(transitive)
- Removed@file-services/types@8.3.3(transitive)
Updated@file-services/types@^9.0.0