(cwd: string)
| 16 | } |
| 17 | |
| 18 | export function getNextjsVersion(cwd: string): NextjsVersionResult { |
| 19 | try { |
| 20 | const nextPkgPath = require.resolve('next/package.json', { paths: [cwd] }) |
| 21 | const pkg = JSON.parse(fs.readFileSync(nextPkgPath, 'utf-8')) |
| 22 | return { version: pkg.version } |
| 23 | } catch { |
| 24 | // Not found at root - check for monorepo workspace |
| 25 | const workspace = detectWorkspace(cwd) |
| 26 | if (workspace.isMonorepo && workspace.packages.length > 0) { |
| 27 | const highestVersion = findNextjsInWorkspace(cwd, workspace.packages) |
| 28 | |
| 29 | if (highestVersion) { |
| 30 | return { version: highestVersion } |
| 31 | } |
| 32 | |
| 33 | return { |
| 34 | version: null, |
| 35 | error: `No Next.js found in ${workspace.type} workspace packages.`, |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | return { |
| 40 | version: null, |
| 41 | error: 'Next.js is not installed in this project.', |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | function versionToGitHubTag(version: string): string { |
| 47 | return version.startsWith('v') ? version : `v${version}` |
no test coverage detected