mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-22 20:46:25 +00:00
dca3418bbd
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
31 lines
900 B
TypeScript
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;
|
|
}
|