Closed Liaoct closed 2 years ago
Hey, did this use to work with an older version or is this a new issue related to v12?
I can confirm it works with v11
@escapedcat @a-pavlov-parc i did some digging and there seem to be an issue in commitizen
v11: code was transpiled with babel and async functions where converted to functions with regenerator v12: code is compiled with typescript and there is no need anymore to do this transformation
function getPrompter (adapterPath) {
// Resolve the adapter path
let resolvedAdapterPath = resolveAdapterPath(adapterPath);
// Load the adapter
let adapter = require(resolvedAdapterPath);
/* istanbul ignore next */
if (adapter && adapter.prompter && isFunction(adapter.prompter)) {
return adapter.prompter;
} else if (adapter && adapter.default && adapter.default.prompter && isFunction(adapter.default.prompter)) {
return adapter.default.prompter;
} else {
throw new Error(`Could not find prompter method in the provided adapter module: ${adapterPath}`);
}
}
adapter.prompter
is a async function
but isFunction
returns false
function isFunction (functionToCheck) {
if (typeof functionToCheck === "undefined")
{
return false;
} else if (functionToCheck === null) {
return false;
} else {
var getType = {};
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
}
}
Object.prototype.toString.call(async function () {}) // [object AsyncFunction]
Object.prototype.toString.call(function () {}) // [object Function]
this implementation is not correct as it should be
function isFunction (functionToCheck) {
return typeof functionToCheck === 'function'
}
this issue should be reported to commitizen but as "workaround" we could take this
and replace it with
export function prompter(_: unknown, commit: Commit): void {
input(vorpal).then((message) => {
commit(message);
});
}
@escapedcat @a-pavlov-parc i did some digging and there seem to be an issue in commitizen
v11: code was transpiled with babel and async functions where converted to functions with regenerator v12: code is compiled with typescript and there is no need anymore to do this transformation
function getPrompter (adapterPath) { // Resolve the adapter path let resolvedAdapterPath = resolveAdapterPath(adapterPath); // Load the adapter let adapter = require(resolvedAdapterPath); /* istanbul ignore next */ if (adapter && adapter.prompter && isFunction(adapter.prompter)) { return adapter.prompter; } else if (adapter && adapter.default && adapter.default.prompter && isFunction(adapter.default.prompter)) { return adapter.default.prompter; } else { throw new Error(`Could not find prompter method in the provided adapter module: ${adapterPath}`); } }
adapter.prompter
is aasync function
butisFunction
returns falsefunction isFunction (functionToCheck) { if (typeof functionToCheck === "undefined") { return false; } else if (functionToCheck === null) { return false; } else { var getType = {}; return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]'; } }
Object.prototype.toString.call(async function () {}) // [object AsyncFunction] Object.prototype.toString.call(function () {}) // [object Function]
this implementation is not correct as it should be
function isFunction (functionToCheck) { return typeof functionToCheck === 'function' }
this issue should be reported to commitizen but as "workaround" we could take this
and replace it with
export function prompter(_: unknown, commit: Commit): void { input(vorpal).then((message) => { commit(message); }); }
@armano2 Thanks for help.
Will this fix to be released in the next version, or users have to modify it by fork and wait for commitizen to fix.
@curly210102 so far this hasn't been changed on our side. Happy if you want create a PR with the workaround here.
If someone opens up an issue at commitizen it would be nice to link it here.
@escapedcat this can be closed as for #2697
Thanks @armano2 , closing
This issue can be reproduced when bundling the application webpack and ts-loader together with tsconfig.json.
I consoled my output:
{ prompter: [AsyncFunction: prompter] }
Could not find prompter method in the provided adapter module: dist/index.js
This happens when I have async prompter.
@tal-rofe would you mind creating a new issue and maybe a repo for reproduction? Thanks
@tal-rofe would you mind creating a new issue and maybe a repo for reproduction? Thanks
Hi, I opened the issue in commitizen
repo page as it is more related with their code
As title.
Expected Behavior
Current Behavior
i got
Could not find prompter method in the provided adapter module: @commitlint/prompt
Affected packages
Possible Solution
Maybe this code as below at
commitizen/adapter.js
, got a error:Steps to Reproduce (for bugs)
and package.json
Context
Your Environment
commitlint --version
git --version
node --version
commitizen --version