fix(packages): fix ERR_USE_AFTER_CLOSE error when pressing Ctrl+C during commit

This commit is contained in:
Azir-11
2026-05-16 16:09:37 +08:00
committed by Soybean
parent 7b809c09b4
commit eba4950428

View File

@@ -42,7 +42,18 @@ export async function gitCommit(lang: Lang = 'en-us') {
message: `${value.padEnd(30)} (${msg})` message: `${value.padEnd(30)} (${msg})`
})); }));
const result = await prompt<PromptObject>([ // 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<PromptObject>([
{ {
name: 'types', name: 'types',
type: 'select', type: 'select',
@@ -61,6 +72,11 @@ export async function gitCommit(lang: Lang = 'en-us') {
message: gitCommitMessages.description message: gitCommitMessages.description
} }
]); ]);
} catch {
process.exit(0);
} finally {
process.off('uncaughtException', errorHandler);
}
const breaking = result.description.startsWith('!') ? '!' : ''; const breaking = result.description.startsWith('!') ? '!' : '';