From 740add740e5496e5c04f6983a84c7ca7f114379a Mon Sep 17 00:00:00 2001 From: "@andatoshiki" Date: Sat, 16 Sep 2023 19:56:33 -0700 Subject: [PATCH] fix(husky): revert usage of node instead of ts-node for running commit message validation feature & switch typescript verfication util to `cjs` due to change in project property type to `module` of overall monorepo --- .husky/commit-msg | 2 +- scripts/verifyCommit.cjs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 scripts/verifyCommit.cjs diff --git a/.husky/commit-msg b/.husky/commit-msg index 23c4c7ca..680fc2b2 100755 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -ts-node scripts/verifyCommit.ts \ No newline at end of file +node scripts/verifyCommit.cjs \ No newline at end of file diff --git a/scripts/verifyCommit.cjs b/scripts/verifyCommit.cjs new file mode 100644 index 00000000..a29c2b77 --- /dev/null +++ b/scripts/verifyCommit.cjs @@ -0,0 +1,17 @@ +const msg = require('fs') + .readFileSync('.git/COMMIT_EDITMSG', 'utf-8') + .trim() + +const commitRE = /^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/ +const mergeRe = /^(Merge pull request|Merge branch)/ +if (!commitRE.test(msg)) { + if(!mergeRe.test(msg)){ + console.log('git commit message does not pass validation') + + console.error(`git commit message format error, use \" title(scope): desc\" as the format`) + process.exit(1) + } + +}else{ + console.log('git commit message validation test passes') +} \ No newline at end of file