commitizen/cz-conventional-changelog

require('@commitlint/load') does not work properly anymore

heyqbnk opened this issue · 9 comments

Since @commitlint/load release v9, this line of code is not working anymore and as a result, no config could be downloaded

https://github.com/commitizen/cz-conventional-changelog/blob/master/index.js#L32

The reason is require('@commitlint/load') now returns {default: func} but not function itself.

Here is my package.json:

{
  "scripts": {
    "commit": "git-cz"
  },
  "devDependencies": {
    "@commitlint/cli": "^9.1.1",
    "@commitlint/config-conventional": "^9.1.1",
    "commitizen": "^4.1.2",
    "conventional-github-releaser": "^3.1.3",
    "cz-conventional-changelog": "^3.2.0",
    "husky": "^4.2.5",
    "lint-staged": "^10.2.2",
    "typescript": "^3.9.2",
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  },
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "src/**/*.ts": [
      "eslint --fix"
    ]
  }
}

It didnt work even if you specify @commitlint packages versions as 8.3.5, or specify @commitilint/load directly to deps with version 8.3.5. It looks like cz-conventional-changelog installs latest version by itself

So would it be better for us to have a peerDependency on commitlint @ 8.3.5? Or should we actually try to support both versions of commitlint?

var commitlintLoad = require('@commitlint/load');

if (typeof commitlintLoad !== 'function' && typeof commitlintLoad.default === 'function'){
  commitlintLoad = commitlintLoad.default
}

return commitlintLoad().then(function(clConfig) {

I think, typecheck is enough for our problem. Not sure, commitlint @ load will change return type in near future, so checking if require returns function or object with field default is enough

I might fix this in a commit on #126, as on that branch we can actually properly test config loading.

Will try in several days

Ah, actually, looks like commitlint 9.0.0 was broken, and the fix was in 9.0.1:

Can you first try with commitlint@9.0.1? I don't know a whole heap about commitlint, but it looks like they've moved from javascript to typescript which seems to be where the issue came in.

I've just tried with commitlint@8.5.3, and @9.0.0, and I'm unable to reproduce this issue; I'm on node.js v12.8.x

Hm. I am now unable to reproduce this issue too. Probably, the problem could be somehow connected with yarn.lock and new version of commitlint. It appeared, when I decided to upgrade all deps and tried to call git-cz and then I saw that commit head length changed. And finally I got into cz-conventional-changelog sources and found that anomaly.

Thank you for your participant @ThisIsMissEm ! Will reopen in case, problem occurs again

The issue still exists for me, when changing this line:

var commitlintLoad = require('@commitlint/load');

to

var commitlintLoad = require('@commitlint/load').default;

it starts working...

na-ji commented

The issue still exists today as you can see in issue #129. Tried with version 8.3, 9.1 and version 12.0 of commitlint, the config is not loaded correctly.