Skip to content

Commit

Permalink
gracefully exit if we can't solve an issue with peer dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo authored and randhircs committed Nov 22, 2024
1 parent fa3a23f commit 1b870a1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ protected static Task TestNoChangeforProject(
TestFile[]? additionalFiles = null,
MockNuGetPackage[]? packages = null,
ExperimentsManager? experimentsManager = null,
string projectFilePath = "test-project.csproj")
string projectFilePath = "test-project.csproj",
ExpectedUpdateOperationResult? expectedResult = null)
=> TestUpdateForProject(
dependencyName,
oldVersion,
Expand All @@ -88,7 +89,8 @@ protected static Task TestNoChangeforProject(
additionalFiles,
additionalFilesExpected: additionalFiles,
packages: packages,
experimentsManager: experimentsManager);
experimentsManager: experimentsManager,
expectedResult: expectedResult);

protected static Task TestUpdateForProject(
string dependencyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3109,6 +3109,46 @@ await TestNoChangeforProject("Some.Package", "7.0.1", "13.0.1",
);
}

[Fact]
public async Task NoChange_IfPeerDependenciesCannotBeEvaluated()
{
// make sure we don't throw if we find conflicting peer dependencies; this can happen in multi-tfm projects if the dependencies are too complicated to resolve
// eventually this should be able to be resolved, but currently we can't branch on the different packages for different TFMs
await TestNoChangeforProject("Some.Package", "1.0.0", "1.1.0",
packages:
[
// initial packages
new MockNuGetPackage("Some.Package", "1.0.0",
DependencyGroups: [
("net8.0", [("Transitive.Dependency", "8.0.0")]),
("net9.0", [("Transitive.Dependency", "9.0.0")])
]),
MockNuGetPackage.CreateSimplePackage("Transitive.Dependency", "8.0.0", "net8.0"),
MockNuGetPackage.CreateSimplePackage("Transitive.Dependency", "9.0.0", "net9.0"),

// what we're trying to update to, but will fail
new MockNuGetPackage("Some.Package", "1.1.0",
DependencyGroups: [
("net8.0", [("Transitive.Dependency", "8.1.0")]),
("net9.0", [("Transitive.Dependency", "9.1.0")])
]),
MockNuGetPackage.CreateSimplePackage("Transitive.Dependency", "8.1.0", "net8.0"),
MockNuGetPackage.CreateSimplePackage("Transitive.Dependency", "9.1.0", "net9.0"),
],
projectContents: """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" Version="1.0.0" />
</ItemGroup>
</Project>
""",
expectedResult: new() // success
);
}

[Fact]
public async Task ProcessingProjectWithWorkloadReferencesDoesNotFail()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public static async Task UpdateDependencyAsync(
}
else
{
if (peerDependencies is null)
{
return;
}

await UpdateDependencyWithConflictResolution(repoRootPath, buildFiles, tfms, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive, peerDependencies, logger);
}

Expand Down

0 comments on commit 1b870a1

Please sign in to comment.