Conventional changelog plugin for release-it that automates changelog generation and semantic version bumping based on conventional commits
npx @tessl/cli install tessl/npm-release-it--conventional-changelog@10.0.0The @release-it/conventional-changelog plugin automates changelog generation and semantic version bumping for release-it. It analyzes conventional commits to determine the appropriate version bump (major, minor, patch) and generates comprehensive changelog files using conventional changelog standards.
npm install --save-dev @release-it/conventional-changelogThis plugin is typically configured in release-it rather than imported directly. However, for programmatic usage or extension:
import ConventionalChangelog from "@release-it/conventional-changelog";For CommonJS environments:
const ConventionalChangelog = require("@release-it/conventional-changelog");This plugin is typically configured in the release-it configuration file:
{
"plugins": {
"@release-it/conventional-changelog": {
"preset": {
"name": "angular"
},
"infile": "CHANGELOG.md"
}
}
}The plugin extends the release-it Plugin base class and integrates with the conventional changelog ecosystem:
Main plugin class that provides conventional changelog functionality for release-it.
class ConventionalChangelog extends Plugin {
/**
* Determines whether to disable the plugin based on options
* @param {Object} options - Plugin configuration options
* @returns {string|null} 'version' if plugin should be disabled, null otherwise
*/
static disablePlugin(options);
/**
* Processes initial plugin options and sets tag prefix
* @param {Object} options - Configuration options
* @param {string} namespace - Plugin namespace
* @returns {Object} Processed options for namespace
*/
getInitialOptions(options, namespace);
/**
* Generates changelog for given version
* @param {string} latestVersion - Latest version string
* @returns {Promise<string>} Generated changelog
*/
async getChangelog(latestVersion);
/**
* Calculates recommended version based on conventional commits
* @param {Object} options - Configuration with increment, latestVersion, isPreRelease, preReleaseId
* @param {string} options.increment - Increment type (major, minor, patch)
* @param {string} options.latestVersion - Latest version string
* @param {boolean} options.isPreRelease - Whether this is a pre-release
* @param {string} options.preReleaseId - Pre-release identifier
* @returns {Promise<string|null>} Recommended version or null
*/
async getRecommendedVersion({ increment, latestVersion, isPreRelease, preReleaseId });
/**
* Creates a stream for generating changelog content
* @param {Object} rawOptions - Optional raw options for changelog generation (defaults to {})
* @returns {NodeJS.ReadableStream} conventional-changelog stream
*/
getChangelogStream(rawOptions = {});
/**
* Generates changelog as a string promise
* @param {Object} options - Optional changelog generation options
* @returns {Promise<string>} Generated changelog
*/
generateChangelog(options);
/**
* Reads existing changelog from infile
* @returns {Promise<string>} Existing changelog content
*/
getPreviousChangelog();
/**
* Writes generated changelog to file
* @returns {Promise<void>}
*/
async writeChangelog();
/**
* Gets incremented version if not ignoring recommended bump
* @param {Object} options - Version increment options
* @returns {Promise<string|null>} Incremented version or null
*/
getIncrementedVersion(options);
/**
* Gets incremented version for CI environments
* @param {Object} options - Version increment options
* @returns {Promise<string|null>} Incremented version or null
*/
getIncrementedVersionCI(options);
/**
* Sets version context and generates changelog if needed
* @param {string} version - Target version
* @returns {Promise<void>}
*/
async bump(version);
/**
* Hook executed before release, writes changelog to file
* @returns {Promise<void>}
*/
async beforeRelease();
}interface PluginOptions {
/** Conventional changelog preset configuration */
preset?: PresetConfig | string;
/** Path to changelog file */
infile?: string | false;
/** Header for changelog file (defaults to "# Changelog") */
header?: string;
/** Whether to ignore recommended version bump */
ignoreRecommendedBump?: boolean;
/** Whether to strictly follow semver for pre-releases */
strictSemVer?: boolean;
}
interface PresetConfig {
/** Preset name (angular, conventionalcommits, etc.) */
name: string;
/** Custom commit types configuration */
types?: Array<{
type: string;
section: string;
}>;
}interface AdvancedOptions {
/** Options for commit analysis */
commitsOpts?: Object;
/** Options for git tag handling */
tagOpts?: Object;
/** Custom bump determination function or false to skip */
whatBump?: Function | false;
/** Additional context for changelog generation */
context?: Object;
/** Options for git-raw-commits */
gitRawCommitsOpts?: Object;
/** Options for conventional-commits-parser */
parserOpts?: Object;
/** Options for conventional-changelog-writer */
writerOpts?: Object;
/** Lerna package name for monorepo support */
lernaPackage?: string;
/** Current working directory for git operations */
cwd?: string;
/** Git tag prefix for version tags */
tagPrefix?: string;
}The plugin supports multiple conventional changelog presets:
angular - Angular commit conventionatom - Atom editor conventioncodemirror - CodeMirror conventionconventionalcommits - Conventional Commits specificationember - Ember.js conventioneslint - ESLint conventionexpress - Express.js conventionjquery - jQuery conventionjscs - JSCS conventionjshint - JSHint conventionPlugin options can be configured via command line:
# Set changelog file
release-it --plugins.@release-it/conventional-changelog.infile=history.md
# Disable changelog file writing
release-it --no-plugins.@release-it/conventional-changelog.infile
# Use dot notation for nested options
release-it --plugins.@release-it/conventional-changelog.preset.name=angularWhen using in GitHub Actions, ensure fetch-depth: 0 is set to access full git history:
- uses: actions/checkout@v4
with:
fetch-depth: 0concat-stream ^2.0.0 - Stream concatenation utilityconventional-changelog ^6.0.0 - Core conventional changelog functionalityconventional-recommended-bump ^10.0.0 - Version bump recommendationsgit-semver-tags ^8.0.0 - Git semver tag utilitiessemver ^7.6.3 - Semantic version handlingrelease-it ^18.0.0 || ^19.0.0 - Required release-it frameworkThe plugin handles various error conditions gracefully: