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

41 lines
1.1 KiB
TypeScript

import is from '@sindresorhus/is';
import { z } from 'zod';
import { logger } from '../../logger';
import versionings from './api';
import * as defaultVersioning from './semver-coerced';
import type { VersioningApi } from './types';
export const Versioning = z
.string()
.transform((versioningSpec, ctx): VersioningApi => {
const [versioningName, ...versioningRest] = versioningSpec.split(':');
let versioning = versionings.get(versioningName);
if (!versioning) {
logger.info(
{ versioning: versioningSpec },
`Versioning: '${versioningSpec}' not found, falling back to ${defaultVersioning.id}`,
);
return defaultVersioning.api;
}
if (is.function_(versioning)) {
const versioningConfig = versioningRest.length
? versioningRest.join(':')
: undefined;
try {
versioning = new versioning(versioningConfig);
} catch (error) {
ctx.addIssue({
code: 'custom',
message: `Versioning: '${versioningSpec}' failed to initialize`,
params: { error },
});
return z.NEVER;
}
}
return versioning;
});