renovate/lib/modules/versioning/index.ts
Sebastian Poxhofer 8e2df85268
feat(versioning)!: default to semver-coerced instead of semver (#20573)
BREAKING CHANGE: default versioning is now `semver-coerced`, instead of `semver`.
2023-03-10 09:34:41 +01:00

44 lines
1.3 KiB
TypeScript

import { logger } from '../../logger';
import versionings from './api';
import { isVersioningApiConstructor } from './common';
import * as semverCoerced from './semver-coerced';
import type { VersioningApi, VersioningApiConstructor } from './types';
export * from './types';
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 | undefined): VersioningApi {
if (!versioning) {
logger.trace(
`Missing versioning, using ${defaultVersioning.id} as fallback.`
);
return defaultVersioning.api;
}
const [versioningName, ...versioningRest] = versioning.split(':');
const versioningConfig = versioningRest.length
? versioningRest.join(':')
: undefined;
const theVersioning = versionings.get(versioningName);
if (!theVersioning) {
logger.info(
{ versioning },
`Unknown versioning - defaulting to ${defaultVersioning.id}`
);
return defaultVersioning.api;
}
if (isVersioningApiConstructor(theVersioning)) {
return new theVersioning(versioningConfig);
}
return theVersioning;
}