MCPcopy
hub / github.com/vercel/next.js / getNextjsVersion

Function getNextjsVersion

packages/next-codemod/lib/agents-md.ts:18–44  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

16}
17
18export 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
46function versionToGitHubTag(version: string): string {
47 return version.startsWith('v') ? version : `v${version}`

Callers 4

runAgentsMdFunction · 0.90
promptForOptionsFunction · 0.90
pullDocsFunction · 0.85

Calls 5

detectWorkspaceFunction · 0.85
findNextjsInWorkspaceFunction · 0.85
readFileSyncMethod · 0.80
resolveMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected