MCPcopy Create free account
hub / github.com/anomalyco/opencode / findUp

Function findUp

packages/opencode/src/util/filesystem.ts:186–211  ·  view source on GitHub ↗
(
  target: string | string[],
  start: string,
  stop?: string,
  options?: { rootFirst?: boolean },
)

Source from the content-addressed store, hash-verified

184 options?: { rootFirst?: boolean },
185): Promise<string[]>
186export async function findUp(
187 target: string | string[],
188 start: string,
189 stop?: string,
190 options?: { rootFirst?: boolean },
191) {
192 const dirs = [start]
193 let current = start
194 while (true) {
195 if (stop === current) break
196 const parent = dirname(current)
197 if (parent === current) break
198 dirs.push(parent)
199 current = parent
200 }
201
202 const targets = Array.isArray(target) ? target : [target]
203 const result = []
204 for (const dir of options?.rootFirst ? dirs.toReversed() : dirs) {
205 for (const item of targets) {
206 const search = join(dir, item)
207 if (await exists(search)) result.push(search)
208 }
209 }
210 return result
211}
212
213export async function* up(options: { targets: string[]; start: string; stop?: string }) {
214 const { targets, start, stop } = options

Callers

nothing calls this directly

Calls 3

joinFunction · 0.85
pushMethod · 0.80
existsFunction · 0.70

Tested by

no test coverage detected