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

Function resolveTailwindPath

src/sorter.ts:206–245  ·  view source on GitHub ↗
(
  options: { packageName?: string },
  baseDir: string,
)

Source from the content-addressed store, hash-verified

204let resolvedModCache = expiringMap<string, [any, string | null]>(10_000)
205
206async function resolveTailwindPath(
207 options: { packageName?: string },
208 baseDir: string,
209): Promise<[any, string | null]> {
210 let pkgName = options.packageName ?? 'tailwindcss'
211 let makeKey = (dir: string) => `${pkgName}:${dir}`
212
213 // Check cache for this directory
214 let cached = resolvedModCache.get(makeKey(baseDir))
215 if (cached !== undefined) {
216 return cached
217 }
218
219 let resolve = async () => {
220 let pkgDir: string | null = null
221 let mod: any = null
222
223 try {
224 let pkgPath = resolveJsFrom(baseDir, pkgName)
225 mod = await import(pathToFileURL(pkgPath).toString())
226
227 let pkgFile = resolveJsFrom(baseDir, `${pkgName}/package.json`)
228 pkgDir = path.dirname(pkgFile)
229 } catch {}
230
231 return [mod, pkgDir] as [any, string | null]
232 }
233
234 let result = await resolve()
235
236 // Cache all directories from baseDir up to package location
237 let [, pkgDir] = result
238 if (pkgDir) {
239 cacheForDirs(resolvedModCache, baseDir, result, pkgDir, makeKey)
240 } else {
241 resolvedModCache.set(makeKey(baseDir), result)
242 }
243
244 return result
245}
246
247function resolveJsConfigPath(configPath: string | null): string | null {
248 if (!configPath) return null

Callers 1

getTailwindConfigFunction · 0.85

Calls 5

makeKeyFunction · 0.85
cacheForDirsFunction · 0.85
getMethod · 0.80
setMethod · 0.80
resolveFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…