(
cache: { set(key: string, value: V): void; get(key: string): V | undefined },
inputDir: string,
value: V,
targetDir: string,
makeKey: (dir: string) => string = (dir) => dir,
)
| 161 | * - '/repo' -> '/repo/package.json' |
| 162 | */ |
| 163 | export function cacheForDirs<V>( |
| 164 | cache: { set(key: string, value: V): void; get(key: string): V | undefined }, |
| 165 | inputDir: string, |
| 166 | value: V, |
| 167 | targetDir: string, |
| 168 | makeKey: (dir: string) => string = (dir) => dir, |
| 169 | ): void { |
| 170 | let dir = inputDir |
| 171 | while (dir !== path.dirname(dir) && dir.length >= targetDir.length) { |
| 172 | const key = makeKey(dir) |
| 173 | // Stop caching if we hit an existing entry |
| 174 | if (cache.get(key) !== undefined) break |
| 175 | |
| 176 | cache.set(key, value) |
| 177 | if (dir === targetDir) break |
| 178 | dir = path.dirname(dir) |
| 179 | } |
| 180 | } |
no test coverage detected
searching dependent graphs…