@neosjs/conventional-changelog-neosjs
遵循 Conventional Commits 规范的 conventional-changelog 预设(preset)。基于提交类型将变更分组到带 emoji 的章节(✨ Features、🐛 Bug Fixes 等),并按约定计算版本提升级别:BREAKING CHANGE 提升大版本、feat 提升小版本。
环境要求
Node.js >= 18。
安装
sh
pnpm add -D @neosjs/conventional-changelog-neosjssh
npm i -D @neosjs/conventional-changelog-neosjssh
yarn add -D @neosjs/conventional-changelog-neosjs快速上手
作为 conventional-changelog 预设使用
配合 conventional-changelog CLI 生成变更日志,用 -p 指定本包完整包名作为预设:
sh
npx conventional-changelog-cli -p @neosjs/conventional-changelog-neosjs -i CHANGELOG.md -s编程式使用
包的默认导出是 createPreset(config) 异步工厂函数,返回包含 commits、parser、writer、whatBump 的预设对象:
js
import neosPreset from '@neosjs/conventional-changelog-neosjs'
const preset = await neosPreset({
// 忽略指定提交
ignoreCommits: [/^chore/],
// 自定义提交类型与章节(见下表默认值)
// types: [...],
// 0.x 阶段:BREAKING CHANGE / feat 不再提升大版本
// preMajor: true
})同时具名导出 DEFAULT_COMMIT_TYPES(默认提交类型表)。
默认提交类型
| type | CHANGELOG 章节 | 是否显示 |
|---|---|---|
feat / feature | ✨ Features | 显示 |
fix | 🐛 Bug Fixes | 显示 |
perf | 🚀 Performance Improvements | 显示 |
revert | 🗑 Reverts | 显示 |
docs | 📚 Documentation | 显示 |
style | 🎨 Styles | 显示 |
chore | ♻️ Miscellaneous Chores | 显示 |
build | 🛠 Build System | 显示 |
refactor | Code Refactoring | 隐藏 |
test | Tests | 隐藏 |
ci | Continuous Integration | 隐藏 |
解析与版本提升规则
- 提交头按
type(scope)!: subject解析,noteKeywords为BREAKING CHANGE/BREAKING-CHANGE,issue 前缀默认#(可通过issuePrefixes配置); - 提交信息含
release-as: x.y.z时可覆盖版本; - 版本提升(whatBump):出现
BREAKING CHANGE或!标记为大版本(level 0),存在feat/feature为小版本(level 1),其余为补丁(level 2);preMajor: true时 level 上调一档(0.x 阶段防止误升 major); - 写入 CHANGELOG 的链接格式(
commitUrlFormat、compareUrlFormat、issueUrlFormat、userUrlFormat)均可通过配置覆盖。