From 6f8575a7c64b28e198959c7e1c98a111f5ecfead Mon Sep 17 00:00:00 2001 From: escapedcat Date: Wed, 29 Sep 2021 12:53:53 +0800 Subject: [PATCH] fix: integrate review feedback --- @commitlint/prompt/src/index.ts | 16 ++++------------ .../prompt/src/inquirer/InputCustomPrompt.ts | 6 +++--- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/@commitlint/prompt/src/index.ts b/@commitlint/prompt/src/index.ts index ce0ef977242..ca85678b1a4 100644 --- a/@commitlint/prompt/src/index.ts +++ b/@commitlint/prompt/src/index.ts @@ -3,16 +3,8 @@ import {input} from './input'; type Commit = (input: string) => void; -/** - * Entry point for commitizen - * @param cz inquirer instance passed by commitizen - * @param commit callback to execute with complete commit message - * @return {void} - */ -export async function prompter( - cz: typeof inquirer, - commit: Commit -): Promise { - const message = await input(cz.prompt); - commit(message); +export function prompter(cz: typeof inquirer, commit: Commit): void { + input(cz.prompt).then((message) => { + commit(message); + }); } diff --git a/@commitlint/prompt/src/inquirer/InputCustomPrompt.ts b/@commitlint/prompt/src/inquirer/InputCustomPrompt.ts index 779f2b1db1e..036bb78cc3b 100644 --- a/@commitlint/prompt/src/inquirer/InputCustomPrompt.ts +++ b/@commitlint/prompt/src/inquirer/InputCustomPrompt.ts @@ -1,10 +1,9 @@ /// -import {Interface as ReadlineInterface, Key} from 'readline'; - import chalk from 'chalk'; import inquirer from 'inquirer'; import InputPrompt from 'inquirer/lib/prompts/input'; import observe from 'inquirer/lib/utils/events'; +import {Interface as ReadlineInterface, Key} from 'readline'; import type {Subscription} from 'rxjs/internal/Subscription'; import Answers = inquirer.Answers; @@ -86,7 +85,6 @@ export default class InputCustomPrompt< render(error?: string): void { const answered = this.status === 'answered'; - let bottomContent = ''; let message = this.getQuestion(); const length = this.measureInput(this.rl.line); @@ -96,6 +94,8 @@ export default class InputCustomPrompt< message += this.opt.transformer(this.rl.line, this.answers, {}); } + let bottomContent = ''; + if (error) { bottomContent = chalk.red('>> ') + error; } else if (!answered) {