Skip to content

Commit 7273c3a

Browse files
committed
chore: move commitizen config to commitlint; remove cz-lerna-changelog pkg; skip commit hook on rebase and amend
1 parent 2061319 commit 7273c3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+242
-6441
lines changed

.github/workflows/pr-validation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
run: npm ci
1717
- name: Bootstrap project
1818
run: npm run bootstrap
19-
- name: Lint commit
20-
run: npm run lint:commit
19+
- name: Lint commits
20+
run: npm run lint:commits
2121
- name: Lint code
2222
run: npm run lint:changes
2323
vitest-tests:

.husky/commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
npm run lint:commit
1+
npx --no -- commitlint --edit $1

.husky/pre-push

Lines changed: 0 additions & 1 deletion
This file was deleted.

.husky/prepare-commit-msg

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
exec < /dev/tty && npx cz --hook || true
1+
# Don't run this hook on --amend or rebase
2+
# From https://github.com/commitizen/cz-cli/issues/672#issuecomment-1328123802
3+
#
4+
# Explanation:
5+
# Per the [prepare-commit-msg hook docs](https://git-scm.com/docs/githooks#_prepare_commit_msg),
6+
# the second argument can have these values:
7+
# - Empty: No message supplied
8+
# - "message": Message was supplied via -m or -F
9+
# - "template": Template was supplied via -t or via commit.template git config
10+
# - "merge": Commit is a merge commit or .git/MERGE_MSG file exists
11+
# - "squash": .git/SQUASH_MSG file exists
12+
# - "commit": -c, -C, or --amend was supplied. In this case, the script gets a third argument representing the commit object.
13+
14+
if [ -z "$2" ]; then
15+
exec < /dev/tty && npx cz --hook
16+
fi

commitlint.config.js

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,71 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
25+
const { execSync } = require('child_process')
26+
const fs = require('fs')
27+
const path = require('path')
28+
29+
const ignoredPackages = ['__docs__', '__examples__']
30+
31+
function getChangedPackages() {
32+
try {
33+
const output = execSync('git diff --cached --name-only', {
34+
encoding: 'utf-8'
35+
})
36+
return Array.from(
37+
new Set(
38+
output
39+
.split('\n')
40+
.filter((line) => line.startsWith('packages/'))
41+
.map((line) => line.split('/')[1])
42+
.filter((pkg) => !ignoredPackages.includes(pkg))
43+
)
44+
)
45+
} catch (error) {
46+
console.error(error.message)
47+
return []
48+
}
49+
}
50+
51+
function getAllPackages() {
52+
try {
53+
const packagesDir = path.resolve('packages')
54+
return fs
55+
.readdirSync(packagesDir)
56+
.filter(
57+
(pkg) =>
58+
fs.statSync(path.join(packagesDir, pkg)).isDirectory() &&
59+
!ignoredPackages.includes(pkg)
60+
)
61+
} catch (error) {
62+
console.error(error.message)
63+
return []
64+
}
65+
}
66+
2467
module.exports = {
2568
extends: ['@commitlint/config-conventional'],
2669
parserOpts: {
2770
headerPattern: /^(\w*)\((\w*)\)-(\w*)\s(.*)$/,
2871
headerCorrespondence: ['type', 'scope', 'subject']
2972
},
30-
// see https://commitlint.js.org/#/reference-rules
73+
// https://commitlint.js.org/reference/rules.html
3174
rules: {
32-
'type-enum': [
33-
2,
34-
'always',
35-
[
36-
'WIP',
37-
'feat',
38-
'fix',
39-
'docs',
40-
'chore',
41-
'style',
42-
'refactor',
43-
'test',
44-
'perf',
45-
'revert'
46-
]
47-
],
48-
'type-case': [0],
49-
'header-max-length': [0, 'always', 150] // commit message first field (subject) length
75+
'header-max-length': [2, 'always', 150]
76+
},
77+
78+
// https://cz-git.qbb.sh/config/
79+
prompt: {
80+
enableMultipleScopes: true,
81+
scopeEnumSeparator: ',',
82+
scopes: getAllPackages(),
83+
defaultScope: getChangedPackages(),
84+
skipQuestions: ['footerPrefix', 'confirmCommit'],
85+
// If more than 3 packages are selected display 'many', e.g. `refactor(many): some message`
86+
formatMessageCB: ({ scope, defaultMessage }) =>
87+
scope.split(',').length > 3
88+
? defaultMessage.replace(scope, 'many')
89+
: defaultMessage
5090
}
5191
}

0 commit comments

Comments
 (0)