Skip to content

CommitLint with Yarn v2 (Plug'n'play) #2637

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

Open
1 of 4 tasks
loctran016 opened this issue Jun 7, 2021 · 16 comments
Open
1 of 4 tasks

CommitLint with Yarn v2 (Plug'n'play) #2637

loctran016 opened this issue Jun 7, 2021 · 16 comments

Comments

@loctran016
Copy link
Contributor

loctran016 commented Jun 7, 2021

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

  • 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
@escapedcat
Copy link
Member

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

@loctran016
Copy link
Contributor Author

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

@plus-
Copy link

plus- commented Jun 22, 2021

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"

@loctran016
Copy link
Contributor Author

Do you mind sharing your monorepo?

@plus-
Copy link

plus- commented Jun 22, 2021

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

@escapedcat
Copy link
Member

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

@silouanwright
Copy link

silouanwright commented Dec 3, 2021

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: #2637 (comment)

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

@escapedcat
Copy link
Member

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

@sbolel
Copy link

sbolel commented May 26, 2022

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

@escapedcat

This comment was marked as outdated.

@sbolel
Copy link

sbolel commented May 26, 2022

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

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

@retepz
Copy link

retepz commented Jul 17, 2024

Bump?

@silouanwright
Copy link

@pzimmermaninmo most of my teams have moved back to npm or pnpm. It's already been 3 years. Respectfully, you may want to switch to a different solution.

@escapedcat
Copy link
Member

Bump?

Happy for a PR.

@retepz
Copy link

retepz commented Jul 18, 2024

@pzimmermaninmo most of my teams have moved back to npm or pnpm. It's already been 3 years. Respectfully, you may want to switch to a different solution.

Yeah I get it, I just figured I'd double check since it hasn't been closed or anything like that yet. Reverting to node_modules in yarn does seem to work. I'll probably stick with yarn cause its a balance of most at my company are used to just using yarn vs going to npm.

@covik
Copy link

covik commented Oct 18, 2024

Do we know why Yarn PnP does not work?
I'm guessing; is it due to how it loads configs? Instead of importing the module you just set a string and then commitlint tries to load it by itself? Like eslint used to do before FlatConfig?

Edit:
I actually got it working in a brand new project I started a couple of days ago.
I use Yarn 4.5.0 with PnP and Zero-install.

Proof (terminal)
developer@a7f267b3db37:/workspaces/palettar$ yarn add --dev @commitlint/{cli,config-conventional}
➤ YN0000: · Yarn 4.5.0
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + @commitlint/cli@npm:19.5.0, @babel/code-frame@npm:7.25.7, @babel/helper-validator-identifier@npm:7.25.7, @babel/highlight@npm:7.25.7, @commitlint/config-validator@npm:19.5.0, and 92 more.
➤ YN0000: └ Completed in 1s 317ms
➤ YN0000: ┌ Post-resolution validation
➤ YN0086: │ Some peer dependencies are incorrectly met by dependencies; run yarn explain peer-requirements for details.
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ 97 packages were added to the project (+ 6.71 MiB).
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings in 1s 485ms
developer@a7f267b3db37:/workspaces/palettar$ echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
developer@a7f267b3db37:/workspaces/palettar$ echo "feat: add commitlint support to Palettar" | yarn commitlint
developer@a7f267b3db37:/workspaces/palettar$ echo "feat2: add commitlint support to Palettar" | yarn commitlint
⧗   input: feat2: add commitlint support to Palettar
✖   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
developer@a7f267b3db37:/workspaces/palettar$ yarn add -D husky
➤ YN0000: · Yarn 4.5.0
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + husky@npm:9.1.6
➤ YN0000: └ Completed
➤ YN0000: ┌ Post-resolution validation
➤ YN0086: │ Some peer dependencies are incorrectly met by dependencies; run yarn explain peer-requirements for details.
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0013: │ A package was added to the project (+ 5.06 KiB).
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings in 0s 303ms
developer@a7f267b3db37:/workspaces/palettar$ yarn husky init
developer@a7f267b3db37:/workspaces/palettar$ echo "yarn commitlint --edit \$1" > .husky/commit-msg
developer@a7f267b3db37:/workspaces/palettar$ git add .
developer@a7f267b3db37:/workspaces/palettar$ git commit -m "invalid: test commit message"
⧗   input: invalid: test commit message
✖   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 - commit-msg script failed (code 1)
developer@a7f267b3db37:/workspaces/palettar$ git commit -m "feat: lint commit messages"
[main df227c6] chore: lint commit messages
113 files changed, 977 insertions(+), 1 deletion(-)
create mode 100644 .husky/commit-msg
create mode 100644 .yarn/cache/@babel-code-frame-npm-7.25.7-40a9f53f43-14825c298b.zip
create mode 100644 .yarn/cache/@babel-helper-validator-identifier-npm-7.25.7-1c758f0472-07438e5bf0.zip
create mode 100644 .yarn/cache/@babel-highlight-npm-7.25.7-308b20da71-1f5894fdb0.zip
create mode 100644 .yarn/cache/@commitlint-cli-npm-19.5.0-621eb7a04d-a9fb05f3de.zip
create mode 100644 .yarn/cache/@commitlint-config-conventional-npm-19.5.0-aea781dcb6-a7dc6c0d23.zip
create mode 100644 .yarn/cache/@commitlint-config-validator-npm-19.5.0-3e21395d0a-f04b8c6644.zip
create mode 100644 .yarn/cache/@commitlint-ensure-npm-19.5.0-9a76ded8a5-94955d424d.zip
create mode 100644 .yarn/cache/@commitlint-execute-rule-npm-19.5.0-6d93febb36-966dfc09ae.zip
create mode 100644 .yarn/cache/@commitlint-format-npm-19.5.0-6d6e8dd100-209a3d530d.zip
create mode 100644 .yarn/cache/@commitlint-is-ignored-npm-19.5.0-94bd6a650f-ac74cd00c4.zip
create mode 100644 .yarn/cache/@commitlint-lint-npm-19.5.0-b9fef12eb2-8db4d5ca31.zip
create mode 100644 .yarn/cache/@commitlint-load-npm-19.5.0-5e9dc48946-72fb5f3b22.zip
create mode 100644 .yarn/cache/@commitlint-message-npm-19.5.0-47f494dcec-72b990ba8c.zip
create mode 100644 .yarn/cache/@commitlint-parse-npm-19.5.0-eae307254f-63655cedcf.zip
create mode 100644 .yarn/cache/@commitlint-read-npm-19.5.0-ae9658ad59-c2d6f95893.zip
create mode 100644 .yarn/cache/@commitlint-resolve-extends-npm-19.5.0-b6ceaa62ff-10569a4603.zip
create mode 100644 .yarn/cache/@commitlint-rules-npm-19.5.0-a8b1a50340-8dc5a6e827.zip
create mode 100644 .yarn/cache/@commitlint-to-lines-npm-19.5.0-d7bc1d1dc4-7674b4b688.zip
create mode 100644 .yarn/cache/@commitlint-top-level-npm-19.5.0-2be77f8c8c-8c1edc513c.zip
create mode 100644 .yarn/cache/@commitlint-types-npm-19.5.0-e5342f6a60-f4a93992f4.zip
create mode 100644 .yarn/cache/@types-conventional-commits-parser-npm-5.0.0-cc661330d3-16c748ce01.zip
create mode 100644 .yarn/cache/@types-node-npm-22.7.6-cbb64e0ad4-d4406a63af.zip
create mode 100644 .yarn/cache/JSONStream-npm-1.3.5-1987f2e6dd-0f54694da3.zip
create mode 100644 .yarn/cache/ajv-npm-8.17.1-12ade7edc6-ec3ba10a57.zip
create mode 100644 .yarn/cache/ansi-regex-npm-5.0.1-c963a48615-9a64bb8627.zip
create mode 100644 .yarn/cache/ansi-styles-npm-3.2.1-8cb8107983-ece5a8ef06.zip
create mode 100644 .yarn/cache/ansi-styles-npm-4.3.0-245c7d42c7-895a23929d.zip
create mode 100644 .yarn/cache/argparse-npm-2.0.1-faff7999e6-c5640c2d89.zip
create mode 100644 .yarn/cache/array-ify-npm-1.0.0-e09a371977-75c9c072fa.zip
create mode 100644 .yarn/cache/callsites-npm-3.1.0-268f989910-fff9227740.zip
create mode 100644 .yarn/cache/chalk-npm-2.4.2-3ea16dd91e-e6543f02ec.zip
create mode 100644 .yarn/cache/chalk-npm-5.3.0-d181999efb-8297d436b2.zip
create mode 100644 .yarn/cache/cliui-npm-8.0.1-3b029092cf-4bda0f09c3.zip
create mode 100644 .yarn/cache/color-convert-npm-1.9.3-1fe690075e-5ad3c53494.zip
create mode 100644 .yarn/cache/color-convert-npm-2.0.1-79730e935b-37e1150172.zip
create mode 100644 .yarn/cache/color-name-npm-1.1.3-728b7b5d39-566a3d42cc.zip
create mode 100644 .yarn/cache/color-name-npm-1.1.4-025792b0ea-a1a3f91415.zip
create mode 100644 .yarn/cache/compare-func-npm-2.0.0-9cd7852f23-78bd4dd4ed.zip
create mode 100644 .yarn/cache/conventional-changelog-angular-npm-7.0.0-de5edb79f0-90e73e25e2.zip
create mode 100644 .yarn/cache/conventional-changelog-conventionalcommits-npm-7.0.2-f878f86efe-3cb1eab35e.zip
create mode 100644 .yarn/cache/conventional-commits-parser-npm-5.0.0-8c896e66c7-c9e542f488.zip
create mode 100644 .yarn/cache/cosmiconfig-npm-9.0.0-47d78cf275-1c1703be4f.zip
create mode 100644 .yarn/cache/cosmiconfig-typescript-loader-npm-5.0.0-6462903b70-0eb1a767a5.zip
create mode 100644 .yarn/cache/dargs-npm-8.1.0-39fde97ef5-08cbd1ee4a.zip
create mode 100644 .yarn/cache/dot-prop-npm-5.3.0-7bf6ee1eb8-93f0d343ef.zip
create mode 100644 .yarn/cache/emoji-regex-npm-8.0.0-213764015c-b6053ad399.zip
create mode 100644 .yarn/cache/env-paths-npm-2.2.1-7c7577428c-285325677b.zip
create mode 100644 .yarn/cache/error-ex-npm-1.3.2-5654f80c0f-ba827f8936.zip
create mode 100644 .yarn/cache/escalade-npm-3.2.0-19b50dd48f-ced4dd3a78.zip
create mode 100644 .yarn/cache/escape-string-regexp-npm-1.0.5-3284de402f-a968ad453d.zip
create mode 100644 .yarn/cache/fast-deep-equal-npm-3.1.3-790edcfcf5-40dedc862e.zip
create mode 100644 .yarn/cache/fast-uri-npm-3.0.3-0874072625-4b2c5ce681.zip
create mode 100644 .yarn/cache/find-up-npm-7.0.0-2283627385-e6ee3e6154.zip
create mode 100644 .yarn/cache/get-caller-file-npm-2.0.5-80e8a86305-c6c7b60271.zip
create mode 100644 .yarn/cache/git-raw-commits-npm-4.0.0-60e7e666d1-ab51335d9e.zip
create mode 100644 .yarn/cache/global-directory-npm-4.0.1-1de95382fd-f9cbeef41d.zip
create mode 100644 .yarn/cache/has-flag-npm-3.0.0-16ac11fe05-1c6c83b14b.zip
create mode 100644 .yarn/cache/husky-npm-9.1.6-f05821288d-705673db4a.zip
create mode 100644 .yarn/cache/import-fresh-npm-3.3.0-3e34265ca9-7f882953aa.zip
create mode 100644 .yarn/cache/import-meta-resolve-npm-4.1.0-6e93749986-42f3284b04.zip
create mode 100644 .yarn/cache/ini-npm-4.1.1-01c2cbda7b-7fddc8dfd3.zip
create mode 100644 .yarn/cache/is-arrayish-npm-0.2.1-23927dfb15-e7fb686a73.zip
create mode 100644 .yarn/cache/is-fullwidth-code-point-npm-3.0.0-1ecf4ebee5-bb11d825e0.zip
create mode 100644 .yarn/cache/is-obj-npm-2.0.0-3d95e053f4-85044ed7ba.zip
create mode 100644 .yarn/cache/is-text-path-npm-2.0.0-5c0fb9b2bc-e3c470e126.zip
create mode 100644 .yarn/cache/jiti-npm-1.21.6-0bb76563a3-05b9ed58cd.zip
create mode 100644 .yarn/cache/js-tokens-npm-4.0.0-0ac852e9e2-e248708d37.zip
create mode 100644 .yarn/cache/js-yaml-npm-4.1.0-3606f32312-184a24b4ea.zip
create mode 100644 .yarn/cache/json-parse-even-better-errors-npm-2.3.1-144d62256e-140932564c.zip
create mode 100644 .yarn/cache/json-schema-traverse-npm-1.0.0-fb3684f4f0-71e30015d7.zip
create mode 100644 .yarn/cache/jsonparse-npm-1.3.1-b6fde74828-89bc68080c.zip
create mode 100644 .yarn/cache/lines-and-columns-npm-1.2.4-d6c7cc5799-3da6ee62d4.zip
create mode 100644 .yarn/cache/locate-path-npm-7.2.0-0e1169e19b-139e8a7fe1.zip
create mode 100644 .yarn/cache/lodash.camelcase-npm-4.3.0-bf268e3bf0-fcba15d21a.zip
create mode 100644 .yarn/cache/lodash.isplainobject-npm-4.0.6-d73937742f-afd70b5c45.zip
create mode 100644 .yarn/cache/lodash.kebabcase-npm-4.1.1-89ffca7e1f-da5d8f41db.zip
create mode 100644 .yarn/cache/lodash.merge-npm-4.6.2-77cb4416bf-402fa16a1e.zip
create mode 100644 .yarn/cache/lodash.mergewith-npm-4.6.2-7d2d4201ec-4adbed65ff.zip
create mode 100644 .yarn/cache/lodash.snakecase-npm-4.1.1-b12cdbecb4-f0b3f2497e.zip
create mode 100644 .yarn/cache/lodash.startcase-npm-4.4.0-637aa8cc15-bd82aa87a4.zip
create mode 100644 .yarn/cache/lodash.uniq-npm-4.5.0-7c270dca85-262d400bb0.zip
create mode 100644 .yarn/cache/lodash.upperfirst-npm-4.3.1-e3b7c364ba-435625da4b.zip
create mode 100644 .yarn/cache/meow-npm-12.1.1-bd7858d088-a125ca99a3.zip
create mode 100644 .yarn/cache/minimist-npm-1.2.8-d7af7b1dce-19d3fcdca0.zip
create mode 100644 .yarn/cache/p-limit-npm-4.0.0-5dccf29b67-a56af34a77.zip
create mode 100644 .yarn/cache/p-locate-npm-6.0.0-b6cfb720dc-d72fa2f41a.zip
create mode 100644 .yarn/cache/parent-module-npm-1.0.1-1fae11b095-c63d6e8000.zip
create mode 100644 .yarn/cache/parse-json-npm-5.2.0-00a63b1199-77947f2253.zip
create mode 100644 .yarn/cache/path-exists-npm-5.0.0-0bf403c56c-b170f3060b.zip
create mode 100644 .yarn/cache/picocolors-npm-1.1.1-4fede47cf1-e2e3e8170a.zip
create mode 100644 .yarn/cache/require-directory-npm-2.1.1-8608aee50b-83aa76a7bc.zip
create mode 100644 .yarn/cache/require-from-string-npm-2.0.2-8557e0db12-aaa267e0c5.zip
create mode 100644 .yarn/cache/resolve-from-npm-4.0.0-f758ec21bf-8408eec31a.zip
create mode 100644 .yarn/cache/resolve-from-npm-5.0.0-15c9db4d33-b21cb7f1fb.zip
create mode 100644 .yarn/cache/semver-npm-7.6.3-57e82c14d5-88f33e148b.zip
create mode 100644 .yarn/cache/split2-npm-4.2.0-16aa3883ba-b292beb8ce.zip
create mode 100644 .yarn/cache/string-width-npm-4.2.3-2c27177bae-1e525e92e5.zip
create mode 100644 .yarn/cache/strip-ansi-npm-6.0.1-caddc7cb40-1ae5f212a1.zip
create mode 100644 .yarn/cache/supports-color-npm-5.5.0-183ac537bc-6ae5ff319b.zip
create mode 100644 .yarn/cache/text-extensions-npm-2.4.0-d2843791b9-6790e7ee72.zip
create mode 100644 .yarn/cache/through-npm-2.3.8-df5f72a16e-4b09f37740.zip
create mode 100644 .yarn/cache/tinyexec-npm-0.3.1-13938c6dae-11e7a7c5d8.zip
create mode 100644 .yarn/cache/undici-types-npm-6.19.8-9f12285b7a-078afa5990.zip
create mode 100644 .yarn/cache/unicorn-magic-npm-0.1.0-12d4f6ff8b-e4ed0de05b.zip
create mode 100644 .yarn/cache/wrap-ansi-npm-7.0.0-ad6e1a0554-d15fc12c11.zip
create mode 100644 .yarn/cache/y18n-npm-5.0.8-5f3a0a7e62-4df2842c36.zip
create mode 100644 .yarn/cache/yargs-npm-17.7.2-80b62638e1-ccd7e723e6.zip
create mode 100644 .yarn/cache/yargs-parser-npm-21.1.1-8fdc003314-f84b5e4816.zip
create mode 100644 .yarn/cache/yocto-queue-npm-1.1.1-6bddf81a40-cb287fe5e6.zip
create mode 100644 commitlint.config.js
developer@a7f267b3db37:/workspaces/palettar$

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

No branches or pull requests

7 participants