Skip to content

Commit fcf4464

Browse files
committed
next-upgrade: Allow custom selection of codemods
Instead of having to choose between all or none of the codemods, each application can now be select up front. We select all by default so that you still have just one keypress for the happy path. But sometimes codemods are added later. Or we have codemods that may not be suitable depending on how code is structured. Or we have optional codemods. For me specifically it was just motivated by not being able to select a specific version yet and skipping the async API codemod while it's under development.
1 parent 32a0155 commit fcf4464

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

packages/next-codemod/bin/upgrade.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -320,20 +320,18 @@ async function suggestCodemods(
320320
return
321321
}
322322

323-
let codemodsString = `\nThe following ${chalk.blue('codemods')} are available for your upgrade:`
324-
relevantCodemods.forEach((codemod) => {
325-
codemodsString += `\n- ${codemod.title} ${chalk.gray(`(${codemod.value})`)}`
326-
})
327-
codemodsString += '\n'
328-
329-
console.log(codemodsString)
330-
331-
const responseCodemods = await prompts(
323+
const { codemods } = await prompts(
332324
{
333-
type: 'confirm',
334-
name: 'apply',
335-
message: `Do you want to apply these codemods?`,
336-
initial: true,
325+
type: 'multiselect',
326+
name: 'codemods',
327+
message: `\nThe following ${chalk.blue('codemods')} are recommended for your upgrade. Would you like to apply them?`,
328+
choices: relevantCodemods.map((codemod) => {
329+
return {
330+
title: `${codemod.title} ${chalk.grey(`(${codemod.value})`)}`,
331+
value: codemod.value,
332+
selected: true,
333+
}
334+
}),
337335
},
338336
{
339337
onCancel: () => {
@@ -342,13 +340,9 @@ async function suggestCodemods(
342340
}
343341
)
344342

345-
if (!responseCodemods.apply) {
346-
return
347-
}
348-
349-
for (const codemod of relevantCodemods) {
343+
for (const codemod of codemods) {
350344
execSync(
351-
`npx @next/codemod@latest ${codemod.value} ${process.cwd()} --force`,
345+
`npx --yes @next/codemod@latest ${codemod} ${process.cwd()} --force`,
352346
{
353347
stdio: 'inherit',
354348
}

0 commit comments

Comments
 (0)