@better-builds/lets-version
Version:
A package that reads your conventional commits and git history and recommends (or applies) a SemVer version bump for you
315 lines (314 loc) • 10.2 kB
TypeScript
import type { PackageJson } from 'type-fest';
/**
* Represents a raw git commit with no conventional commits connection
* (basically straight from "git log")
*/
export declare class GitCommit {
author: string;
date: string;
email: string;
message: string;
sha: string;
/**
* @param author - Author of the commit
* @param date - Date when the commit happened
* @param email - Author's email
* @param message - Raw commit message
* @param sha - Unique hash for the commit
*/
constructor(author: string, date: string, email: string, message: string, sha: string);
}
/**
* Represents a raw git commit with no conventional commits connection
* (basically straight from "git log"), but with package info
* attached to the commit. this might be uber verbose, but at least
* we have all the data available
*/
export declare class GitCommitWithPackageInfo extends GitCommit {
author: string;
date: string;
email: string;
message: string;
sha: string;
packageInfo: PackageInfo;
/**
* @param author - Author of the commit
* @param date - Date when the commit happened
* @param email - Author's email
* @param message - Raw commit message
* @param sha - Unique hash for the commit
* @param packageInfo - Parsed packageInfo
*/
constructor(author: string, date: string, email: string, message: string, sha: string, packageInfo: PackageInfo);
}
/**
* Represents notes detected on a conventional commit
*/
export declare class GitConventionalNote {
title: string;
text: string;
constructor(title: string, text: string);
}
export interface GitConventionalOpts {
sha: string;
author?: string | null;
email?: string | null;
body: string | null;
breaking: boolean;
footer: string | null;
header: string | null;
mentions: string[] | null;
merge: string | null;
notes: GitConventionalNote[];
references?: string[];
revert?: object | null;
scope?: string | null;
subject?: string | null;
type?: ConventionalCommitType | null;
}
/**
* Represents a parsed commit with conventional commits enriched data
*/
export declare class GitConventional {
sha: string;
author?: string | null;
email?: string | null;
body: string | null;
breaking: boolean;
footer: string | null;
header: string | null;
mentions: string[] | null;
merge: string | null;
notes: GitConventionalNote[];
references?: object | null;
revert?: object | null;
scope?: string | null;
subject?: string | null;
type?: ConventionalCommitType | null;
constructor({ body, breaking, footer, header, mentions, merge, notes, references, revert, scope, sha, subject, type, author, email, }: GitConventionalOpts);
}
/**
* Represents a commit that has had its message parsed and converted
* into a valid Conventional Commits structure
*/
export declare class GitCommitWithConventional extends GitCommit {
author: string;
date: string;
email: string;
message: string;
sha: string;
conventional: GitConventional;
constructor(author: string, date: string, email: string, message: string, sha: string, conventional: GitConventional);
}
/**
* Represents a commit that has had its message parsed and converted
* into a valid Conventional Commits structure. Additionally, package
* info will be attached to the commit
*/
/**
* Represents a Git commit with conventional commit and package information
*/
export declare class GitCommitWithConventionalAndPackageInfo extends GitCommitWithConventional {
packageInfo: PackageInfo;
constructor(author: string, date: string, email: string, message: string, sha: string, conventional: GitConventional, packageInfo: PackageInfo);
}
export interface PackageInfoOpts {
filesChanged?: string[];
isPrivate: boolean;
name: string;
packagePath: string;
packageJSONPath: string;
pkg: PackageJson;
root: boolean;
version: string;
}
export declare class PackageInfo {
isPrivate: boolean;
name: string;
packageJSONPath: string;
packagePath: string;
pkg: PackageJson;
root: boolean;
version: string;
filesChanged?: string[];
constructor({ filesChanged, isPrivate, name, packageJSONPath, packagePath, pkg, root, version }: PackageInfoOpts);
}
export type DepType = 'self' | 'devDependencies' | 'dependencies' | 'optionalDependencies' | 'peerDependencies';
export interface LocalDependencyGraphNodeOpts extends PackageInfoOpts {
depType: DepType;
deps: LocalDependencyGraphNode[];
}
/**
* Represents an instance of a local repository dependency
* and any other local deps it relies on
*/
export declare class LocalDependencyGraphNode extends PackageInfo {
depType: DepType;
deps: LocalDependencyGraphNode[];
constructor({ depType, deps, ...info }: LocalDependencyGraphNodeOpts);
}
/**
* Represents information about a package and its latest detected git tag
* that corresponds to a version or publish event
*/
export declare class PublishTagInfo {
packageName: string;
tag: string | null;
sha: string | null;
constructor(packageName: string, tag: string | null, sha: string | null);
}
/**
* Represents the which type of preset release a user can do.
*/
export declare enum ReleaseAsPresets {
ALPHA = "alpha",
AUTO = "auto",
BETA = "beta",
MAJOR = "major",
MINOR = "minor",
PATCH = "patch"
}
/**
* Represents the type of commit, as detected
* by the conventional parser
*
*/
export declare enum ConventionalCommitType {
BUILD = "build",
CHORE = "chore",
CI = "ci",
DOCS = "docs",
FEAT = "feat",
FIX = "fix",
PERF = "perf",
REFACTOR = "refactor",
REVERT = "revert",
STYLE = "style",
TEST = "test"
}
/**
* Represents a semver bump type operation
*/
export declare enum BumpType {
PATCH = 0,
MINOR = 1,
MAJOR = 2,
FIRST = 3,
PRERELEASE = 4,
EXACT = 5
}
/**
* Represents the type of entry that will be
* added to a changelog
*
* @enum {string}
*/
export declare enum ChangelogEntryType {
BREAKING = "BREAKING",
DOCS = "DOCS",
FEATURES = "FEATURES",
FIXES = "FIXES",
MISC = "MISC"
}
/**
* Will return the renderer that will be used for the
* changelog entry type
*/
export declare const getChangelogEntryTypeRenderer: (type: ChangelogEntryType) => "🚨 Breaking Changes 🚨" | "📖 Docs 📖" | "✨ Features ✨" | "🛠️ Fixes 🛠️" | "🔀 Miscellaneous 🔀";
/**
* Represents the string version of a bump type for user display
*/
export declare const BumpTypeToString: Record<number, string>;
/**
* Represents information about a version bump recommendation
* for a specific parsed package
*/
export declare class BumpRecommendation {
packageInfo: PackageInfo;
from: string | null;
to: string;
type: BumpType;
parentBumps: Set<BumpRecommendation>;
constructor(packageInfo: PackageInfo, from: string | null, to: string, type: BumpType, parentBump?: BumpRecommendation);
/**
* Determines if the bump is valid.
* An invalid bump is one where the "from" an "to" are marked as the same.
* This means there was an issue when attempting to recommend a bump in the "lets-version" logic
*/
get isValid(): boolean;
/**
* Computes a human-friendly bump type name
* from the BumpType enum for this Bump recommendation
*/
get bumpTypeName(): string;
}
export type ChangeLogEntryFormatter = (updates: ChangelogUpdate, allUpdates: ChangelogUpdate[]) => string;
export type ChangeLogLineFormatter = (line: GitConventional) => string | null;
export type ChangeLogRollupFormatter = (aggregatedUpdate: ChangelogAggregateUpdate) => string | null;
/**
* Represents a single type of changelog update
* that should be included as part of a larger "ChangelogUpdate."
* This individual entry should be written to a CHANGELOG.md file
* as part of the larger update
*/
export declare class ChangelogUpdateEntry {
type: ChangelogEntryType;
lines: GitConventional[];
formatter: ChangeLogLineFormatter;
/**
* Default formatter, will format each individual line of the changelog
*/
static defaultFormatter(line: GitConventional): string;
constructor(type: ChangelogEntryType, lines: GitConventional[], formatter?: ChangeLogLineFormatter);
/**
* Returns a string representation of this specific changelog entry
* that can be included in a parent ChangelogUpdate (which will then be
* prepended to a CHANGELOG.md file)
*/
toString(): string;
}
/**
* Represents a changelog update that can be
* prepends to a new or existing CHANGELOG.md file for a specific
* package
*/
export declare class ChangelogUpdate {
formattedDate: string;
bumpRecommendation: BumpRecommendation;
entries: Record<string, ChangelogUpdateEntry>;
constructor(formattedDate: string, bumpRecommendation: BumpRecommendation, entries: Record<string, ChangelogUpdateEntry>);
/**
* Returns an absolute path to the CHANGELOG.md
* file that should correspond to this update
*/
get changelogPath(): string;
/**
* Converts this ChangelogUpdate instance into a string that
* can be safely prepended to a CHANGELOG.md file
*
* @returns {string}
*/
toString(): string;
}
/**
* Represents a "rollup" CHANGELOG.md that will contain
* all of the updates that happened for a given version bump operation.
* Typically, this is placed at the root of a multi-package monorepo
*/
export declare class ChangelogAggregateUpdate {
cwd: string;
formattedDate: string;
changelogUpdates: ChangelogUpdate[];
/**
* @param {string} cwd
* @param {string} formattedDate
* @param {ChangelogUpdate[]} changelogUpdates
*/
constructor(cwd: string, formattedDate: string, changelogUpdates: ChangelogUpdate[]);
get changelogPath(): string;
/**
* Converts this ChangelogAggregateUpdate instance into a string that
* can be safely prepended to a CHANGELOG.md file in the root of your project
*/
toString(): string;
}