MCPcopy
hub / github.com/tailwindlabs/prettier-plugin-tailwindcss / cacheForDirs

Function cacheForDirs

src/utils.ts:163–180  ·  view source on GitHub ↗
(
  cache: { set(key: string, value: V): void; get(key: string): V | undefined },
  inputDir: string,
  value: V,
  targetDir: string,
  makeKey: (dir: string) => string = (dir) => dir,
)

Source from the content-addressed store, hash-verified

161 * - '/repo' -> '/repo/package.json'
162 */
163export 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}

Callers 3

resolvePrettierConfigDirFunction · 0.85
resolveTailwindPathFunction · 0.85
findClosestJsConfigFunction · 0.85

Calls 3

makeKeyFunction · 0.85
getMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…