question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

commitlint does not find plugin when a relative path is provided

See original GitHub issue

Expected Behavior

Currently, it seems that plugins can only be resolved if they’re an npm package inside of the node_modules folder (node resolution logic). If I try to load a plugin using a relative path, I get this error:

Error: Failed to load plugin ./plugins/my-custom-plugin.js: Cannot find module 'commitlint-plugin-./plugins/my-custom-plugin.js'

Relative paths are supported for the extends and parserPreset keys, so making this work would align that behavior with plugins too.

Current Behavior

I would love to be able to write this and just have it work.

{
  plugins: ['./dir/my-custom-plugin.js'],
  ...
}

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

Looking at how the parserPreset key is being loaded, it seems like it’s just a matter of using resolveFrom before requireing the plugin.

Context

I basically want to have a small custom rule in a single file, but it seems like a hassle to either handle two separate packages or set up lerna or something.

Your Environment

Executable Version
commitlint --version 8.2.0
git --version git version 2.23.0
node --version v12.10.0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
armano2commented, Jan 11, 2021

Ah thanks for pointing this out. I think this creates two bodies of work for us:

  1. resolve from the current config file for plugin paths starting with ./
  2. do not prefix for paths starting with ./ or /

thats not fully true, we should support also windows absolute paths eg. C:\DEV\....

0reactions
armano2commented, Jan 16, 2021

Currently there is a way to load local plugins by simply using require’ing it

// commitlint.config.js
{
  plugins: [require('./dir/my-custom-plugin.js')],
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I get lint-staged working with Husky version 6
Based on this husky github issue, just do these steps to make it work(we did it and it is working ... Finally, add...
Read more >
babel-plugin-module-resolver-tsconfig - npm package - Snyk
By trying to get the babel config file path from CLI if provided. Otherwise the calling module (babel config file). If no config...
Read more >
commitlint - Visual Studio Marketplace
config.file. Path to a commitlint configuration file. Relative paths are resolved based on the workspace root. Leave blank to auto-detect.
Read more >
Commitizen - GitHub Pages
If your repo is Commitizen friendly: Simply use git cz or just cz instead of git commit when committing. You can also use...
Read more >
Options - Stylelint
Use this option if you don't want Stylelint to search for a configuration file. The path should be either absolute or relative to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found