mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-14 16:46:25 +00:00
143c9a6751
Renames `lookupName` to be `packageName`. BREAKING CHANGE: Use `packageName` instead of `lookupName` if interacting with Renovate datasources directly.
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { regEx } from '../../../util/regex';
|
|
import { CdnJsDatasource } from '../../datasource/cdnjs';
|
|
import { cloudflareUrlRegex } from '../cdnurl/extract';
|
|
import type { PackageDependency, PackageFile } from '../types';
|
|
|
|
const regex = regEx(/<\s*(script|link)\s+[^>]*?\/?>/i);
|
|
|
|
const integrityRegex = regEx(
|
|
/\s+integrity\s*=\s*("|')(?<currentDigest>[^"']+)/
|
|
);
|
|
|
|
export function extractDep(tag: string): PackageDependency | null {
|
|
const match = cloudflareUrlRegex.exec(tag);
|
|
if (!match) {
|
|
return null;
|
|
}
|
|
const { depName, currentValue, asset } = match.groups;
|
|
const dep: PackageDependency = {
|
|
datasource: CdnJsDatasource.id,
|
|
depName,
|
|
packageName: `${depName}/${asset}`,
|
|
currentValue,
|
|
replaceString: tag,
|
|
};
|
|
const integrityMatch = integrityRegex.exec(tag);
|
|
if (integrityMatch) {
|
|
dep.currentDigest = integrityMatch.groups.currentDigest;
|
|
}
|
|
return dep;
|
|
}
|
|
|
|
export function extractPackageFile(content: string): PackageFile {
|
|
const deps: PackageDependency[] = [];
|
|
let rest = content;
|
|
let match = regex.exec(rest);
|
|
let offset = 0;
|
|
while (match) {
|
|
const [replaceString] = match;
|
|
offset += match.index + replaceString.length;
|
|
rest = content.slice(offset);
|
|
match = regex.exec(rest);
|
|
const dep = extractDep(replaceString);
|
|
if (dep) {
|
|
deps.push(dep);
|
|
}
|
|
}
|
|
if (!deps.length) {
|
|
return null;
|
|
}
|
|
return { deps };
|
|
}
|