commitizen / cz-cli

The commitizen command line utility. #BlackLivesMatter

Home Page:http://commitizen.github.io/cz-cli/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Could not find prompter method in the provided adapter module: dist/index.js"

tal-rofe opened this issue ยท comments

I created my own adapter for commitizen. At first, I built the adapter using TSC.
The problem is that I export an async function:

import { Inquirer } from 'inquirer';
import InquirerAutoComplete from 'inquirer-autocomplete-prompt';
import InquirerMaxLength from 'inquirer-maxlength-input-prompt';
import wrap from 'word-wrap';

import { getConfiguration } from './utils/configuration';
import { formatHeader, formatIssues, formatBreakingChange } from './pipes/commit-format';
import { getQuestions } from './utils/questions';
import { ICommitFunc } from './interfaces/commit';

const prompter = async (cz: Inquirer, commit: ICommitFunc) => {
	cz.prompt.registerPrompt('autocomplete', InquirerAutoComplete);
	cz.prompt.registerPrompt('maxlength-input', InquirerMaxLength);

	const configuration = await getConfiguration();

	const wrapOptions = {
		indent: '',
		trim: true,
		width: configuration.maxCommitLineWidth,
	};

	const questions = await getQuestions(configuration);
	const answers = await cz.prompt(questions);

	commit(
		[
			formatHeader(
				configuration.headerFormat,
				answers.type.type,
				answers.scope,
				answers.type.emoji,
				answers.ticket_id,
				answers.subject,
			),
			wrap(answers.body || '', wrapOptions),
			wrap(formatBreakingChange(answers.breakingBody) || '', wrapOptions),
			formatIssues(answers.issues),
		]
			.filter(Boolean)
			.join('\n\n')
			.trim(),
	);
};

const InqObj = { prompter };

export default InqObj;

But when I try to apply this adapter with commitizen I got the error in the title.
When I transformed my exported function to non-async, but using "().then()" it was resolved

The reason is, when exporting such thing, its type is: [object AsyncFunction]
However, commitizen will emit error.
Because: https://github.com/commitizen/cz-cli/blob/master/src/common/util.js
line 41: return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
This should be:

return functionToCheck && (getType.toString.call(functionToCheck) === '[object Function]' || getType.toString.call(functionToCheck) === '[object AsyncFunction]');

๐ŸŽ‰ This issue has been resolved in version 4.2.5 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€