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

Function resolvePrettierConfigDir

src/config.ts:13–44  ·  view source on GitHub ↗
(
  filePath: string,
  inputDir: string,
)

Source from the content-addressed store, hash-verified

11let prettierConfigCache = expiringMap<string, string | null>(10_000)
12
13async function resolvePrettierConfigDir(
14 filePath: string,
15 inputDir: string,
16): Promise<string> {
17 // Check cache for this directory
18 let cached = prettierConfigCache.get(inputDir)
19 if (cached !== undefined) {
20 return cached ?? process.cwd()
21 }
22
23 const resolve = async () => {
24 try {
25 return await prettier.resolveConfigFile(filePath)
26 } catch (err) {
27 console.error('prettier-config-not-found', 'Failed to resolve Prettier Config')
28 console.error('prettier-config-not-found-err', err)
29 return null
30 }
31 }
32
33 let prettierConfig = await resolve()
34
35 // Cache all directories from inputDir up to config location
36 if (prettierConfig) {
37 let configDir = path.dirname(prettierConfig)
38 cacheForDirs(prettierConfigCache, inputDir, configDir, configDir)
39 return configDir
40 } else {
41 prettierConfigCache.set(inputDir, null)
42 return process.cwd()
43 }
44}
45
46export async function getTailwindConfig(options: ParserOptions): Promise<UnifiedApi> {
47 let cwd = process.cwd()

Callers 1

getTailwindConfigFunction · 0.85

Calls 4

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…