Skip to content

Commit 6535e9a

Browse files
committed
next-upgrade: Stop interleaving user-input with long tasks
We now ask for all input in a single phase at the beginning followed by a single phase of lung running tasks that processes this input. Interleaving is unintuitive and may leave the process hanging if people tab out when the install takes more than a few seconds.
1 parent f95faf8 commit 6535e9a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/next-codemod/bin/upgrade.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ export async function runUpgrade(
164164
await suggestTurbopack(appPackageJson)
165165
}
166166

167+
const codemods = await suggestCodemods(
168+
installedNextVersion,
169+
targetNextVersion
170+
)
171+
167172
fs.writeFileSync(appPackageJsonPath, JSON.stringify(appPackageJson, null, 2))
168173

169174
const packageManager: PackageManager = getPkgManager(process.cwd())
@@ -193,7 +198,9 @@ export async function runUpgrade(
193198
silent: !verbose,
194199
})
195200

196-
await suggestCodemods(installedNextVersion, targetNextVersion)
201+
for (const codemod of codemods) {
202+
await runTransform(codemod, process.cwd(), { force: true })
203+
}
197204

198205
console.log(
199206
`\n${chalk.green('✔')} Your Next.js project has been upgraded successfully. ${chalk.bold('Time to ship! 🚢')}`
@@ -313,13 +320,13 @@ async function suggestTurbopack(packageJson: any): Promise<void> {
313320
async function suggestCodemods(
314321
initialNextVersion: string,
315322
targetNextVersion: string
316-
): Promise<void> {
323+
): Promise<string[]> {
317324
const initialVersionIndex = availableCodemods.findIndex(
318325
(versionCodemods) =>
319326
compareVersions(versionCodemods.version, initialNextVersion) > 0
320327
)
321328
if (initialVersionIndex === -1) {
322-
return
329+
return []
323330
}
324331

325332
let targetVersionIndex = availableCodemods.findIndex(
@@ -335,7 +342,7 @@ async function suggestCodemods(
335342
.flatMap((versionCodemods) => versionCodemods.codemods)
336343

337344
if (relevantCodemods.length === 0) {
338-
return
345+
return []
339346
}
340347

341348
const { codemods } = await prompts(
@@ -358,7 +365,5 @@ async function suggestCodemods(
358365
}
359366
)
360367

361-
for (const codemod of codemods) {
362-
await runTransform(codemod, process.cwd(), { force: true })
363-
}
368+
return codemods
364369
}

0 commit comments

Comments
 (0)