| 10 | * Returns 2 as the default if nitro is not found or the version cannot be determined. |
| 11 | */ |
| 12 | export async function getNitroMajorVersion(): Promise<number> { |
| 13 | try { |
| 14 | const { getPackageInfo } = await import('local-pkg'); |
| 15 | const info = await getPackageInfo('nitro'); |
| 16 | if (info?.version) { |
| 17 | const major = parseInt(info.version.split('.')[0] ?? '2', 10); |
| 18 | return isNaN(major) ? 2 : major; |
| 19 | } |
| 20 | } catch { |
| 21 | // If local-pkg is unavailable or nitro is not found, default to v2 |
| 22 | } |
| 23 | return 2; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Find the default SDK init file for the given type (client or server). |