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

Function runUpgrade

packages/next-codemod/bin/upgrade.ts:112–426  ·  view source on GitHub ↗
(
  revision: string | undefined,
  options: { verbose: boolean }
)

Source from the content-addressed store, hash-verified

110}
111
112export async function runUpgrade(
113 revision: string | undefined,
114 options: { verbose: boolean }
115): Promise<void> {
116 const { verbose } = options
117 const appPackageJsonPath = path.resolve(cwd, 'package.json')
118 let appPackageJson = JSON.parse(fs.readFileSync(appPackageJsonPath, 'utf8'))
119
120 const installedNextVersion = getInstalledNextVersion()
121
122 // Resolve semantic keywords to npm version queries
123 const resolvedRevision = resolveSemanticRevision(
124 revision ?? 'minor',
125 installedNextVersion
126 )
127
128 if (options.verbose) {
129 console.log(` Resolved upgrade target: ${resolvedRevision}`)
130 }
131
132 let targetNextPackageJson: {
133 version: string
134 peerDependencies: Record<string, string>
135 }
136
137 try {
138 // First, find the highest matching version
139 const versionsJSON = execSync(
140 `npm --silent view "next@${resolvedRevision}" --json --field version`,
141 { encoding: 'utf-8' }
142 )
143 const versionOrVersions = JSON.parse(versionsJSON)
144 let targetVersion: string
145 if (Array.isArray(versionOrVersions)) {
146 versionOrVersions.sort(compareVersions)
147 targetVersion = versionOrVersions[versionOrVersions.length - 1]
148 } else {
149 targetVersion = versionOrVersions
150 }
151
152 if (options.verbose) {
153 console.log(` Target version: ${targetVersion}`)
154 }
155
156 // Then fetch the full package info for that specific version
157 const targetNextPackage = execSync(
158 `npm --silent view "next@${targetVersion}" --json`,
159 { encoding: 'utf-8' }
160 )
161 targetNextPackageJson = JSON.parse(targetNextPackage)
162 } catch (e) {
163 if (options.verbose) {
164 console.error(' Error fetching package info:', e)
165 }
166 }
167
168 const validRevision =
169 targetNextPackageJson !== null &&

Callers 1

next-codemod.tsFile · 0.90

Calls 15

getPkgManagerFunction · 0.90
addPackageDependencyFunction · 0.90
runInstallationFunction · 0.90
runTransformFunction · 0.90
getInstalledNextVersionFunction · 0.85
resolveSemanticRevisionFunction · 0.85
compareVersionsFunction · 0.85
endMessageFunction · 0.85
getInstalledReactVersionFunction · 0.85
isUsingAppDirFunction · 0.85
isUsingPagesDirFunction · 0.85

Tested by

no test coverage detected