commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

CommitLint with Yarn v2 (Plug'n'play)

Open loctran016 opened this issue 4 years ago • 16 comments
trafficstars

Expected Behavior

In the yarn v1 and yarn v2 (with nodeLinker: node_modules), commitlint work perfectly

Current Behavior

It doesn't work at all. I've tried these command in git-hook (husky):

  • npx --no-install commitlint --edit "$1"
  • yarn --no-install commitlint --edit "$1"
  • yarn run --no-install commitlint --edit "$1"

Here is the pictures of this problem: Screen Shot 2021-06-07 at 12 33 55

Screen Shot 2021-06-07 at 12 34 31

Screen Shot 2021-06-07 at 12 34 51

Affected packages

  • [x] cli
  • [ ] core
  • [ ] prompt
  • [ ] config-angular

Steps to Reproduce (for bugs)

Link for my repo (bypass git hook)

  1. yarn init && yarn set version berry
  2. yarn add -D @commitlint/config-conventional @commitlint/cli husky
  3. yarn husky install
  4. echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
  5. npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
  6. Commit change

Context

Your Environment

Mac OS X 10.11.6 El Captain

Executable Version
commitlint --version bash: commitlint: command not found
yarn run commitlint --version @commitlint/[email protected] (Need yarn run, see here
git --version git version 2.29.2
node --version v14.15.3

loctran016 avatar Jun 07 '21 09:06 loctran016

Tbh I think we don't support yarn 2 at the moment.
Probably should mention this in the docs.
Happy for a PR.

escapedcat avatar Jun 07 '21 09:06 escapedcat

Tbh I think we don't support yarn 2 at the moment. Probably should mention this in the docs. Happy for a PR.

I've created it here: #2638

loctran016 avatar Jun 07 '21 11:06 loctran016

I've just tried in a fresh Yarn 2 (PNP) monorepo project and it works.

yarn --version
2.4.2

yarn run commitlint --edit "$1"

plus- avatar Jun 22 '21 16:06 plus-

Do you mind sharing your monorepo?

loctran016 avatar Jun 22 '21 17:06 loctran016

sure, here is a trimmed copy: https://github.com/plus-/yarn-commitlint-sample

plus- avatar Jun 22 '21 17:06 plus-

@loctran016 do we need to udpate the docs in a way?

escapedcat avatar Jun 28 '21 01:06 escapedcat

Context for anyone that stumbles upon this: If you're using Plug n Play, you'll want to go .husky/commit-msg and update the npx command to be the yarn run command, as listed here: https://github.com/conventional-changelog/commitlint/issues/2637#issuecomment-866118830

It essentially works, but the current documentation doesn't fully account for it.

silouanwright avatar Dec 03 '21 17:12 silouanwright

@reywright thanks for your comment! Wanna create a PR to fix the docs?

escapedcat avatar Dec 04 '21 05:12 escapedcat

With yarn ~v3~ v2 (3.2.1), I'm running into an issue when amending commits -- it seems the last commit message is being checked, rather than the new amending message.

Here's an example:

❯ yarn -v
3.2.1


❯ touch .temp && git add .temp


❯ git commit -m "build: add .temp"
.husky/pre-commit

[build/wip d55d5ec] build: add .temp
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 .temp


❯ git commit --amend -m "nonsense: blah"
.husky/pre-commit

[build/wip 87555c4] nonsense: blah
 Date: Thu May 26 06:03:06 2022 -0400
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 .temp


❯ git commit --amend -m "build: add .temp"
.husky/pre-commit

⧗   input: nonsense: blah
✖   type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum]

✖   found 1 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

husky - pre-commit hook exited with code 1 (error)

has anyone else run into this issue?


Your Environment

MacOS Monterey 12.4 (21F79)

Executable Version
commitlint --version zsh: commitlint: command not found
yarn run commitlint --version @commitlint/[email protected]
git --version git version 2.36.1
node --version v17.3.1

sbolel avatar May 26 '22 10:05 sbolel

@sbolel is v3 very different from v2 (plug 'n play)?
If yes, wanna create a new issue for yarn v3? Might be worth to tackle this separately? I'm not too familiar with v3.

escapedcat avatar May 26 '22 10:05 escapedcat

@escapedcat sorry, yarn 3.2.1 is actually still "yarn v2"

https://stackoverflow.com/a/69089979/1526037

sbolel avatar May 26 '22 10:05 sbolel