mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 23:11:31 +00:00
8ea65f77d2
* fix(kotlin-script): support vararg arguments in @file:DependsOn and @file:Repository Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(kotlin-script): remove unreachable branch to restore code coverage Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(kotlin-script): restore functional style after vararg fix Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(kotlin-script): use non-null assertion to avoid uncovered branches Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Implement requested changes --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { isString, isTruthy } from '@sindresorhus/is';
|
|
import { regEx } from '../../../util/regex.ts';
|
|
import { MavenDatasource } from '../../datasource/maven/index.ts';
|
|
import type { PackageDependency, PackageFileContent } from '../types.ts';
|
|
|
|
const dependsOnBlockRegex = regEx(
|
|
/@file\s*:\s*DependsOn\s*\((?<args>[^)]*)\)/g,
|
|
);
|
|
const dependencyRegex = regEx(
|
|
/(?<replaceString>"(?<groupId>[^:"]+):(?<artifactId>[^:"]+):(?<version>[^"]+)")/g,
|
|
);
|
|
const repositoryBlockRegex = regEx(
|
|
/@file\s*:\s*Repository\s*\((?<args>[^)]*)\)/g,
|
|
);
|
|
const repositoryUrlRegex = regEx(/"(?<repositoryName>[^"]+)"/g);
|
|
|
|
export function extractPackageFile(
|
|
fileContent: string,
|
|
): PackageFileContent | null {
|
|
const registryUrls: string[] = [...fileContent.matchAll(repositoryBlockRegex)]
|
|
.flatMap((block) => [...block.groups!.args.matchAll(repositoryUrlRegex)])
|
|
.map((match) => match.groups?.repositoryName)
|
|
.filter(isString);
|
|
|
|
const deps: PackageDependency[] = [];
|
|
for (const block of fileContent.matchAll(dependsOnBlockRegex)) {
|
|
const matches = [...block.groups!.args.matchAll(dependencyRegex)]
|
|
.map((m) => m.groups)
|
|
.filter(isTruthy);
|
|
for (const match of matches) {
|
|
const dep: PackageDependency = {
|
|
currentValue: match.version,
|
|
depName: `${match.groupId}:${match.artifactId}`,
|
|
replaceString: match.replaceString,
|
|
datasource: MavenDatasource.id,
|
|
};
|
|
deps.push(dep);
|
|
}
|
|
}
|
|
|
|
if (deps.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
deps,
|
|
...(registryUrls.length && { registryUrls }),
|
|
};
|
|
}
|