* Detect the Tailwind CSS version from the user's package.json. * Returns 3, 4, or null if unable to determine.
()
| 42 | * Returns 3, 4, or null if unable to determine. |
| 43 | */ |
| 44 | async 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. |