CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-conventional-changelog-conventionalcommits

Conventional Commits preset for conventional-changelog providing automated CHANGELOG generation and version management.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Conventional Changelog Conventionalcommits

A 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.

Package Information

  • Package Name: conventional-changelog-conventionalcommits
  • Package Type: npm
  • Language: JavaScript/Node.js (ESM-only)
  • Installation: npm install -D conventional-changelog-conventionalcommits

Core Imports

import 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");

Basic Usage

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}}'
});

Architecture

The preset system is built around four core components:

  • Parser Configuration: Defines how commit messages are parsed using regex patterns for headers, breaking changes, and reverts
  • Writer Configuration: Controls changelog generation with Handlebars templates, commit transformation, and URL formatting
  • Version Bump Logic: Analyzes commits to determine semantic version increments (major, minor, patch)
  • Commit Type System: Categorizes commits into sections with configurable visibility and grouping

Capabilities

Preset Creation

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;
}

Default Commit Types

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 → Features
  • fix → Bug Fixes
  • perf → Performance Improvements
  • revert → Reverts
  • docs → Documentation (hidden)
  • style → Styles (hidden)
  • chore → Miscellaneous Chores (hidden)
  • refactor → Code Refactoring (hidden)
  • test → Tests (hidden)
  • build → Build System (hidden)
  • ci → Continuous Integration (hidden)

Parser Configuration

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[];
}

Writer Configuration

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[];
}

Version Bump Determination

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;
}

Usage Examples

Custom Issue Tracking

import createPreset from "conventional-changelog-conventionalcommits";

const preset = await createPreset({
  issuePrefixes: ['JIRA-', 'TICKET-'],
  issueUrlFormat: 'https://company.atlassian.net/browse/{{prefix}}{{id}}'
});

Scope Filtering

const preset = await createPreset({
  scope: ['api', 'ui'],
  scopeOnly: true // Only include commits with these scopes
});

Custom Commit Types

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 }
  ]
});

Strict Version Bumping

const preset = await createPreset({
  bumpStrict: true // Only bump for non-hidden types
});

Release-As Footer Support

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 type

Pre-Major Version Handling

Use 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
});

Template System

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 tags

The system loads four template files:

  • template.hbs - Main changelog structure
  • header.hbs - Version header section
  • commit.hbs - Individual commit formatting
  • footer.hbs - Version footer section

Error Handling

The preset creation process may throw errors in the following cases:

  • Template Loading Errors: If Handlebars template files cannot be read from the file system
  • Configuration Errors: If invalid configuration options are provided
  • Parser Errors: If commit messages cannot be parsed with the configured patterns

Common patterns for error handling:

try {
  const preset = await createPreset(config);
} catch (error) {
  console.error('Failed to create preset:', error.message);
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/conventional-changelog-conventionalcommits@9.1.x
Publish Source
CLI
Badge
tessl/npm-conventional-changelog-conventionalcommits badge