commitizen / cz-cli

The commitizen command line utility. #BlackLivesMatter
http://commitizen.github.io/cz-cli/
MIT License
16.58k stars 552 forks source link

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

Closed tal-rofe closed 2 years ago

tal-rofe commented 2 years ago

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

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 4.2.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket: