mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-15 09:06:25 +00:00
6293edc19a
Co-Authored-By: Michael Kriese <michael.kriese@visualon.de>
35 lines
1,020 B
TypeScript
35 lines
1,020 B
TypeScript
import { PackageFile, PackageDependency } from '../common';
|
|
import * as datasourceCdnjs from '../../datasource/cdnjs';
|
|
|
|
export const cloudflareUrlRegex = /\/\/cdnjs\.cloudflare\.com\/ajax\/libs\/(?<depName>[^/]+?)\/(?<currentValue>[^/]+?)\/(?<asset>[-/_.a-zA-Z0-9]+)/;
|
|
|
|
export function extractPackageFile(content: string): PackageFile {
|
|
const deps: PackageDependency[] = [];
|
|
|
|
let rest = content;
|
|
let match = cloudflareUrlRegex.exec(rest);
|
|
let offset = 0;
|
|
while (match) {
|
|
const [wholeSubstr] = match;
|
|
const { depName, currentValue, asset } = match.groups;
|
|
|
|
const fileReplacePosition =
|
|
offset + match.index + wholeSubstr.indexOf(currentValue);
|
|
|
|
offset += match.index + wholeSubstr.length;
|
|
rest = content.slice(offset);
|
|
match = cloudflareUrlRegex.exec(rest);
|
|
|
|
deps.push({
|
|
datasource: datasourceCdnjs.id,
|
|
depName,
|
|
lookupName: `${depName}/${asset}`,
|
|
currentValue,
|
|
managerData: {
|
|
fileReplacePosition,
|
|
},
|
|
});
|
|
}
|
|
|
|
return { deps };
|
|
}
|