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

Function getTailwindConfig

src/config.ts:46–94  ·  view source on GitHub ↗
(options: ParserOptions)

Source from the content-addressed store, hash-verified

44}
45
46export async function getTailwindConfig(options: ParserOptions): Promise<UnifiedApi> {
47 let cwd = process.cwd()
48 let inputDir = options.filepath ? path.dirname(options.filepath) : cwd
49
50 // Only resolve prettier config dir if we need it for relative path resolution
51 let needsPrettierConfig =
52 (options.tailwindConfig && !path.isAbsolute(options.tailwindConfig)) ||
53 (options.tailwindStylesheet && !path.isAbsolute(options.tailwindStylesheet)) ||
54 (options.tailwindEntryPoint && !path.isAbsolute(options.tailwindEntryPoint))
55
56 let configDir: string
57 if (needsPrettierConfig) {
58 configDir = await resolvePrettierConfigDir(options.filepath, inputDir)
59 } else {
60 configDir = cwd
61 }
62
63 let configPath =
64 options.tailwindConfig && !options.tailwindConfig.endsWith('.css')
65 ? options.tailwindConfig
66 : undefined
67
68 let stylesheetPath = options.tailwindStylesheet
69 if (!stylesheetPath && options.tailwindEntryPoint) {
70 console.warn(
71 'entrypoint-is-deprecated',
72 configDir,
73 'Deprecated: Use the `tailwindStylesheet` option for v4 projects instead of `tailwindEntryPoint`.',
74 )
75 stylesheetPath = options.tailwindEntryPoint
76 }
77
78 if (!stylesheetPath && options.tailwindConfig && options.tailwindConfig.endsWith('.css')) {
79 console.warn(
80 'config-as-css-is-deprecated',
81 configDir,
82 'Deprecated: Use the `tailwindStylesheet` option for v4 projects instead of `tailwindConfig`.',
83 )
84 stylesheetPath = options.tailwindConfig
85 }
86
87 return getTailwindConfigFromLib({
88 base: configDir,
89 filepath: options.filepath,
90 configPath,
91 stylesheetPath,
92 packageName: options.tailwindPackageName,
93 })
94}

Callers 1

loadTailwindCSSFunction · 0.90

Calls 1

resolvePrettierConfigDirFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…