@bscotch/pathy
Advanced tools
Comparing version 2.11.0 to 2.12.0
@@ -18,2 +18,4 @@ /// <reference types="node" resolution-mode="require"/> | ||
export declare function rmSafe(path: PathyOrString, options?: PathyRemoveOptions): Promise<void>; | ||
export declare function isMissingError(err: any): boolean; | ||
export declare function isPermissionsError(err: any): boolean; | ||
//# sourceMappingURL=fsSafe.d.ts.map |
@@ -93,3 +93,3 @@ import fsp from 'node:fs/promises'; | ||
catch (err) { | ||
if (_isMissingError(err)) { | ||
if (isMissingError(err)) { | ||
if (options?.throwIfMissing) { | ||
@@ -116,7 +116,16 @@ throw err; | ||
} | ||
function _isMissingError(err) { | ||
return err instanceof Error && 'code' in err && err.code === 'ENOENT'; | ||
export function isMissingError(err) { | ||
if (!err || typeof err !== 'object') | ||
return false; | ||
return ((err instanceof Error && 'code' in err && err.code === 'ENOENT') || | ||
('cause' in err && isMissingError(err.cause))); | ||
} | ||
export function isPermissionsError(err) { | ||
if (!err || typeof err !== 'object') | ||
return false; | ||
return ((err instanceof Error && 'code' in err && err.code === 'EPERM') || | ||
('cause' in err && isPermissionsError(err.cause))); | ||
} | ||
function _throwIfMissing(err) { | ||
if (_isMissingError(err)) { | ||
if (isMissingError(err)) { | ||
throw err; | ||
@@ -123,0 +132,0 @@ } |
@@ -6,3 +6,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
import { PathyStatic } from './pathy.static.js'; | ||
import type { PathyCopyOptions, PathyFindParentOptions, PathyInfix, PathyListChildrenOptions, PathyOrString, PathyReadOptions, PathyReadOutput, PathyRemoveOptions, PathyWriteOptions } from './pathy.types.js'; | ||
import type { FileRetryOptions, PathyCopyOptions, PathyFindParentOptions, PathyInfix, PathyListChildrenOptions, PathyOrString, PathyReadOptions, PathyReadOutput, PathyRemoveOptions, PathyWriteOptions } from './pathy.types.js'; | ||
export interface PathyOptions<T> { | ||
@@ -142,7 +142,7 @@ cwd?: PathyOrString; | ||
assert?: boolean; | ||
}): Promise<boolean>; | ||
} & FileRetryOptions): Promise<boolean>; | ||
existsSync(options?: { | ||
assert?: boolean; | ||
}): boolean; | ||
stat(): Promise<fs.Stats>; | ||
stat(options?: FileRetryOptions): Promise<fs.Stats>; | ||
statSync(): fs.Stats; | ||
@@ -149,0 +149,0 @@ /** |
@@ -192,3 +192,3 @@ import fs from 'fs'; | ||
try { | ||
await this.stat(); | ||
await this.stat(options); | ||
return true; | ||
@@ -215,4 +215,4 @@ } | ||
} | ||
async stat() { | ||
return await Pathy.stat(this.absolute); | ||
async stat(options) { | ||
return await Pathy.stat(this.absolute, options); | ||
} | ||
@@ -219,0 +219,0 @@ statSync() { |
@@ -5,3 +5,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
import type { Pathy } from './pathy.js'; | ||
import type { PathyFindParentOptions, PathyInfix, PathyListChildrenOptions, PathyOrString, PathyReadOptions, PathyReadOutput, PathySchema, PathyWriteOptions } from './pathy.types.js'; | ||
import type { FileRetryOptions, PathyFindParentOptions, PathyInfix, PathyListChildrenOptions, PathyOrString, PathyReadOptions, PathyReadOutput, PathySchema, PathyWriteOptions } from './pathy.types.js'; | ||
/** | ||
@@ -28,3 +28,3 @@ * A base class providing static functions for {@link Pathy}. | ||
*/ | ||
static replaceSeparator(path: string, separator?: "\\" | "/"): string; | ||
static replaceSeparator(path: string, separator?: "/" | "\\"): string; | ||
static basename(path: PathyOrString): string; | ||
@@ -139,4 +139,4 @@ /** | ||
static normalizedExtension(filepath: PathyOrString): string | undefined; | ||
static stat(filepath: PathyOrString): Promise<Stats>; | ||
static exists(filepath: PathyOrString): Promise<boolean>; | ||
static stat(filepath: PathyOrString, options?: FileRetryOptions): Promise<Stats>; | ||
static exists(filepath: PathyOrString, options?: FileRetryOptions): Promise<boolean>; | ||
/** | ||
@@ -143,0 +143,0 @@ * Write data to file, using the extension to determine |
@@ -306,6 +306,6 @@ import { __decorate, __metadata } from "tslib"; | ||
try { | ||
await child.stat(); | ||
await child.stat(options); | ||
} | ||
catch (err) { | ||
if (err.code === 'EPERM') { | ||
if (options.onError !== 'throw') { | ||
continue; | ||
@@ -431,8 +431,8 @@ } | ||
} | ||
static async stat(filepath) { | ||
return await statSafe(filepath); | ||
static async stat(filepath, options) { | ||
return await statSafe(filepath, options); | ||
} | ||
static async exists(filepath) { | ||
static async exists(filepath, options) { | ||
try { | ||
await PathyStatic.stat(filepath); | ||
await PathyStatic.stat(filepath, options); | ||
return true; | ||
@@ -504,3 +504,5 @@ } | ||
ok(doesExist || hasFallback, `File does not exist: ${filepath}`); | ||
const fileInfo = doesExist ? await PathyStatic.stat(filepath) : undefined; | ||
const fileInfo = doesExist | ||
? await PathyStatic.stat(filepath, options) | ||
: undefined; | ||
const isDirectory = doesExist && fileInfo.isDirectory(); | ||
@@ -507,0 +509,0 @@ ok(!isDirectory, `Expected file, found directory: ${filepath}`); |
@@ -150,3 +150,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
} | ||
export interface PathyListChildrenOptions<As = Pathy> { | ||
export interface PathyListChildrenOptions<As = Pathy> extends FileRetryOptions { | ||
/** | ||
@@ -270,2 +270,8 @@ * If provided, filter returned filepaths based | ||
includeDirs?: boolean | 'only'; | ||
/** | ||
* If there is an error trying to stat a file (e.g. a permissions error), what should we do? | ||
* | ||
* @default 'skip' | ||
*/ | ||
onError?: 'throw' | 'skip'; | ||
} | ||
@@ -272,0 +278,0 @@ export type PathyOrString = string | Pathy; |
{ | ||
"name": "@bscotch/pathy", | ||
"version": "2.11.0", | ||
"version": "2.12.0", | ||
"description": "A toolkit for simplifying working with paths and files.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
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
130321
2036