As title.
i got Could not find prompter method in the provided adapter module: @commitlint/prompt
Maybe this code as below at commitizen/adapter.js, got a error:
function getPrompter(adapterPath) {
cov_8emx7ww64.f[7]++;
// Resolve the adapter path
let resolvedAdapterPath = (cov_8emx7ww64.s[25]++, resolveAdapterPath(adapterPath)); // Load the adapter
let adapter = (cov_8emx7ww64.s[26]++, require(resolvedAdapterPath));
/* istanbul ignore next */
if (adapter && adapter.prompter && (0, _util.isFunction)(adapter.prompter)) {
return adapter.prompter;
} else if (adapter && adapter.default && adapter.default.prompter && (0, _util.isFunction)(adapter.default.prompter)) {
return adapter.default.prompter;
} else {
throw new Error(`Could not find prompter method in the provided adapter module: ${adapterPath}`);
}
}
module.exports = {
extends: ['@commitlint/config-conventional']
}
and package.json
{
"scripts": {
"commit": "git-cz"
},
"config": {
"commitizen": {
"path": "@commitlint/prompt"
}
}
}
| Executable | Version |
| ---------------------: | :------ |
| commitlint --version | 12.0.1 |
| git --version | 2.25.1 |
| node --version | 12.16.1 |
| commitizen --version | 4.2.3 |
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]';
}
}
```js
Object.prototype.toString.call(async function () {}) // [object AsyncFunction]
Object.prototype.toString.call(function () {}) // [object Function]
this implementation is not correct as it should be
```js
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 transformationfunction 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.prompteris aasync functionbutisFunctionreturns 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.
Most helpful comment
@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
https://github.com/commitizen/cz-cli/blob/ba7eeb67c4d3347cc2369ff6538d9d97761cedc8/src/commitizen/adapter.js#L150-L153
adapter.prompteris aasync functionbutisFunctionreturns false```js
Object.prototype.toString.call(async function () {}) // [object AsyncFunction]
Object.prototype.toString.call(function () {}) // [object Function]
this issue should be reported to commitizen but as "workaround" we could take this
https://github.com/conventional-changelog/commitlint/blob/6a48e44dbc803bf49b1f9253e650ca1184421914/%40commitlint/prompt/src/index.ts#L14-L17
and replace it with