Unverified Commit 99e24f56 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

refactor(next-upgrade): ensures prompts are cancelled when user exits (#70930)

Without `onCancel` handling, even if `CTRL + C`, the prompt will not
exit and continue to next step. Added it to missing prompts calls.
parent a805a774
...@@ -3,7 +3,11 @@ import globby from 'globby' ...@@ -3,7 +3,11 @@ import globby from 'globby'
import prompts from 'prompts' import prompts from 'prompts'
import { join } from 'node:path' import { join } from 'node:path'
import { installPackages, uninstallPackage } from '../lib/handle-package' import { installPackages, uninstallPackage } from '../lib/handle-package'
import { checkGitStatus, TRANSFORMER_INQUIRER_CHOICES } from '../lib/utils' import {
checkGitStatus,
onCancel,
TRANSFORMER_INQUIRER_CHOICES,
} from '../lib/utils'
function expandFilePathsIfNeeded(filesBeforeExpansion) { function expandFilePathsIfNeeded(filesBeforeExpansion) {
const shouldExpandFiles = filesBeforeExpansion.some((file) => const shouldExpandFiles = filesBeforeExpansion.some((file) =>
...@@ -41,22 +45,28 @@ export async function runTransform( ...@@ -41,22 +45,28 @@ export async function runTransform(
} }
if (!path) { if (!path) {
const res = await prompts({ const res = await prompts(
type: 'text', {
name: 'path', type: 'text',
message: 'On which files or directory should the codemods be applied?', name: 'path',
initial: '.', message: 'On which files or directory should the codemods be applied?',
}) initial: '.',
},
{ onCancel }
)
directory = res.path directory = res.path
} }
if (!transform) { if (!transform) {
const res = await prompts({ const res = await prompts(
type: 'select', {
name: 'transformer', type: 'select',
message: 'Which transform would you like to apply?', name: 'transformer',
choices: TRANSFORMER_INQUIRER_CHOICES, message: 'Which transform would you like to apply?',
}) choices: TRANSFORMER_INQUIRER_CHOICES,
},
{ onCancel }
)
transformer = res.transformer transformer = res.transformer
} }
......
...@@ -7,6 +7,7 @@ import chalk from 'chalk' ...@@ -7,6 +7,7 @@ import chalk from 'chalk'
import { availableCodemods } from '../lib/codemods' import { availableCodemods } from '../lib/codemods'
import { getPkgManager, installPackages } from '../lib/handle-package' import { getPkgManager, installPackages } from '../lib/handle-package'
import { runTransform } from './transform' import { runTransform } from './transform'
import { onCancel } from '../lib/utils'
type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun' type PackageManager = 'pnpm' | 'npm' | 'yarn' | 'bun'
...@@ -162,11 +163,7 @@ async function suggestTurbopack(packageJson: any): Promise<void> { ...@@ -162,11 +163,7 @@ async function suggestTurbopack(packageJson: any): Promise<void> {
message: 'Turbopack is now the stable default for dev mode. Enable it?', message: 'Turbopack is now the stable default for dev mode. Enable it?',
initial: true, initial: true,
}, },
{ { onCancel }
onCancel: () => {
process.exit(0)
},
}
) )
if (!responseTurbopack.enable) { if (!responseTurbopack.enable) {
...@@ -181,12 +178,15 @@ async function suggestTurbopack(packageJson: any): Promise<void> { ...@@ -181,12 +178,15 @@ async function suggestTurbopack(packageJson: any): Promise<void> {
return return
} }
const responseCustomDevScript = await prompts({ const responseCustomDevScript = await prompts(
type: 'text', {
name: 'customDevScript', type: 'text',
message: 'Please add `--turbo` to your dev command:', name: 'customDevScript',
initial: devScript, message: 'Please add `--turbo` to your dev command:',
}) initial: devScript,
},
{ onCancel }
)
packageJson.scripts['dev'] = packageJson.scripts['dev'] =
responseCustomDevScript.customDevScript || devScript responseCustomDevScript.customDevScript || devScript
...@@ -233,11 +233,7 @@ async function suggestCodemods( ...@@ -233,11 +233,7 @@ async function suggestCodemods(
} }
}), }),
}, },
{ { onCancel }
onCancel: () => {
process.exit(0)
},
}
) )
return codemods return codemods
......
...@@ -31,6 +31,10 @@ export function checkGitStatus(force) { ...@@ -31,6 +31,10 @@ export function checkGitStatus(force) {
} }
} }
export function onCancel() {
process.exit(1)
}
export const TRANSFORMER_INQUIRER_CHOICES = [ export const TRANSFORMER_INQUIRER_CHOICES = [
{ {
title: title:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment