Skip to content

Commit aa9d47e

Browse files
authored
Merge pull request #3822 from marticliment/dependencies
2 parents b01c955 + d0cb1f5 commit aa9d47e

22 files changed

Lines changed: 259 additions & 10 deletions

File tree

src/UniGetUI.PAckageEngine.Interfaces/IPackageDetails.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,14 @@ public interface IPackageDetails
9494
/// </summary>
9595
/// <returns>An asynchronous task that can be awaited</returns>
9696
public Task Load();
97+
98+
public List<Dependency> Dependencies { get; }
99+
100+
public struct Dependency
101+
{
102+
public string Name;
103+
public string Version;
104+
public bool Mandatory;
105+
}
97106
}
98107
}

src/UniGetUI.PackageEngine.Enums/ManagerCapabilities.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public struct ManagerCapabilities
2525
public bool CanRemoveDataOnUninstall = false;
2626
public bool CanDownloadInstaller = false;
2727
public bool CanUninstallPreviousVersionsAfterUpdate = false;
28+
public bool CanListDependencies = false;
2829
public bool SupportsCustomVersions = false;
2930
public bool SupportsCustomArchitectures = false;
3031
public string[] SupportedCustomArchitectures = [];

src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public Chocolatey()
3232
CanSkipIntegrityChecks = true,
3333
CanRunInteractively = true,
3434
SupportsCustomVersions = true,
35+
CanListDependencies = true,
3536
SupportsCustomArchitectures = true,
3637
SupportedCustomArchitectures = [Architecture.x86],
3738
SupportsPreRelease = true,

src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public DotNet()
3030
SupportsCustomArchitectures = true,
3131
SupportedCustomArchitectures = [Architecture.x86, Architecture.x64, Architecture.arm64, Architecture.arm32],
3232
SupportsPreRelease = true,
33+
CanListDependencies = true,
3334
SupportsCustomLocations = true,
3435
SupportsCustomPackageIcons = true,
3536
SupportsCustomVersions = true,

src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGet.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@ public abstract class BaseNuGet : PackageManager
1818

1919
public sealed override void Initialize()
2020
{
21-
if (DetailsHelper is not BaseNuGetDetailsHelper)
21+
static void ThrowIC(string name)
2222
{
23-
throw new InvalidOperationException("NuGet-based package managers must not reassign the PackageDetailsProvider property");
23+
throw new InvalidOperationException($"NuGet-based package managers must have Capabilities.{name} set to true");
2424
}
2525

26-
if (!Capabilities.SupportsCustomVersions)
26+
if (DetailsHelper is not BaseNuGetDetailsHelper)
2727
{
28-
throw new InvalidOperationException("NuGet-based package managers must support custom versions");
28+
throw new InvalidOperationException("NuGet-based package managers must not reassign the PackageDetailsProvider property");
2929
}
3030

31-
if (!Capabilities.SupportsCustomPackageIcons)
32-
{
33-
throw new InvalidOperationException("NuGet-based package managers must support custom versions");
34-
}
31+
if (!Capabilities.SupportsCustomVersions) ThrowIC(nameof(Capabilities.SupportsCustomVersions));
32+
if (!Capabilities.SupportsCustomPackageIcons) ThrowIC(nameof(Capabilities.SupportsCustomPackageIcons));
33+
if (!Capabilities.CanListDependencies) ThrowIC(nameof(Capabilities.CanListDependencies));
3534

3635
base.Initialize();
3736
}

src/UniGetUI.PackageEngine.Managers.Generic.NuGet/BaseNuGetDetailsHelper.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ protected override void GetDetails_UnSafe(IPackageDetails details)
107107
break;
108108
}
109109

110+
details.Dependencies.Clear();
111+
foreach (Match match in Regex.Matches(PackageManifestContents,
112+
@"<d\:Dependencies>([^<]+)</d\:Dependencies>"))
113+
{
114+
foreach (var dep in match.Groups[1].ToString().Split('|'))
115+
{
116+
if(string.IsNullOrEmpty(dep))
117+
continue;
118+
else if (dep.StartsWith("::"))
119+
details.Dependencies.Add(new() { Name = dep.TrimStart(':'), Version = "", Mandatory = true });
120+
else
121+
details.Dependencies.Add(new()
122+
{
123+
Name = dep.Split(':')[0], Version = dep.Split(':')[1].TrimEnd(':'), Mandatory = true
124+
});
125+
}
126+
}
127+
128+
110129
logger.Close(0);
111130
return;
112131
}

src/UniGetUI.PackageEngine.Managers.Npm/Helpers/NpmPkgDetailsHelper.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,47 @@ protected override void GetDetails_UnSafe(IPackageDetails details)
6161

6262
details.InstallerHash = contents?["dist"]?["integrity"]?.ToString();
6363

64+
details.Dependencies.Clear();
65+
HashSet<string> addedDeps = new();
66+
foreach (var rawDep in (contents?["dependencies"]?.AsObject() ?? []))
67+
{
68+
if(addedDeps.Contains(rawDep.Key)) continue;
69+
addedDeps.Add(rawDep.Key);
70+
71+
details.Dependencies.Add(new()
72+
{
73+
Name = rawDep.Key,
74+
Version = rawDep.Value?.GetValue<string>() ?? "",
75+
Mandatory = true,
76+
});
77+
}
78+
79+
foreach (var rawDep in (contents?["devDependencies"]?.AsObject() ?? []))
80+
{
81+
if(addedDeps.Contains(rawDep.Key)) continue;
82+
addedDeps.Add(rawDep.Key);
83+
84+
details.Dependencies.Add(new()
85+
{
86+
Name = rawDep.Key,
87+
Version = rawDep.Value?.GetValue<string>() ?? "",
88+
Mandatory = false,
89+
});
90+
}
91+
92+
foreach (var rawDep in (contents?["peerDependencies"]?.AsObject() ?? []))
93+
{
94+
if(addedDeps.Contains(rawDep.Key)) continue;
95+
addedDeps.Add(rawDep.Key);
96+
97+
details.Dependencies.Add(new()
98+
{
99+
Name = rawDep.Key,
100+
Version = rawDep.Value?.GetValue<string>() ?? "",
101+
Mandatory = false,
102+
});
103+
}
104+
64105
logger.AddToStdErr(p.StandardError.ReadToEnd());
65106
p.WaitForExit();
66107
logger.Close(p.ExitCode);

src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public Npm()
2323
SupportsCustomVersions = true,
2424
CanDownloadInstaller = true,
2525
SupportsCustomScopes = true,
26+
CanListDependencies = true,
2627
SupportsPreRelease = true,
2728
SupportsProxy = ProxySupport.No,
2829
SupportsProxyAuth = false

src/UniGetUI.PackageEngine.Managers.Pip/Helpers/PipPkgDetailsHelper.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ protected override void GetDetails_UnSafe(IPackageDetails details)
5555
}
5656
details.Tags = Tags.ToArray();
5757
}
58+
59+
details.Dependencies.Clear();
60+
foreach (var rawDep in (info?["requires_dist"]?.AsArray() ?? []))
61+
{
62+
string line = rawDep?.GetValue<string>().Split(';')[0] ?? "";
63+
string name = line.Split(['>', '<', '=', '!'])[0];
64+
details.Dependencies.Add(new()
65+
{
66+
Name = name,
67+
Version = line[name.Length..],
68+
Mandatory = true,
69+
});
70+
}
5871
}
5972

6073
JsonObject? url = contents?["url"] as JsonObject;

src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public Pip()
5050
SupportsCustomScopes = true,
5151
CanDownloadInstaller = true,
5252
SupportsPreRelease = true,
53+
CanListDependencies = true,
5354
SupportsProxy = ProxySupport.Yes,
5455
SupportsProxyAuth = true
5556
};

0 commit comments

Comments
 (0)