Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tal-rofe opened this issue Apr 23, 2022 · 1 comment · Fixed by #927
Closed

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

tal-rofe opened this issue Apr 23, 2022 · 1 comment · Fixed by #927
Labels

Comments

@tal-rofe
Copy link
Contributor

tal-rofe commented Apr 23, 2022

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

LinusU pushed a commit that referenced this issue Apr 25, 2022
…"Function"s (#927)

current behavior is the utility tries to match only "Function" and therefore "AsyncFunction" will be
considered bad and error will be thrown

fix #926
@github-actions
Copy link

🎉 This issue has been resolved in version 4.2.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

tal-rofe pushed a commit to tal-rofe/cz-vinyl that referenced this issue Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant