-
Notifications
You must be signed in to change notification settings - Fork 525
/
FindOutdated.fs
88 lines (73 loc) · 4.12 KB
/
FindOutdated.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/// Contains methods to find outdated packages.
module Paket.FindOutdated
open Paket.Domain
open Paket.Logging
open Chessie.ErrorHandling
open System.IO
let private adjustVersionRequirements strict includingPrereleases (dependenciesFile: DependenciesFile) =
let adjust (packageRequirement:Requirements.PackageRequirement) =
let versionRequirement,strategy =
match strict,includingPrereleases with
| true,true -> VersionRequirement.NoRestriction, packageRequirement.ResolverStrategyForTransitives
| true,false -> packageRequirement.VersionRequirement, packageRequirement.ResolverStrategyForTransitives
| false,true ->
match packageRequirement.VersionRequirement with
| VersionRequirement(v,_) -> VersionRequirement.VersionRequirement(v,PreReleaseStatus.All), Some ResolverStrategy.Max
| false,false -> VersionRequirement.AllReleases, Some ResolverStrategy.Max
{ packageRequirement with VersionRequirement = versionRequirement; ResolverStrategyForTransitives = strategy}
let groups =
dependenciesFile.Groups
|> Map.map (fun groupName group -> { group with Packages = group.Packages |> List.map adjust })
DependenciesFile(dependenciesFile.FileName, groups, dependenciesFile.Lines)
/// Finds all outdated packages.
let FindOutdated strict force includingPrereleases groupNameFilter environment = trial {
let! lockFile = environment |> PaketEnv.ensureLockFileExists
let dependenciesFile =
environment.DependenciesFile
|> adjustVersionRequirements strict includingPrereleases
let getSha1 origin owner repo branch auth = RemoteDownload.getSHA1OfBranch origin owner repo branch auth |> Async.RunSynchronously
let root = Path.GetDirectoryName dependenciesFile.FileName
let alternativeProjectRoot = None
let getVersionsF parameters = async {
let! versions = NuGet.GetVersions force alternativeProjectRoot root parameters
return versions |> List.toSeq }
let getPreferredVersionsF resolverStrategy parameters = []
let dependenciesFile = UpdateProcess.detectProjectFrameworksForDependenciesFile dependenciesFile
let checkedDepsGroups =
match groupNameFilter with
| None -> dependenciesFile.Groups
| Some gname -> dependenciesFile.Groups |> Map.filter(fun k _ -> k = GroupName gname)
let newResolution = dependenciesFile.Resolve(force, getSha1, getVersionsF, getPreferredVersionsF, NuGet.GetPackageDetails alternativeProjectRoot root true, RuntimeGraph.getRuntimeGraphFromNugetCache root, checkedDepsGroups, PackageResolver.UpdateMode.UpdateAll)
let checkedLockGroups =
match groupNameFilter with
| None -> lockFile.Groups
| Some gname -> lockFile.Groups |> Map.filter(fun k g -> k.ToString() = gname)
let changed =
[for kv in checkedLockGroups do
match newResolution |> Map.tryFind kv.Key with
| Some group ->
let newPackages = group.ResolvedPackages.GetModelOrFail()
for kv' in kv.Value.Resolution do
let package = kv'.Value
match newPackages |> Map.tryFind package.Name with
| Some newVersion ->
if package.Version <> newVersion.Version then
yield kv.Key,package.Name,package.Version,newVersion.Version
| _ -> ()
| _ -> ()]
return changed
}
let private printOutdated changed =
if List.isEmpty changed then
tracefn "No outdated packages found."
else
tracefn "Outdated packages found:"
for groupName:GroupName,packages in changed |> List.groupBy (fun (g,_,_,_) -> g) do
tracefn " Group: %O" groupName
for _,packageName:PackageName,oldVersion,newVersion in packages do
tracefn " * %O %O -> %O" packageName oldVersion newVersion
/// Prints all outdated packages.
let ShowOutdated strict force includingPrereleases groupName environment = trial {
let! allOutdated = FindOutdated strict force includingPrereleases groupName environment
printOutdated allOutdated
}