// Conventional Commits lint (prek commit-msg stage): reject a commit whose // header is not a Conventional Commit. Read-only — version bumping happens at // release time (scripts/version-bump.mjs), not per commit, so parallel // worktrees stop contending on package.json and the manifest. import { readFileSync } from 'node:fs' import { GIT_SHAPES, HEADER, TYPES } from './conventional.mjs' const SCISSORS = '# ------------------------ >8 ------------------------' const msgFile = process.argv[2] if (!msgFile) { console.error('usage: lint-commit-msg.mjs ') process.exit(2) } // Keep the message above the scissors line (git commit -v appends the diff // below one) and drop comment lines before looking for the header. const raw = readFileSync(msgFile, 'utf8') const cut = raw.indexOf(SCISSORS) const lines = (cut === -1 ? raw : raw.slice(0, cut)) .split('\n') .filter((line) => !line.startsWith('#')) const header = lines.find((line) => line.trim() !== '') ?? '' if (GIT_SHAPES.test(header)) process.exit(0) if (!HEADER.test(header)) { console.error(`commit-lint: not a Conventional Commit header: "${header}"`) console.error(`commit-lint: expected "()!?: " with a type in: ${TYPES.join(', ')}`) process.exit(1) }