diff --git a/packages/core/src/lib/create-prompt.mts b/packages/core/src/lib/create-prompt.mts index 36b511226..bd8dfc41c 100644 --- a/packages/core/src/lib/create-prompt.mts +++ b/packages/core/src/lib/create-prompt.mts @@ -18,7 +18,7 @@ export function createPrompt(view: ViewFunction) { const prompt: Prompt = (config, context = {}) => { // Default `input` to stdin const { input = process.stdin, signal: outsideSignal } = context; - const { promise, resolve, reject, abort, onFinally } = + const { promise, resolve, reject, onFinally } = CancelablePromise.withResolver(); // Add mute capabilities to the output @@ -39,7 +39,7 @@ export function createPrompt(view: ViewFunction) { if (outsideSignal) { const outsideAbort = () => - abort(new AbortPromptError({ cause: outsideSignal.reason })); + reject(new AbortPromptError({ cause: outsideSignal.reason })); if (outsideSignal.aborted) { outsideAbort(); return promise; @@ -51,7 +51,7 @@ export function createPrompt(view: ViewFunction) { withHooks(rl, (cycle) => { onFinally( onSignalExit((code, signal) => { - abort( + reject( new ExitPromptError(`User force closed the prompt with ${code} ${signal}`), ); }), @@ -102,7 +102,7 @@ export function createPrompt(view: ViewFunction) { effectScheduler.run(); } catch (error: unknown) { - abort(error); + reject(error); } }); }); diff --git a/packages/type/src/inquirer.mts b/packages/type/src/inquirer.mts index 838792c2c..c2976e2a8 100644 --- a/packages/type/src/inquirer.mts +++ b/packages/type/src/inquirer.mts @@ -11,7 +11,6 @@ export class CancelablePromise extends Promise { abortController.signal.addEventListener('abort', () => reject(signal.reason), { once: true, }); - const abort = (error: unknown) => abortController.abort(error); const finallyCallbacks = new Set<() => void>(); const onFinally = (onfinally: () => void) => finallyCallbacks.add(onfinally); @@ -32,7 +31,7 @@ export class CancelablePromise extends Promise { }); }); - promise.cancel = () => abort(new CancelPromptError()); + promise.cancel = () => reject(new CancelPromptError()); return { promise, @@ -40,7 +39,6 @@ export class CancelablePromise extends Promise { reject: reject!, signal: abortController.signal, onFinally, - abort, }; } }