0
0
Fork 0
mirror of https://github.com/renovatebot/renovate.git synced 2025-05-12 23:51:55 +00:00
renovatebot_renovate/lib/modules/manager/cake/index.ts
RahulGautamSingh bc7d0595d0
feat(config): managerFilePatterns (#34615)
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2025-05-04 08:30:24 +00:00

81 lines
2.3 KiB
TypeScript

import moo from 'moo';
import type { Category } from '../../../constants';
import { regEx } from '../../../util/regex';
import { isHttpUrl } from '../../../util/url';
import { NugetDatasource } from '../../datasource/nuget';
import type { PackageDependency, PackageFileContent } from '../types';
export const url = 'https://cakebuild.net/docs';
export const categories: Category[] = ['dotnet'];
export const defaultConfig = {
managerFilePatterns: ['/\\.cake$/'],
};
export const supportedDatasources = [NugetDatasource.id];
const lexer = moo.states({
main: {
lineComment: { match: /\/\/.*?$/ }, // TODO #12870
multiLineComment: { match: /\/\*[^]*?\*\//, lineBreaks: true }, // TODO #12870
dependency: {
match: /^#(?:addin|tool|module|load|l)\s+(?:nuget|dotnet):.*$/, // TODO #12870
},
dependencyQuoted: {
match: /^#(?:addin|tool|module|load|l)\s+"(?:nuget|dotnet):[^"]+"\s*$/, // TODO #12870
value: (s: string) => s.trim().slice(1, -1),
},
unknown: moo.fallback,
},
});
function parseDependencyLine(line: string): PackageDependency | null {
try {
let url = line.replace(regEx(/^[^:]*:/), '');
const isEmptyHost = url.startsWith('?');
url = isEmptyHost ? `http://localhost/${url}` : url;
const parsedUrl = new URL(url);
const { origin, pathname, searchParams } = parsedUrl;
const registryUrl = `${origin}${pathname}`;
const depName = searchParams.get('package')!;
const currentValue = searchParams.get('version') ?? undefined;
const result: PackageDependency = {
datasource: NugetDatasource.id,
depName,
currentValue,
};
if (!isEmptyHost) {
if (isHttpUrl(parsedUrl)) {
result.registryUrls = [registryUrl];
} else {
result.skipReason = 'unsupported-url';
}
}
return result;
} catch {
return null;
}
}
export function extractPackageFile(content: string): PackageFileContent {
const deps: PackageDependency[] = [];
lexer.reset(content);
let token = lexer.next();
while (token) {
const { type, value } = token;
if (type === 'dependency' || type === 'dependencyQuoted') {
const dep = parseDependencyLine(value);
if (dep) {
deps.push(dep);
}
}
token = lexer.next();
}
return { deps };
}