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

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

Closed
heyqbnk opened this issue Jul 27, 2020 · 9 comments
Closed

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

heyqbnk opened this issue Jul 27, 2020 · 9 comments

Comments

@heyqbnk
Copy link

heyqbnk commented Jul 27, 2020

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

@ThisIsMissEm
Copy link

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) {

@heyqbnk
Copy link
Author

heyqbnk commented Jul 29, 2020

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

@ThisIsMissEm
Copy link

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

@heyqbnk
Copy link
Author

heyqbnk commented Jul 29, 2020

Will try in several days

@ThisIsMissEm
Copy link

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.

@ThisIsMissEm
Copy link

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

@heyqbnk
Copy link
Author

heyqbnk commented Jul 31, 2020

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

@heyqbnk heyqbnk closed this as completed Jul 31, 2020
@cletter7
Copy link

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
Copy link

na-ji commented Mar 10, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants