mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 17:51:49 +00:00
5505b52d75
* Add nuget capability to read packages from cs files This is useful for dotnet source files that make use of the .NET 10 feature to have single file projects, where packages and sdks can be defined in a source file. * Add tests to validate that the nuget.config file is respected for single csharp files * Apply PR linter suggestion for prettier code * Remove unnecessary try-catch to increase code coverage * Update phrasing in documentation Co-authored-by: RahulGautamSingh <rahultesnik@gmail.com> * Use codeblock instead of fixture * Remove unused import * Remove unnecessary fixtures and only verify required methods are called * Fix imports in single-chsarp-file.ts * Fix import ordering * Increase code block indent --------- Co-authored-by: RahulGautamSingh <rahultesnik@gmail.com> Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { regEx } from '../../../../util/regex.ts';
|
|
import { NugetDatasource } from '../../../datasource/nuget/index.ts';
|
|
import type { PackageDependency, PackageFileContent } from '../../types.ts';
|
|
import type { NugetPackageDependency, Registry } from '../types.ts';
|
|
import { applyRegistries } from '../util.ts';
|
|
|
|
// regex for finding
|
|
// #:package Name@Version
|
|
// or
|
|
// #:sdk Name@Version
|
|
const packageRegex = regEx(
|
|
/^#:(?<type>package|sdk)\s+(?<depName>[A-Za-z0-9_.-]+)@(?<currentValue>[0-9][^\s]*)/,
|
|
'gm',
|
|
);
|
|
|
|
export function extractPackagesFromSingleCsharpFile(
|
|
content: string,
|
|
packageFile: string,
|
|
registries: Registry[] | undefined,
|
|
): PackageFileContent | null {
|
|
const deps: PackageDependency[] = [];
|
|
|
|
for (const match of content.matchAll(packageRegex)) {
|
|
const { type, depName, currentValue } = match.groups!;
|
|
|
|
const dep: NugetPackageDependency = {
|
|
depName,
|
|
currentValue,
|
|
datasource: NugetDatasource.id,
|
|
depType: type === 'package' ? 'nuget' : 'msbuild-sdk',
|
|
};
|
|
|
|
applyRegistries(dep, registries);
|
|
deps.push(dep);
|
|
}
|
|
|
|
return { deps };
|
|
}
|