Commitlint config to enforce packages' name in a workspace as commit scope.
This library takes inspiration from @commitlint/config-lerna-scopes
. Although the mentioned library does a great job on extrapolating scopes from a workspace, it forces to be bound to lerna
even if the project is not actively using it. This means installing lerna
just to respect a peer dependency.
Since yarn
already offers a way to extract the packages involved in a workspace, we can leverage this feature in our favour. Precisely for this goal, this library exists. It lets to be lerna-free
, without having unresolved peer dependencies warnings, while maintaining the ability to extract scopes from the workspace.
yarn install -D commitlint-config-yarn-scopes
Add the following snippet in the commitlint.config.js
file of your project
{
extends: ['yarn-scopes']
}
Optionally, this package exports a function getPackages
that can be used to extract the scopes manually. The usage is the following
const { utils: { getPackages } } = require('commitlint-config-yarn-scopes')
modules.exports = {
...,
'scope-enum': async (context) => [
2,
'always',
[
...(await getPackages(context)),
'other-package-outside-the-workspace',
],
],
}