0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/modules/manager/cdnurl/extract.ts

32 lines
946 B
TypeScript

import { regEx } from '../../../util/regex';
import { CdnjsDatasource } from '../../datasource/cdnjs';
import type { PackageDependency, PackageFileContent } from '../types';
export const cloudflareUrlRegex = regEx(
/\/\/cdnjs\.cloudflare\.com\/ajax\/libs\/(?<depName>[^/]+?)\/(?<currentValue>[^/]+?)\/(?<asset>[-/_.a-zA-Z0-9]+)/,
);
export function extractPackageFile(content: string): PackageFileContent {
const deps: PackageDependency[] = [];
let rest = content;
let match = cloudflareUrlRegex.exec(rest);
let offset = 0;
while (match?.groups) {
const [wholeSubstr] = match;
const { depName, currentValue, asset } = match.groups;
offset += match.index + wholeSubstr.length;
rest = content.slice(offset);
match = cloudflareUrlRegex.exec(rest);
deps.push({
datasource: CdnjsDatasource.id,
depName,
packageName: `${depName}/${asset}`,
currentValue,
});
}
return { deps };
}