From 8879232f17854b003b1cfd663e645536117b3b92 Mon Sep 17 00:00:00 2001 From: "Sebastian \"Sebbie\" Silbermann" Date: Tue, 1 Oct 2024 00:48:30 +0200 Subject: [PATCH] next-upgrade: Allow custom selection of codemods (#70634) --- packages/next-codemod/bin/upgrade.ts | 32 +++++++++++----------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/packages/next-codemod/bin/upgrade.ts b/packages/next-codemod/bin/upgrade.ts index f66cfdc11af62..05b85a4f8b82f 100644 --- a/packages/next-codemod/bin/upgrade.ts +++ b/packages/next-codemod/bin/upgrade.ts @@ -337,20 +337,18 @@ async function suggestCodemods( return } - let codemodsString = `\nThe following ${chalk.blue('codemods')} are available for your upgrade:` - relevantCodemods.forEach((codemod) => { - codemodsString += `\n- ${codemod.title} ${chalk.gray(`(${codemod.value})`)}` - }) - codemodsString += '\n' - - console.log(codemodsString) - - const responseCodemods = await prompts( + const { codemods } = await prompts( { - type: 'confirm', - name: 'apply', - message: `Do you want to apply these codemods?`, - initial: true, + type: 'multiselect', + name: 'codemods', + message: `\nThe following ${chalk.blue('codemods')} are recommended for your upgrade. Would you like to apply them?`, + choices: relevantCodemods.map((codemod) => { + return { + title: `${codemod.title} ${chalk.grey(`(${codemod.value})`)}`, + value: codemod.value, + selected: true, + } + }), }, { onCancel: () => { @@ -359,13 +357,9 @@ async function suggestCodemods( } ) - if (!responseCodemods.apply) { - return - } - - for (const codemod of relevantCodemods) { + for (const codemod of codemods) { execSync( - `npx @next/codemod@latest ${codemod.value} ${process.cwd()} --force`, + `npx --yes @next/codemod@latest ${codemod} ${process.cwd()} --force`, { stdio: 'inherit', }