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

19 lines
505 B
TypeScript
Raw Normal View History

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-09 19:28:06 +00:00
let current = start
const result = []
while (true) {
2025-06-09 19:28:06 +00:00
const search = join(current, target)
if (await exists(search)) result.push(search)
if (stop === current) break
const parent = dirname(current)
if (parent === current) break
current = parent
}
2025-06-09 19:28:06 +00:00
return result
}
}