|
| 1 | +# @modulify/conventional-bump |
| 2 | + |
| 3 | +Semantic-release helper that analyzes conventional commits and recommends the next version (major/minor/patch) |
| 4 | +based on your git history. |
| 5 | + |
| 6 | +- Repository: https://github.com/modulify/conventional |
| 7 | +- Spec: https://www.conventionalcommits.org/en/v1.0.0/ |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +- npm: `npm i @modulify/conventional-bump` |
| 12 | +- yarn: `yarn add @modulify/conventional-bump` |
| 13 | +- pnpm: `pnpm add @modulify/conventional-bump` |
| 14 | + |
| 15 | +## Quick start |
| 16 | + |
| 17 | +``` |
| 18 | +import { ReleaseAdvisor } from '@modulify/conventional-bump' |
| 19 | +
|
| 20 | +const advisor = new ReleaseAdvisor() |
| 21 | +const recommendation = await advisor.advise() |
| 22 | +
|
| 23 | +if (recommendation) { |
| 24 | + console.log(recommendation.type) // 'major' | 'minor' | 'patch' |
| 25 | + console.log(recommendation.reason) // human–readable explanation |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +## Public API |
| 30 | + |
| 31 | +### Types |
| 32 | + |
| 33 | +- `type ReleaseType = 'major' | 'minor' | 'patch'` |
| 34 | +- `type ReleaseRecommendation = { type: ReleaseType; reason: string }` |
| 35 | +- `type CommitType = { type: string; section: string; hidden?: boolean }` |
| 36 | + |
| 37 | +### ReleaseAdvisor |
| 38 | + |
| 39 | +Creates an analyzer that reads commits from git and recommends the next semantic version. |
| 40 | + |
| 41 | +Constructor: |
| 42 | + |
| 43 | +``` |
| 44 | +new ReleaseAdvisor(options?: { |
| 45 | + cwd?: string; // Working directory for git commands |
| 46 | + git?: Client; // Custom @modulify/conventional-git client (for tests) |
| 47 | + parse?: ParseOptions; // Conventional commit parser options (@modulify/conventional-git) |
| 48 | + types?: CommitType[]; // Custom type-to-section mapping |
| 49 | +}) |
| 50 | +``` |
| 51 | + |
| 52 | +Method: |
| 53 | + |
| 54 | +``` |
| 55 | +advise(options?: { |
| 56 | + ignore?: (commit: Commit) => boolean; // Skip specific commits |
| 57 | + ignoreReverted?: boolean; // Ignore commits that were later reverted (default: true) |
| 58 | + preMajor?: boolean; // If true, downgrade major→minor and minor→patch for <1.0.0 |
| 59 | + strict?: boolean; // If true, return null when there are no meaningful changes |
| 60 | +}): Promise<ReleaseRecommendation | null> |
| 61 | +``` |
| 62 | + |
| 63 | +Behavior highlights: |
| 64 | +- Breaking changes ("!" or notes) lead to `major` unless `preMajor` is enabled. |
| 65 | +- New features (`feat`/`feature`) lead to `minor`. |
| 66 | +- Otherwise, `patch` is recommended when there are other visible changes; with `strict: true` and no changes, returns `null`. |
| 67 | +- With `ignoreReverted: true` the advisor cancels out commits that were reverted later, including revert-of-revert chains. |
| 68 | + |
| 69 | +## Example: pre-1.0.0 workflow |
| 70 | + |
| 71 | +``` |
| 72 | +const advisor = new ReleaseAdvisor() |
| 73 | +const next = await advisor.advise({ preMajor: true }) |
| 74 | +console.log(next?.type) // 'minor' or 'patch' for <1.0.0 projects |
| 75 | +``` |
| 76 | + |
| 77 | +## Example: strict mode |
| 78 | + |
| 79 | +``` |
| 80 | +const next = await advisor.advise({ strict: true }) |
| 81 | +if (!next) { |
| 82 | + console.log('No release-worthy changes since last tag') |
| 83 | +} |
| 84 | +``` |
0 commit comments