Skip to content

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

Description

@tal-rofe

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]');

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions