renovate/lib/modules/datasource/sbt-package/util.ts
Rhys Arkins dca3418bbd refactor: lib/modules ()
Moves datasource, manager, platform and versioning code from lib/ into new lib/modules/

BREAKING CHANGE: External tools must update paths to datasource, manager, platform and versioning
2022-03-04 09:04:02 +01:00

31 lines
900 B
TypeScript

import { regEx } from '../../../util/regex';
import { compare } from '../../versioning/maven/compare';
const linkRegExp = /(?<=href=['"])[^'"]*(?=\/['"])/gi;
export function parseIndexDir(
content: string,
filterFn = (x: string): boolean => !regEx(/^\.+/).test(x)
): string[] {
const unfiltered = content.match(linkRegExp) ?? [];
return unfiltered.filter(filterFn);
}
export function normalizeRootRelativeUrls(
content: string,
rootUrl: string | URL
): string {
const rootRelativePath = new URL(rootUrl.toString()).pathname;
return content.replace(linkRegExp, (href: string) =>
href.replace(rootRelativePath, '')
);
}
export function getLatestVersion(versions: string[] | null): string | null {
if (versions?.length) {
return versions.reduce((latestVersion, version) =>
compare(version, latestVersion) === 1 ? version : latestVersion
);
}
return null;
}