Conventional Commits preset for conventional-changelog providing automated CHANGELOG generation and version management.
npx @tessl/cli install tessl/npm-conventional-changelog-conventionalcommits@9.1.0A concrete implementation of the Conventional Commits specification for automated CHANGELOG generation and version management. This preset integrates with the conventional-changelog ecosystem to provide standardized changelog generation based on conventional commit messages.
npm install -D conventional-changelog-conventionalcommitsimport createPreset, { DEFAULT_COMMIT_TYPES } from "conventional-changelog-conventionalcommits";For CommonJS environments (via dynamic import):
const { default: createPreset, DEFAULT_COMMIT_TYPES } = await import("conventional-changelog-conventionalcommits");import createPreset from "conventional-changelog-conventionalcommits";
// Create preset with default configuration
const preset = await createPreset();
// Create preset with custom configuration
const customPreset = await createPreset({
types: [
{ type: 'feat', section: 'Features' },
{ type: 'fix', section: 'Bug Fixes' },
{ type: 'docs', section: 'Documentation', hidden: false }
],
issueUrlFormat: 'https://mytracker.com/issues/{{id}}',
issuePrefixes: ['JIRA-', '#']
});
// Use with conventional-changelog CLI
// conventional-changelog -p conventionalcommits -i CHANGELOG.md -s
// Or use as a config file (config.js):
export default createPreset({
issuePrefixes: ['TEST-'],
issueUrlFormat: 'https://myBugTracker.com/{{prefix}}{{id}}'
});The preset system is built around four core components:
Creates a complete preset configuration for conventional-changelog with customizable options for commit parsing, changelog writing, and version bumping.
/**
* Creates a preset configuration for conventional-changelog
* @param config - Optional configuration object
* @returns Promise resolving to preset configuration
*/
function createPreset(config?: PresetConfig): Promise<Preset>;
interface PresetConfig {
/** Array of commit type configurations */
types?: CommitType[];
/** Template for issue link URLs */
issueUrlFormat?: string;
/** Template for commit link URLs */
commitUrlFormat?: string;
/** Template for version comparison URLs */
compareUrlFormat?: string;
/** Template for user profile URLs */
userUrlFormat?: string;
/** Array of issue reference prefixes */
issuePrefixes?: string[];
/** Strict version bump rules */
bumpStrict?: boolean;
/** Scope filtering configuration */
scope?: string | string[];
/** Exclude unscoped commits when filtering */
scopeOnly?: boolean;
/** Pre-major version handling - increments level by 1 when < 2 */
preMajor?: boolean;
/** Regex pattern to ignore specific commits */
ignoreCommits?: RegExp;
}
interface Preset {
/** Commit filtering configuration */
commits: {
ignore?: RegExp;
merges: boolean;
};
/** Parser options for commit message parsing */
parser: ParserOptions;
/** Writer options for changelog generation */
writer: WriterOptions;
/** Version bump determination function */
whatBump: (commits: Commit[]) => BumpResult | null;
}Predefined commit type configurations following conventional commits specification.
/** Default commit type configurations */
const DEFAULT_COMMIT_TYPES: readonly CommitType[];
interface CommitType {
/** Commit type identifier */
type: string;
/** Display section name in changelog */
section: string;
/** Whether to hide from changelog */
hidden?: boolean;
/** Optional scope restriction */
scope?: string;
}The default types include:
feat, feature → Featuresfix → Bug Fixesperf → Performance Improvementsrevert → Revertsdocs → Documentation (hidden)style → Styles (hidden)chore → Miscellaneous Chores (hidden)refactor → Code Refactoring (hidden)test → Tests (hidden)build → Build System (hidden)ci → Continuous Integration (hidden)Defines how commit messages are parsed using regex patterns.
interface ParserOptions {
/** Regex pattern for parsing commit headers: /^(\w*)(?:\((.*)\))?!?: (.*)$/ */
headerPattern: RegExp;
/** Regex pattern for breaking change headers: /^(\w*)(?:\((.*)\))?!: (.*)$/ */
breakingHeaderPattern: RegExp;
/** Array mapping regex groups to properties: ['type', 'scope', 'subject'] */
headerCorrespondence: string[];
/** Keywords identifying breaking change notes: ['BREAKING CHANGE', 'BREAKING-CHANGE'] */
noteKeywords: string[];
/** Regex pattern for parsing revert commits */
revertPattern: RegExp;
/** Array mapping revert regex groups: ['header', 'hash'] */
revertCorrespondence: string[];
/** Array of valid issue reference prefixes (default: ['#']) */
issuePrefixes: string[];
}Controls changelog generation with transformation logic and templates.
interface WriterOptions {
/** Function transforming commit data for changelog */
transform: (commit: Commit, context: Context) => TransformedCommit | undefined;
/** Property to group commits by (always 'type') */
groupBy: string;
/** Function for sorting commit groups by importance */
commitGroupsSort: (a: CommitGroup, b: CommitGroup) => number;
/** Array of properties for sorting commits (['scope', 'subject']) */
commitsSort: string[];
/** Property for sorting note groups ('title') */
noteGroupsSort: string;
/** Function for sorting notes (compare-func) */
notesSort: Function;
/** Main Handlebars template loaded from template.hbs */
mainTemplate: string;
/** Header template partial loaded from header.hbs */
headerPartial: string;
/** Commit template partial loaded from commit.hbs */
commitPartial: string;
/** Footer template partial loaded from footer.hbs */
footerPartial: string;
}
interface TransformedCommit {
/** Breaking change notes */
notes: Note[];
/** Commit type for grouping */
type: string;
/** Commit scope */
scope: string;
/** Short commit hash */
shortHash: string;
/** Processed commit subject */
subject: string;
/** Issue and PR references */
references: Reference[];
}
interface Context {
/** Repository host (e.g., "github.com") */
host: string;
/** Repository owner */
owner: string;
/** Repository name */
repository: string;
/** Current version tag */
version: string;
/** Previous version tag */
previousTag: string;
/** Current version tag */
currentTag: string;
}
interface CommitGroup {
/** Group title */
title: string;
/** Commits in this group */
commits: TransformedCommit[];
}Analyzes commits to determine semantic version increments.
interface BumpResult {
/** Bump level: 0=major, 1=minor, 2=patch */
level: number;
/** Human-readable reason for the bump (e.g., "There are 2 BREAKING CHANGES and 3 features") */
reason: string;
}
interface Commit {
/** Commit type */
type: string;
/** Commit scope */
scope?: string;
/** Commit subject */
subject: string;
/** Breaking change notes */
notes: Note[];
/** Issue references */
references: Reference[];
/** Commit hash */
hash: string;
/** Whether this is a revert commit */
revert?: boolean;
}
interface Note {
/** Note title (usually "BREAKING CHANGE") */
title: string;
/** Note text content */
text: string;
}
interface Reference {
/** Issue prefix (#, JIRA-, etc.) */
prefix: string;
/** Issue identifier */
issue: string;
/** Repository owner */
owner?: string;
/** Repository name */
repository?: string;
}import createPreset from "conventional-changelog-conventionalcommits";
const preset = await createPreset({
issuePrefixes: ['JIRA-', 'TICKET-'],
issueUrlFormat: 'https://company.atlassian.net/browse/{{prefix}}{{id}}'
});const preset = await createPreset({
scope: ['api', 'ui'],
scopeOnly: true // Only include commits with these scopes
});const preset = await createPreset({
types: [
{ type: 'feat', section: 'New Features' },
{ type: 'fix', section: 'Bug Fixes' },
{ type: 'security', section: 'Security Fixes' },
{ type: 'deps', section: 'Dependencies', hidden: true }
]
});const preset = await createPreset({
bumpStrict: true // Only bump for non-hidden types
});The preset supports special "Release-As:" footer syntax for forcing specific version releases:
// Commit message:
// chore: prepare release
//
// Release-As: v2.1.0
// This commit will be included in the changelog regardless of typeUse the preMajor option to handle pre-1.0.0 version bumping:
const preset = await createPreset({
preMajor: true // Converts major bumps to minor, minor to patch for pre-1.0.0
});The preset uses Handlebars templates for changelog generation. Templates support URL placeholders that are automatically populated:
{{host}} - Repository host (e.g., github.com){{owner}} - Repository owner{{repository}} - Repository name{{id}} - Issue/PR number{{prefix}} - Issue prefix (#, JIRA-, etc.){{hash}} - Commit hash{{previousTag}}, {{currentTag}} - Version tagsThe system loads four template files:
template.hbs - Main changelog structureheader.hbs - Version header sectioncommit.hbs - Individual commit formattingfooter.hbs - Version footer sectionThe preset creation process may throw errors in the following cases:
Common patterns for error handling:
try {
const preset = await createPreset(config);
} catch (error) {
console.error('Failed to create preset:', error.message);
}