fix(nuget): add support for alternate nuget config file names (#5919)

This commit is contained in:
Florian Greinacher 2020-04-08 21:31:44 +02:00 committed by GitHub
parent a9fc67e210
commit f69c517949
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 100 additions and 1 deletions

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Contoso" value="https://contoso.com/packages/" />
</packageSources>
</configuration>

View file

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<Version>0.1.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.5.0" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Contoso" value="https://contoso.com/packages/" />
</packageSources>
</configuration>

View file

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<Version>0.1.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.5.0" />
</ItemGroup>
</Project>

View file

@ -17,6 +17,40 @@ Object {
} }
`; `;
exports[`lib/manager/nuget/extract extractPackageFile() considers lower-case nuget.config 1`] = `
Object {
"deps": Array [
Object {
"currentValue": "4.5.0",
"datasource": "nuget",
"depName": "Autofac",
"depType": "nuget",
"registryUrls": Array [
"https://api.nuget.org/v3/index.json#protocolVersion=3",
"https://contoso.com/packages/",
],
},
],
}
`;
exports[`lib/manager/nuget/extract extractPackageFile() considers pascal-case NuGet.Config 1`] = `
Object {
"deps": Array [
Object {
"currentValue": "4.5.0",
"datasource": "nuget",
"depName": "Autofac",
"depType": "nuget",
"registryUrls": Array [
"https://api.nuget.org/v3/index.json#protocolVersion=3",
"https://contoso.com/packages/",
],
},
],
}
`;
exports[`lib/manager/nuget/extract extractPackageFile() extracts all dependencies 1`] = ` exports[`lib/manager/nuget/extract extractPackageFile() extracts all dependencies 1`] = `
Array [ Array [
Object { Object {

View file

@ -24,6 +24,7 @@ describe('lib/manager/nuget/extract', () => {
const res = await extractPackageFile(sample, packageFile, config); const res = await extractPackageFile(sample, packageFile, config);
expect(res.deps).toMatchSnapshot(); expect(res.deps).toMatchSnapshot();
}); });
it('considers NuGet.config', async () => { it('considers NuGet.config', async () => {
const packageFile = 'with-config-file/with-config-file.csproj'; const packageFile = 'with-config-file/with-config-file.csproj';
const contents = readFileSync( const contents = readFileSync(
@ -35,6 +36,30 @@ describe('lib/manager/nuget/extract', () => {
await extractPackageFile(contents, packageFile, config) await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot(); ).toMatchSnapshot();
}); });
it('considers lower-case nuget.config', async () => {
const packageFile =
'with-lower-case-config-file/with-lower-case-config-file.csproj';
const contents = readFileSync(
path.join(config.localDir, packageFile),
'utf8'
);
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
it('considers pascal-case NuGet.Config', async () => {
const packageFile =
'with-pascal-case-config-file/with-pascal-case-config-file.csproj';
const contents = readFileSync(
path.join(config.localDir, packageFile),
'utf8'
);
expect(
await extractPackageFile(contents, packageFile, config)
).toMatchSnapshot();
});
it('handles malformed NuGet.config', async () => { it('handles malformed NuGet.config', async () => {
const packageFile = const packageFile =
'with-malformed-config-file/with-malformed-config-file.csproj'; 'with-malformed-config-file/with-malformed-config-file.csproj';

View file

@ -22,7 +22,9 @@ async function determineRegistryUrls(
packageFile: string, packageFile: string,
localDir: string localDir: string
): Promise<string[]> { ): Promise<string[]> {
const nuGetConfigPath = await findUp('NuGet.config', { // Valid file names taken from https://github.com/NuGet/NuGet.Client/blob/f64621487c0b454eda4b98af853bf4a528bef72a/src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs#L34
const nuGetConfigFileNames = ['nuget.config', 'NuGet.config', 'NuGet.Config'];
const nuGetConfigPath = await findUp(nuGetConfigFileNames, {
cwd: path.dirname(path.join(localDir, packageFile)), cwd: path.dirname(path.join(localDir, packageFile)),
type: 'file', type: 'file',
}); });