From eba49504280a2866de3a61c65c3401e1453771ce Mon Sep 17 00:00:00 2001 From: Azir-11 <2075125282@qq.com> Date: Sat, 16 May 2026 16:09:37 +0800 Subject: [PATCH] fix(packages): fix ERR_USE_AFTER_CLOSE error when pressing Ctrl+C during commit --- packages/scripts/src/commands/git-commit.ts | 52 ++++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/packages/scripts/src/commands/git-commit.ts b/packages/scripts/src/commands/git-commit.ts index f63c019f..9b3bdac4 100644 --- a/packages/scripts/src/commands/git-commit.ts +++ b/packages/scripts/src/commands/git-commit.ts @@ -42,25 +42,41 @@ export async function gitCommit(lang: Lang = 'en-us') { message: `${value.padEnd(30)} (${msg})` })); - const result = await prompt([ - { - name: 'types', - type: 'select', - message: gitCommitMessages.types, - choices: typesChoices - }, - { - name: 'scopes', - type: 'select', - message: gitCommitMessages.scopes, - choices: scopesChoices - }, - { - name: 'description', - type: 'text', - message: gitCommitMessages.description + // Suppress ERR_USE_AFTER_CLOSE thrown by enquirer's readline cleanup on Ctrl+C (Node.js v24+) + const errorHandler = (error: NodeJS.ErrnoException) => { + if (error.code === 'ERR_USE_AFTER_CLOSE') { + process.exit(0); } - ]); + }; + process.on('uncaughtException', errorHandler); + + let result: PromptObject; + + try { + result = await prompt([ + { + name: 'types', + type: 'select', + message: gitCommitMessages.types, + choices: typesChoices + }, + { + name: 'scopes', + type: 'select', + message: gitCommitMessages.scopes, + choices: scopesChoices + }, + { + name: 'description', + type: 'text', + message: gitCommitMessages.description + } + ]); + } catch { + process.exit(0); + } finally { + process.off('uncaughtException', errorHandler); + } const breaking = result.description.startsWith('!') ? '!' : '';