cloudaxe-opencode/packages/opencode/src/util/filesystem.ts

19 lines
466 B
TypeScript
Raw Normal View History

import { exists } from "fs/promises"
import { dirname, join } from "path"
export namespace Filesystem {
export async function findUp(target: string, start: string) {
let currentDir = start
while (true) {
const targetPath = join(currentDir, target)
if (await exists(targetPath)) return targetPath
const parentDir = dirname(currentDir)
if (parentDir === currentDir) {
return
}
currentDir = parentDir
}
}
}