@bscotch/pathy
Advanced tools
Comparing version 2.9.0 to 2.10.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, PathyWriteOptions } from './pathy.types.js'; | ||
import type { PathyCopyOptions, PathyFindParentOptions, PathyInfix, PathyListChildrenOptions, PathyOrString, PathyReadOptions, PathyReadOutput, PathyRemoveOptions, PathyWriteOptions } from './pathy.types.js'; | ||
export interface PathyOptions<T> { | ||
@@ -215,9 +215,9 @@ cwd?: PathyOrString; | ||
/** | ||
* Delete this file. | ||
* Delete this path. | ||
*/ | ||
delete(options?: PathyCopyOptions): Promise<void>; | ||
delete(options?: PathyRemoveOptions): Promise<void>; | ||
/** | ||
* @alias {@link Pathy.delete} | ||
*/ | ||
readonly rm: (options?: PathyCopyOptions) => Promise<void>; | ||
readonly rm: (options?: PathyRemoveOptions) => Promise<void>; | ||
listSiblings(): Promise<Pathy<unknown>[]>; | ||
@@ -224,0 +224,0 @@ findChild(basename: string | RegExp, options?: { |
import fs from 'fs'; | ||
import fse from 'fs-extra'; | ||
import nodePath from 'path'; | ||
import { rmSafe } from './fsSafe.js'; | ||
import { PathyStatic } from './pathy.static.js'; | ||
@@ -214,3 +215,3 @@ import { arrayWrapped, assert } from './util.js'; | ||
async stat() { | ||
return await fse.stat(this.absolute); | ||
return await Pathy.stat(this.absolute); | ||
} | ||
@@ -312,8 +313,6 @@ statSync() { | ||
/** | ||
* Delete this file. | ||
* Delete this path. | ||
*/ | ||
async delete(options) { | ||
if (await fse.pathExists(this.absolute)) { | ||
await fse.rm(this.absolute, options); | ||
} | ||
await rmSafe(this, options); | ||
} | ||
@@ -320,0 +319,0 @@ /** |
@@ -9,2 +9,3 @@ import { __decorate, __metadata } from "tslib"; | ||
import yaml from 'yaml'; | ||
import { readSafe, statSafe, writeSafe } from './fsSafe.js'; | ||
/** | ||
@@ -431,5 +432,3 @@ * A base class providing static functions for {@link Pathy}. | ||
static async stat(filepath) { | ||
return typeof filepath == 'string' | ||
? await fse.stat(filepath) | ||
: filepath.stat(); | ||
return await statSafe(filepath); | ||
} | ||
@@ -492,3 +491,3 @@ static async exists(filepath) { | ||
} | ||
await fse.writeFile(filepath, serialized); | ||
await writeSafe(filepath, serialized); | ||
} | ||
@@ -516,3 +515,3 @@ /** | ||
// Handle the binary case | ||
const binary = await fse.readFile(filepath.toString()); | ||
const binary = await readSafe(filepath, options); | ||
if (options?.encoding === false) { | ||
@@ -519,0 +518,0 @@ if (customParser) { |
@@ -16,3 +16,3 @@ /// <reference types="node" resolution-mode="require"/> | ||
*/ | ||
export interface PathyReadOptions<Parsed, Fallback, Encoding extends PathyReadEncoding, Schema extends PathySchema<Parsed> | never> { | ||
export interface PathyReadOptions<Parsed, Fallback, Encoding extends PathyReadEncoding, Schema extends PathySchema<Parsed> | never> extends FileRetryOptions { | ||
/** | ||
@@ -68,2 +68,15 @@ * The file encoding. If this is false, | ||
} | ||
export interface FileRetryOptions { | ||
/** | ||
* If there is an error and this is non-falsey, the read operation | ||
* will be attempted again up to this number of times. | ||
* @default 0 | ||
*/ | ||
maxRetries?: number; | ||
/** | ||
* The time (in milliseconds) to wait between read-retry attempts. | ||
* @default 20 | ||
*/ | ||
retryDelayMillis?: number; | ||
} | ||
export interface PathyWriteOptions { | ||
@@ -271,3 +284,14 @@ /** | ||
} | ||
export interface PathyRemoveOptions { | ||
force?: boolean; | ||
maxRetries?: number; | ||
recursive?: boolean; | ||
retryDelay?: number; | ||
/** | ||
* By default, if the target path doesn't exist no error is thrown. | ||
* Set this to `true` to throw an error if the target path doesn't exist. | ||
*/ | ||
throwIfMissing?: boolean; | ||
} | ||
export {}; | ||
//# sourceMappingURL=pathy.types.d.ts.map |
@@ -9,5 +9,5 @@ export type ArrayWrapped<T> = T extends any[] ? T : [T]; | ||
export declare class PathyError extends Error { | ||
constructor(message: string, asserter?: Function); | ||
constructor(message: string, cause?: any, asserter?: Function); | ||
} | ||
export declare function assert(claim: any, message: string): asserts claim; | ||
export declare function assert(claim: any, message: string, cause?: any): asserts claim; | ||
/** | ||
@@ -14,0 +14,0 @@ * A decorator for async methods that ensures that calls to |
@@ -15,11 +15,12 @@ /** | ||
export class PathyError extends Error { | ||
constructor(message, asserter) { | ||
constructor(message, cause, asserter) { | ||
super(message); | ||
this.name = 'PathyError'; | ||
this.cause = cause; | ||
Error.captureStackTrace(this, asserter || this.constructor); | ||
} | ||
} | ||
export function assert(claim, message) { | ||
export function assert(claim, message, cause) { | ||
if (!claim) { | ||
throw new PathyError(message, assert); | ||
throw new PathyError(message, cause, assert); | ||
} | ||
@@ -26,0 +27,0 @@ } |
{ | ||
"name": "@bscotch/pathy", | ||
"version": "2.9.0", | ||
"version": "2.10.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
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
127239
29
2009