Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pskfyi/commitlint-config-monorepo
Scope-focused, shareable commitlint config
https://github.com/pskfyi/commitlint-config-monorepo
Last synced: 9 days ago
JSON representation
Scope-focused, shareable commitlint config
- Host: GitHub
- URL: https://github.com/pskfyi/commitlint-config-monorepo
- Owner: pskfyi
- Created: 2019-08-21T19:43:42.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-11T00:53:36.000Z (over 3 years ago)
- Last Synced: 2024-11-01T17:03:22.098Z (14 days ago)
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# commitlint-config-monorepo
A mixin `commitlint` config intended for monorepos. Makes (scope)s required and forces you to be explicit about which (scope) values are allowed. Intended to be used with another config as the base.
## Differences from Conventional Commits
Invalid:
```sh
echo "fix: some message" # a (scope) is required
```Valid:
```sh
echo "fix(docs): Sandbox re-renders as expected"
```## Getting started
> **note:** see [this gist](https://gist.github.com/pskfyi/497fbcc10a0625c716d30995fe336947) for setting up commitlint and husky.
```sh
npm i -D commitlint-config-monorepo
```In `commitlint.config.js` at the root of your repo:
```js
module.exports = {
extends: ["some-other-base-config", "monorepo"],
rules: {
"scope-enum": [
2, // throw error
"always",
[
// This is the only default value baked into the config.
"repo",
],
],
},
};
```### Advanced Configuration
This configuration dynamically reads subdirectories of `/packages` and makes them valid (scope)s. Ex. if you have a subdirectory `/packages/components/` this would make "components" a valid (scope).
```js
const { readdirSync: readDirectory } = require("fs");
const DEFAULT_SCOPES = ["repo"];const packageDirNames = readDirectory("./packages", { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((dir) => dir.name);const scopes = DEFAULT_SCOPES.concat(packageDirNames);
module.exports = {
extends: ["monorepo"],
rules: {
"scope-enum": [2, "always", scopes],
},
};
```## FAQ
### Why not `@commitlint/config-conventional`?
- This minimal ruleset is meant to be added to another config. Use it with `@commitlint/config-conventional` if you want!
- Mandatory scope provides consistency and discourages haphazard commits that would apply to multiple scopes.
### Why not use `@commitlint/config-lerna-scopes` or a similar pattern?
- Being forced to be explicit about which scopes are allowed makes you more aware of them.
- Desire to call out non-package scopes; ex. the config defaults to "repo" as a scope.
- Lerna package names can sometimes be more verbose than is desirable in a commit message; '@my-org-name/projectname-packagename' is a common pattern, and `@commitlint/config-lerna-scopes` will only trim off '@my-org-name'