t-comm
Version:
专业、稳定、纯粹的工具库
51 lines (50 loc) • 2.1 kB
TypeScript
declare const versionTypeMap: {
alpha: string;
beta: string;
rc: string;
patch: string;
minor: string;
major: string;
};
type VersionType = keyof typeof versionTypeMap | string;
export interface GetNextVersionOptions {
/** 执行 npm dist-tag ls 时所在目录,默认 process.cwd() */
cwd?: string;
/**
* 检测某个版本对应的 tag 是否已存在
* 若返回 true,则会基于该版本继续往后 bump,直到找到一个不冲突的版本
* (仅对 prerelease 类型 alpha/beta/rc 有循环 bump 能力,其他类型只会判断一次)
*/
checkTagExists?: (version: string) => boolean;
/** checkTagExists 循环次数上限,防御无限循环,默认 20 */
maxBumpAttempts?: number;
}
export declare function getNexVersionCore(obj: Record<string, string>, versionType: VersionType): string | null;
/**
* 根据 npm dist-tag 结果计算下一个版本号
* @param packageName 包名
* @param versionType 版本类型 alpha/beta/rc/patch/minor/major,或一个合法的 semver
* @param optionsOrCwd 第三个参数:
* - 字符串:兼容旧用法,作为 cwd 使用
* - 对象:{ cwd, checkTagExists, maxBumpAttempts };当 checkTagExists 返回 true 时会基于该版本继续 bump
*/
export declare function getNextVersion(packageName: string | undefined, versionType: VersionType, optionsOrCwd?: string | GetNextVersionOptions): string | null;
/**
* 生成 alpha、beta 等这些预发布的版本
* @param key 关键词
* @returns 生成的版本
* @example
* ```ts
* // 假设 npm dist-tag 的 latest 是 1.0.0、alpha 是 1.0.0-alpha.1
* getPreReleaseVersion('alpha'); // '1.0.0-alpha.2'
*
* // key 为空时返回 undefined
* getPreReleaseVersion(''); // undefined
*
* // 拉不到 dist-tag 时使用默认 latest 0.1.0
* getPreReleaseVersion('beta'); // '0.1.0-beta.1'
* ```
*/
export declare function getPreReleaseVersion(key?: string, cwd?: string): string | undefined;
export declare function genVersion(obj?: Record<string, string>, key?: string): string;
export {};