@bscotch/pathy
Advanced tools
Comparing version 2.2.0 to 2.4.0
@@ -42,3 +42,3 @@ /// <reference types="node" /> | ||
readonly workingDirectory: string; | ||
constructor(path?: PathyOrString, cwd?: PathyOrString); | ||
constructor(path?: PathyOrString | string[], cwd?: PathyOrString); | ||
get directory(): string; | ||
@@ -103,3 +103,3 @@ get name(): string; | ||
*/ | ||
read<Parsed = FileContent, Encoding extends BufferEncoding | false = 'utf8'>(options?: PathyReadOptions<Parsed, Encoding>): Promise<Parsed>; | ||
read<Parsed = FileContent, Fallback = never, Encoding extends BufferEncoding | false = 'utf8'>(options?: PathyReadOptions<Parsed, Fallback, Encoding>): Promise<Parsed | Fallback>; | ||
/** | ||
@@ -106,0 +106,0 @@ * Write to file at the current path, automatically serializing |
@@ -45,3 +45,3 @@ import { __decorate, __metadata } from "tslib"; | ||
this.workingDirectory = Pathy.normalize(cwd); | ||
this.normalized = Pathy.normalize(path); | ||
this.normalized = Pathy.normalize(Array.isArray(path) ? Pathy.join(...path) : path); | ||
this.absolute = Pathy.resolve(this.workingDirectory, this.normalized); | ||
@@ -251,3 +251,5 @@ this.relative = Pathy.resolveRelative(this.workingDirectory, this.absolute); | ||
async delete(options) { | ||
await fse.rm(this.absolute, options); | ||
if (await fse.pathExists(this.absolute)) { | ||
await fse.rm(this.absolute, options); | ||
} | ||
} | ||
@@ -254,0 +256,0 @@ async listSiblings() { |
@@ -27,3 +27,3 @@ /// <reference types="node" /> | ||
*/ | ||
static replaceSeparator(path: string, separator?: string): string; | ||
static replaceSeparator(path: string, separator?: "/" | "\\"): string; | ||
static basename(path: PathyOrString): string; | ||
@@ -139,5 +139,5 @@ /** | ||
*/ | ||
static read<Parsed = unknown, Encoding extends BufferEncoding | false = 'utf8'>(filepath: PathyOrString, options?: PathyReadOptions<Parsed, Encoding>): Promise<Parsed>; | ||
static read<Parsed = unknown, Fallback = never, Encoding extends BufferEncoding | false = 'utf8'>(filepath: PathyOrString, options?: PathyReadOptions<Parsed, Fallback, Encoding>): Promise<Parsed | Fallback>; | ||
static get defaultIgnoredDirs(): readonly ["node_modules", ".git", ".hg", ".svn", ".idea", ".vscode", ".vscode-test"]; | ||
} | ||
//# sourceMappingURL=pathy.static.d.ts.map |
@@ -484,4 +484,11 @@ import { __decorate, __metadata } from "tslib"; | ||
static async read(filepath, options) { | ||
const fileInfo = await PathyStatic.stat(filepath); | ||
ok(fileInfo.isFile(), `No file found at: ${filepath}`); | ||
const doesExist = await PathyStatic.exists(filepath); | ||
const hasFallback = options && 'fallback' in options; | ||
ok(doesExist || hasFallback, `File does not exist: ${filepath}`); | ||
const fileInfo = doesExist ? await PathyStatic.stat(filepath) : undefined; | ||
ok(!doesExist || !fileInfo.isDirectory(), `Expected file, found directory: ${filepath}`); | ||
if (!doesExist) { | ||
ok(hasFallback, `No file found at: ${filepath}`); | ||
return options.fallback; | ||
} | ||
const doNotParse = options?.parse === false; | ||
@@ -488,0 +495,0 @@ const customParser = typeof options?.parse == 'function' ? options.parse : undefined; |
@@ -11,3 +11,3 @@ /// <reference types="node" /> | ||
*/ | ||
export interface PathyReadOptions<Parsed, Encoding extends PathyReadEncoding> { | ||
export interface PathyReadOptions<Parsed, Fallback, Encoding extends PathyReadEncoding> { | ||
/** | ||
@@ -49,2 +49,10 @@ * The file encoding. If this is false, | ||
parse?: boolean | ((rawContent: Encoding extends false ? Buffer : string) => Parsed); | ||
/** | ||
* By default pathy will throw an error if the file does not exist. | ||
* If you provide a default value, that value will be returned instead. | ||
* | ||
* Note that using this option removes the ability to distinguish between | ||
* a file that does not exist and one that contains the fallback value. | ||
*/ | ||
fallback?: Fallback; | ||
} | ||
@@ -142,2 +150,6 @@ export interface PathyWriteOptions { | ||
* extension matches something. | ||
* | ||
* @example | ||
* ['.js','.ts'] | ||
* ['js','ts'] // Dot added automatically if missing! | ||
*/ | ||
@@ -144,0 +156,0 @@ includeExtension?: string[] | string; |
{ | ||
"name": "@bscotch/pathy", | ||
"version": "2.2.0", | ||
"version": "2.4.0", | ||
"type": "module", | ||
@@ -14,4 +14,3 @@ "exports": { | ||
"dependencies": { | ||
"@bscotch/utility": "6.2.0", | ||
"chai": "^4.3.6", | ||
"@bscotch/utility": "6.4.0", | ||
"fs-extra": "^10.1.0", | ||
@@ -23,5 +22,11 @@ "json5": "^2.2.1", | ||
"devDependencies": { | ||
"@local/helpers": "0.0.0", | ||
"@types/chai": "^4.3.3", | ||
"@types/fs-extra": "^9.0.13", | ||
"type-fest": "^2.16.0", | ||
"typescript": "4.9.0-dev.20220829" | ||
"@types/mocha": "^9.1.1", | ||
"chai": "^4.3.6", | ||
"mocha": "^10.0.0", | ||
"rimraf": "^3.0.2", | ||
"type-fest": "^3.0.0", | ||
"typescript": "4.9.1-beta" | ||
}, | ||
@@ -32,6 +37,8 @@ "publishConfig": { | ||
"scripts": { | ||
"build": "tsc --build", | ||
"test": "treb test", | ||
"build": "tsc-x --build", | ||
"clean": "rimraf build dist *.tsbuildinfo **/*.tsbuildinfo", | ||
"test": "mocha --config ../../config/.mocharc.cjs", | ||
"test:dev": "mocha --config ../../config/.mocharc.cjs --forbid-only=false --parallel=false --timeout=9999999999", | ||
"watch": "tsc --build --watch" | ||
} | ||
} |
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
94322
5
9
24
1594
+ Added@bscotch/utility@6.4.0(transitive)
- Removedchai@^4.3.6
- Removed@bscotch/utility@6.2.0(transitive)
- Removedassertion-error@1.1.0(transitive)
- Removedchai@4.5.0(transitive)
- Removedcheck-error@1.0.3(transitive)
- Removeddeep-eql@4.1.4(transitive)
- Removedget-func-name@2.0.2(transitive)
- Removedloupe@2.3.7(transitive)
- Removedpathval@1.1.1(transitive)
- Removedtype-detect@4.1.0(transitive)
Updated@bscotch/utility@6.4.0