Flexible configuration system supporting multiple configuration sources and automatic resolution of git repository information. This module provides comprehensive configuration loading, validation, and resolution for all changelogen features.
Loads and resolves configuration from multiple sources with intelligent defaults.
/**
* Load and resolve changelog configuration from multiple sources
* @param cwd - Working directory for configuration and git operations
* @param overrides - Optional configuration overrides
* @returns Promise resolving to fully resolved configuration
*/
function loadChangelogConfig(
cwd: string,
overrides?: Partial<ChangelogConfig>
): Promise<ResolvedChangelogConfig>;Usage Examples:
import { loadChangelogConfig } from "changelogen";
// Basic configuration loading
const config = await loadChangelogConfig(process.cwd());
// With overrides
const customConfig = await loadChangelogConfig(process.cwd(), {
from: "v1.0.0",
to: "HEAD",
output: "CHANGELOG.md",
noAuthors: true
});
// For specific directory
const repoConfig = await loadChangelogConfig("/path/to/repo", {
types: {
feat: { title: "β¨ Features", semver: "minor" },
fix: { title: "π Fixes", semver: "patch" }
}
});Resolves configuration values by filling in defaults and auto-detecting repository information.
/**
* Resolve configuration by applying defaults and auto-detection
* @param config - Base configuration object
* @param cwd - Working directory for resolution
* @returns Promise resolving to resolved configuration
*/
function resolveChangelogConfig(
config: ChangelogConfig,
cwd: string
): Promise<ResolvedChangelogConfig>;Configuration is loaded from multiple sources in order of precedence:
changelog.config.{ts,js,mjs,cjs}.changelogrcpackage.json (changelog field)Example Configuration Files:
// changelog.config.ts
export default {
types: {
feat: { title: "π Features", semver: "minor" },
fix: { title: "π Bug Fixes", semver: "patch" },
docs: { title: "π Documentation", semver: "patch" }
},
scopeMap: {
"ui": "interface",
"cli": "command-line"
},
excludeAuthors: ["dependabot[bot]", "renovate[bot]"],
noAuthors: false,
hideAuthorEmail: true
};// .changelogrc
{
"types": {
"feat": { "title": "π Features", "semver": "minor" },
"fix": { "title": "π Bug Fixes", "semver": "patch" }
},
"output": "CHANGELOG.md",
"excludeAuthors": ["bot@example.com"]
}// package.json
{
"name": "my-package",
"changelog": {
"types": {
"feat": { "title": "Features" }
},
"repo": "user/my-package"
}
}interface ChangelogConfig {
/** Working directory for git operations */
cwd: string;
/** Commit type configuration with titles and semver mapping */
types: Record<string, { title: string; semver?: SemverBumpType } | boolean>;
/** Scope name mapping for normalization */
scopeMap: Record<string, string>;
/** Repository configuration (auto-resolved if not provided) */
repo?: RepoConfig | string;
/** Authentication tokens for different providers */
tokens: Partial<Record<RepoProvider, string>>;
/** Starting commit reference */
from: string;
/** Ending commit reference */
to: string;
/** Target version for release */
newVersion?: string;
/** Whether git tags should be signed */
signTags?: boolean;
/** Output file path or false to disable file output */
output: string | boolean;
/** Publishing configuration */
publish: {
args?: string[];
tag?: string;
private?: boolean;
};
/** Template strings for commits and tags */
templates: {
commitMessage?: string;
tagMessage?: string;
tagBody?: string;
};
/** Disable author attribution section */
noAuthors: boolean;
/** Authors to exclude from attribution */
excludeAuthors: string[];
/** Hide author email addresses */
hideAuthorEmail?: boolean;
}type ResolvedChangelogConfig = Omit<ChangelogConfig, "repo"> & {
/** Fully resolved repository configuration */
repo: RepoConfig;
};Changelogen provides comprehensive defaults that work out of the box:
const defaultTypes = {
feat: { title: "π Enhancements", semver: "minor" },
perf: { title: "π₯ Performance", semver: "patch" },
fix: { title: "π©Ή Fixes", semver: "patch" },
refactor: { title: "π
Refactors", semver: "patch" },
docs: { title: "π Documentation", semver: "patch" },
build: { title: "π¦ Build", semver: "patch" },
types: { title: "π Types", semver: "patch" },
chore: { title: "π‘ Chore" }, // No semver bump
examples: { title: "π Examples" }, // No semver bump
test: { title: "β
Tests" }, // No semver bump
style: { title: "π¨ Styles" }, // No semver bump
ci: { title: "π€ CI" } // No semver bump
};const defaultTemplates = {
commitMessage: "chore(release): v{{newVersion}}",
tagMessage: "v{{newVersion}}",
tagBody: "v{{newVersion}}"
};const defaultPublish = {
private: false,
tag: "latest",
args: []
};Automatically detects repository information from:
package.json repository field:
{
"repository": "user/repo",
"repository": {
"type": "git",
"url": "https://github.com/user/repo.git"
}
}Git remote URL:
git remote get-url origingit describe --tags --abbrev=0)HEAD)Automatically resolves authentication tokens from:
GITHUB_TOKEN, GH_TOKEN, etc.)# GitHub token (in order of precedence)
CHANGELOGEN_TOKENS_GITHUB=ghp_xxxxxxxxxxxx
GITHUB_TOKEN=ghp_xxxxxxxxxxxx
GH_TOKEN=ghp_xxxxxxxxxxxx
# NPM publishing
NPM_CONFIG_PROVENANCE=false # Disable provenance in CI# Override configuration via environment
CHANGELOG_FROM=v1.0.0
CHANGELOG_TO=HEAD
CHANGELOG_OUTPUT=RELEASES.mdconst config = await loadChangelogConfig(process.cwd(), {
types: {
// Custom types with emojis
feature: { title: "β¨ New Features", semver: "minor" },
bugfix: { title: "π Bug Fixes", semver: "patch" },
security: { title: "π Security", semver: "patch" },
breaking: { title: "π₯ Breaking Changes", semver: "major" },
// Disable certain types
chore: false,
// Types without semver impact
docs: { title: "π Documentation" }
}
});const config = await loadChangelogConfig(process.cwd(), {
scopeMap: {
// Normalize scope names
"ui": "interface",
"cli": "command-line",
"db": "database",
"api": "API",
// Group related scopes
"auth": "authentication",
"oauth": "authentication"
}
});const config = await loadChangelogConfig(process.cwd(), {
// Exclude bots and automated commits
excludeAuthors: [
"dependabot[bot]",
"renovate[bot]",
"github-actions[bot]",
"ci@company.com"
],
// Hide email addresses for privacy
hideAuthorEmail: true,
// Disable author section entirely
noAuthors: false
});const config = await loadChangelogConfig(process.cwd(), {
templates: {
// Custom commit message format
commitMessage: "release: {{newVersion}}",
// Custom tag formats
tagMessage: "Release {{newVersion}}",
tagBody: "Release {{newVersion}}\n\nSee CHANGELOG.md for details"
}
});const config = await loadChangelogConfig(process.cwd(), {
publish: {
// Custom npm tag
tag: "beta",
// Additional npm publish arguments
args: ["--access", "public", "--registry", "https://npm.example.com"],
// Publish private packages
private: true
}
});The configuration system includes built-in validation:
Configuration loading handles various error conditions: