MCPcopy Create free account
hub / github.com/formkit/formkit / detectTailwindVersion

Function detectTailwindVersion

packages/cli/src/theme.ts:44–61  ·  view source on GitHub ↗

* Detect the Tailwind CSS version from the user's package.json. * Returns 3, 4, or null if unable to determine.

()

Source from the content-addressed store, hash-verified

42 * Returns 3, 4, or null if unable to determine.
43 */
44async function detectTailwindVersion(): Promise<3 | 4 | null> {
45 try {
46 const pkgPath = resolve(process.cwd(), 'package.json')
47 if (!existsSync(pkgPath)) return null
48 const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'))
49 const deps = { ...pkg.dependencies, ...pkg.devDependencies }
50 const twVersion = deps['tailwindcss']
51 if (!twVersion) return null
52 // Check if v3 (handles ^3, ~3, 3.x.x, etc.)
53 if (/^[\^~>=]*3/.test(twVersion)) {
54 return 3
55 }
56 // Default to v4 for anything else (including 'latest', ^4, etc.)
57 return 4
58 } catch {
59 return null
60 }
61}
62
63/**
64 * Get the appropriate theme name based on detected Tailwind version.

Callers 1

buildThemeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected