0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/modules/versioning/index.ts
2023-11-07 15:50:29 +00:00

36 lines
977 B
TypeScript

import versionings from './api';
import { Versioning } from './schema';
import * as semverCoerced from './semver-coerced';
import type { VersioningApi, VersioningApiConstructor } from './types';
export * from './types';
export const defaultVersioning = semverCoerced;
export const getVersioningList = (): string[] => Array.from(versionings.keys());
/**
* Get versioning map. Can be used to dynamically add new versioning type
*/
export const getVersionings = (): Map<
string,
VersioningApi | VersioningApiConstructor
> => versionings;
export function get(versioning: string | null | undefined): VersioningApi {
const res = Versioning.safeParse(
versioning ? versioning : defaultVersioning.id,
);
if (!res.success) {
const [issue] = res.error.issues;
if (issue && issue.code === 'custom' && issue.params?.error) {
throw issue.params.error;
}
// istanbul ignore next: should never happen
throw res.error;
}
return res.data;
}