2025-06-01 18:40:44 +00:00
|
|
|
import { exists } from "fs/promises"
|
|
|
|
|
import { dirname, join } from "path"
|
|
|
|
|
|
|
|
|
|
export namespace Filesystem {
|
2025-06-03 19:57:38 +00:00
|
|
|
export async function findUp(target: string, start: string, stop?: string) {
|
2025-06-01 18:40:44 +00:00
|
|
|
let currentDir = start
|
|
|
|
|
while (true) {
|
|
|
|
|
const targetPath = join(currentDir, target)
|
|
|
|
|
if (await exists(targetPath)) return targetPath
|
2025-06-03 19:57:38 +00:00
|
|
|
if (stop === currentDir) return
|
2025-06-01 18:40:44 +00:00
|
|
|
const parentDir = dirname(currentDir)
|
|
|
|
|
if (parentDir === currentDir) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
currentDir = parentDir
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|