@arktype/fs
Advanced tools
Comparing version 0.1.2 to 0.2.1
@@ -28,3 +28,6 @@ export { rmSync } from "node:fs"; | ||
export declare const fsRoot: string; | ||
export declare const findPackageRoot: (fromDir?: string) => string; | ||
export declare const findPackageRoot: (fromDir?: string) => string | null; | ||
export declare const assertPackageRoot: (fromDir?: string) => string; | ||
export declare const findPackageAncestors: (fromDir?: string) => string[]; | ||
export declare const readPackageJsonAncestors: (fromDir?: string) => any[]; | ||
export declare const fromPackageRoot: (...joinWith: string[]) => string; | ||
@@ -31,0 +34,0 @@ export declare const readPackageJson: (startDir?: string) => any; |
@@ -81,6 +81,24 @@ import { cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs"; | ||
} | ||
return null; | ||
}; | ||
export const assertPackageRoot = (fromDir) => { | ||
const startDir = fromDir ?? dirOfCaller(); | ||
const result = findPackageRoot(fromDir); | ||
if (result) | ||
return result; | ||
throw new Error(`${startDir} is not part of a node package.`); | ||
}; | ||
export const fromPackageRoot = (...joinWith) => join(findPackageRoot(dirOfCaller()), ...joinWith); | ||
export const readPackageJson = (startDir) => readJson(join(findPackageRoot(startDir), "package.json")); | ||
export const findPackageAncestors = (fromDir) => { | ||
const dirs = []; | ||
let dir = fromDir ?? dirOfCaller(); | ||
while (dir) { | ||
dir = findPackageRoot(dir); | ||
if (dir) | ||
dirs.push(dir); | ||
} | ||
return dirs; | ||
}; | ||
export const readPackageJsonAncestors = (fromDir) => findPackageAncestors(fromDir).map(dir => readPackageJson(dir)); | ||
export const fromPackageRoot = (...joinWith) => join(assertPackageRoot(dirOfCaller()), ...joinWith); | ||
export const readPackageJson = (startDir) => readJson(join(assertPackageRoot(startDir), "package.json")); | ||
export const getSourceControlPaths = () => | ||
@@ -87,0 +105,0 @@ // include tracked and untracked files as long as they are not ignored |
@@ -15,3 +15,3 @@ // Copied from unmaintained package https://github.com/bevry/get-current-line to fix imports | ||
try { | ||
/** @ts-expect-error https://github.com/winstonjs/winston/issues/401#issuecomment-61913086 */ | ||
// @ts-expect-error https://github.com/winstonjs/winston/issues/401#issuecomment-61913086 | ||
const previous = err.__previous__ || err.__previous; | ||
@@ -18,0 +18,0 @@ stack = previous && previous.stack; |
{ | ||
"name": "@arktype/fs", | ||
"version": "0.1.2", | ||
"version": "0.2.1", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "David Blass", |
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
22759
536