Skip to content

Commit 6e5e067

Browse files
committed
Parse new resolver settings as group setting in LockFile
1 parent df5e1c8 commit 6e5e067

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

Diff for: src/Paket.Core/Dependencies/PackageResolver.fs

+2
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,8 @@ let Resolve (getVersionsRaw : PackageVersionsFunc, getPreferredVersionsRaw : Pre
10791079
let sorted =
10801080
match resolverStrategy with
10811081
| ResolverStrategy.Max -> List.sortDescending versions
1082+
| ResolverStrategy.LatestPatch -> List.sortDescending versions
1083+
| ResolverStrategy.LatestMinor -> List.sortDescending versions
10821084
| ResolverStrategy.Min -> List.sort versions
10831085

10841086
yield! sorted }

Diff for: src/Paket.Core/PaketConfigFiles/DependenciesFile.fs

+11-2
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,12 @@ type DependenciesFile(fileName,groups:Map<GroupName,DependenciesGroup>, textRepr
454454
match strategy with
455455
| None -> this
456456
| Some strategy ->
457-
let strategyString = sprintf "strategy: %s" (match strategy with ResolverStrategy.Max -> "max" | ResolverStrategy.Min -> "min")
457+
let strategyString =
458+
match strategy with
459+
| ResolverStrategy.Max -> "strategy: max"
460+
| ResolverStrategy.LatestPatch -> "strategy: latest-patch"
461+
| ResolverStrategy.LatestMinor -> "strategy: latest-minor"
462+
| ResolverStrategy.Min -> "strategy: min"
458463

459464
let list = new System.Collections.Generic.List<_>()
460465
list.AddRange textRepresentation
@@ -478,7 +483,11 @@ type DependenciesFile(fileName,groups:Map<GroupName,DependenciesGroup>, textRepr
478483
match strategy with
479484
| None -> this
480485
| Some strategy ->
481-
let strategyString = sprintf "lowest_matching: %s" (match strategy with ResolverStrategy.Max -> "false" | ResolverStrategy.Min -> "true")
486+
let strategyString =
487+
match strategy with
488+
| ResolverStrategy.Max -> "lowest_matching: max"
489+
| ResolverStrategy.Min -> "lowest_matching: min"
490+
| _ -> failwithf "Strategy %O is invalid for lowest_matching setting." strategy
482491

483492
let list = new System.Collections.Generic.List<_>()
484493
list.AddRange textRepresentation

Diff for: src/Paket.Core/PaketConfigFiles/LockFile.fs

+5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ module LockFileSerializer =
5353
| None -> ()
5454
match options.ResolverStrategyForTransitives with
5555
| Some ResolverStrategy.Min -> yield "STRATEGY: MIN"
56+
| Some ResolverStrategy.LatestPatch -> yield "STRATEGY: LATEST-PATCH"
57+
| Some ResolverStrategy.LatestMinor -> yield "STRATEGY: LATEST-MINOR"
5658
| Some ResolverStrategy.Max -> yield "STRATEGY: MAX"
5759
| None -> ()
5860
match options.ResolverStrategyForDirectDependencies with
5961
| Some ResolverStrategy.Min -> yield "LOWEST_MATCHING: TRUE"
6062
| Some ResolverStrategy.Max -> yield "LOWEST_MATCHING: FALSE"
63+
| Some x -> failwithf "Strategy %O is invalid as lowest_matching setting." x
6164
| None -> ()
6265
match options.Settings.CopyLocal with
6366
| Some x -> yield "COPY-LOCAL: " + x.ToString().ToUpper()
@@ -346,6 +349,8 @@ module LockFileParser =
346349
let setting =
347350
match trimmed.Trim() with
348351
| String.EqualsIC "min" -> Some ResolverStrategy.Min
352+
| String.EqualsIC "latest-patch" -> Some ResolverStrategy.LatestPatch
353+
| String.EqualsIC "latest-minor" -> Some ResolverStrategy.LatestMinor
349354
| String.EqualsIC "max" -> Some ResolverStrategy.Max
350355
| _ -> None
351356

Diff for: tests/Paket.Tests/Lockfile/ParserSpecs.fs

+28
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,34 @@ NUGET
670670
packages.Length |> shouldEqual 1
671671
lockFile.Options.ResolverStrategyForTransitives |> shouldEqual (Some ResolverStrategy.Max)
672672

673+
[<Test>]
674+
let ``should parse strategy latest-patch lock file``() =
675+
let lockFile = """STRATEGY: LATEST-PATCH
676+
NUGET
677+
remote: "D:\code\temp with space"
678+
specs:
679+
Castle.Windsor (2.1)
680+
"""
681+
let lockFile = LockFileParser.Parse(toLines lockFile) |> List.head
682+
let packages = List.rev lockFile.Packages
683+
684+
packages.Length |> shouldEqual 1
685+
lockFile.Options.ResolverStrategyForTransitives |> shouldEqual (Some ResolverStrategy.LatestPatch)
686+
687+
[<Test>]
688+
let ``should parse strategy latest-minor lock file``() =
689+
let lockFile = """STRATEGY: LATEST-MINOR
690+
NUGET
691+
remote: "D:\code\temp with space"
692+
specs:
693+
Castle.Windsor (2.1)
694+
"""
695+
let lockFile = LockFileParser.Parse(toLines lockFile) |> List.head
696+
let packages = List.rev lockFile.Packages
697+
698+
packages.Length |> shouldEqual 1
699+
lockFile.Options.ResolverStrategyForTransitives |> shouldEqual (Some ResolverStrategy.LatestMinor)
700+
673701
[<Test>]
674702
let ``should parse no strategy lock file``() =
675703
let lockFile = """NUGET

0 commit comments

Comments
 (0)