Skip to content

Commit 34714dc

Browse files
committed
fix: abort on ctrl-c at suggestion prompts
1 parent 0da979a commit 34714dc

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

packages/nuxt-cli/src/main.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async function warnUnknownFlags(command: string, rawArgs: string[]): Promise<voi
129129
return
130130
}
131131

132-
const { confirm, isCancel } = await import('@clack/prompts')
132+
const { cancel, confirm, isCancel } = await import('@clack/prompts')
133133
const { restoreRawMode, withDirectStdout } = await import('./utils/console')
134134
for (const { flag, suggestion } of suggestions) {
135135
if (!suggestion) {
@@ -144,7 +144,13 @@ async function warnUnknownFlags(command: string, rawArgs: string[]): Promise<voi
144144
logger.warn(`Unknown option ${styleText('cyan', flag)}.`)
145145
const answer = await withDirectStdout(() => confirm({ message: `Use ${styleText('cyan', replacement)} instead?`, initialValue: true }))
146146
restoreRawMode()
147-
if (!isCancel(answer) && answer) {
147+
// Ctrl-C at the prompt must abort, not fall through to running the command
148+
// with the flag the user was told is unknown.
149+
if (isCancel(answer)) {
150+
cancel('Aborted.')
151+
process.exit(130)
152+
}
153+
if (answer) {
148154
replaceFlag(rawArgs, flag, replacement)
149155
}
150156
}
@@ -178,7 +184,11 @@ async function reportUnknownCommand(command: string, rawArgs: string[]): Promise
178184
const answer = await withDirectStdout(() => confirm({ message: `Run ${styleText('cyan', `nuxt ${suggestion}`)} instead?`, initialValue: true }))
179185
restoreRawMode()
180186

181-
if (!isCancel(answer) && answer) {
187+
if (isCancel(answer)) {
188+
process.exit(130)
189+
}
190+
191+
if (answer) {
182192
const index = rawArgs.indexOf(command)
183193
const argv = index === -1 ? rawArgs : rawArgs.toSpliced(index, 1)
184194
setCurrentCommand(suggestion)

0 commit comments

Comments
 (0)