conventional-changelog / conventional-changelog/commitlint

commitlint does not find plugin when a relative path is provided

Open
#932 7 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
18.7k
Forks
970
Avg merge
7h 33m
Merged PRs (30d)
49

Description

## 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.

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

## Affected packages
* [ ] cli
* [x] core
* [ ] prompt
* [ ] config-angular

## Possible Solution

Looking at how the [parserPreset](https://github.com/conventional-changelog/commitlint/blob/d74b40b18602655968b08ce15b91546009816c0b/%40commitlint/load/src/load.ts#L44-L53) key is being loaded, it seems like it's just a matter of using `resolveFrom` before `require`ing 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 |

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.