Fix mod SptVersion to be a range (#605)

* Fix mod SptVersion to be a range
- SptVersion and ModDependencies now use a Range instead of a set version
- Remove IsValid and IsValidRange checks from ModValidator, as invalid values will fail to parse into the strong types before this method is called
- Remove unused "AnySatisfies" and "IsValid*" methods from ISemVer
- Update TestMod to use Range types

* Formatting

---------

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
This commit is contained in:
DrakiaXYZ
2025-10-07 08:56:48 -07:00
committed by GitHub
parent 3e576a1143
commit c756479239
5 changed files with 14 additions and 36 deletions
+3 -5
View File
@@ -1,4 +1,5 @@
using Version = SemanticVersioning.Version;
using Range = SemanticVersioning.Range;
using Version = SemanticVersioning.Version;
namespace SPTarkov.Common.Semver;
@@ -8,8 +9,5 @@ public interface ISemVer
string MaxSatisfying(IEnumerable<Version> versions);
string MaxSatisfying(string version, List<Version> versions);
string MaxSatisfying(string version, IEnumerable<Version> versions);
bool Satisfies(Version version, Version testVersion);
bool AnySatisfies(Version version, List<Version> testVersions);
bool IsValid(Version version);
bool IsValidRange(Version version);
bool Satisfies(Version version, Range testRange);
}
@@ -26,23 +26,8 @@ public class SemanticVersioningSemVer : ISemVer
return Range.MaxSatisfying(version, versionRanges, true);
}
public bool Satisfies(Version version, Version testVersion)
public bool Satisfies(Version version, Range testRange)
{
return Range.IsSatisfied(testVersion.ToString(), version.ToString(), true);
}
public bool AnySatisfies(Version version, List<Version> testVersions)
{
return testVersions.Any(v => Satisfies(version, v));
}
public bool IsValid(Version version)
{
return Version.TryParse(version.ToString(), out _);
}
public bool IsValidRange(Version version)
{
return Range.TryParse(version.ToString(), out _);
return testRange.IsSatisfied(version, true);
}
}
@@ -1,4 +1,5 @@
using Version = SemanticVersioning.Version;
using Range = SemanticVersioning.Range;
using Version = SemanticVersioning.Version;
namespace SPTarkov.Server.Core.Models.Spt.Mod;
@@ -42,13 +43,13 @@ public abstract record AbstractModMetadata
public abstract Version Version { get; init; }
/// <summary>
/// SPT version this mod was built for, this uses the semver standard: https://semver.org/
/// SPT version this mod was built for, this uses the semver standard constraints: https://semver.org/
/// <br/><br/>
/// Version = new Version("4.0.0"); is valid
/// Version = new Version("~4.0.0"); is valid
/// <br/>
/// Version = new Version("4.0.0.0"); is not
/// </summary>
public abstract Version SptVersion { get; init; }
public abstract Range SptVersion { get; init; }
/// <summary>
/// List of mods not compatible with this mod
@@ -60,7 +61,7 @@ public abstract record AbstractModMetadata
///
/// Mod dependency is the key, version is the value
/// </summary>
public abstract Dictionary<string, Version>? ModDependencies { get; init; }
public abstract Dictionary<string, Range>? ModDependencies { get; init; }
/// <summary>
/// Link to this mod's mod page, or GitHub page
-7
View File
@@ -126,13 +126,6 @@ public class ModValidator(ISptLogger<ModValidator> logger, ServerLocalisationSer
var sptVersion = ProgramStatics.SPT_VERSION();
var modName = $"{mod.Author}-{mod.Name}";
// Error and prevent loading if sptVersion property is not a valid semver string
if (!(semVer.IsValid(mod.SptVersion) || semVer.IsValidRange(mod.SptVersion)))
{
logger.Error(localisationService.GetText("modloader-invalid_sptversion_field", modName));
return false;
}
// Warning and allow loading if semver is not satisfied
if (!semVer.Satisfies(sptVersion, mod.SptVersion))
{
+3 -2
View File
@@ -3,6 +3,7 @@ using SPTarkov.Server.Core.DI;
using SPTarkov.Server.Core.Models.Spt.Mod;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Web;
using Range = SemanticVersioning.Range;
using Version = SemanticVersioning.Version;
namespace TestMod;
@@ -14,9 +15,9 @@ public record TestModMetadata : AbstractModMetadata, IModWebMetadata
public override string Author { get; init; } = "SPTarkov";
public override List<string>? Contributors { get; init; }
public override Version Version { get; init; } = new("1.0.0");
public override Version SptVersion { get; init; } = new("~4.0.0");
public override Range SptVersion { get; init; } = new("~4.0.0");
public override List<string>? Incompatibilities { get; init; }
public override Dictionary<string, Version>? ModDependencies { get; init; }
public override Dictionary<string, Range>? ModDependencies { get; init; }
public override string? Url { get; init; }
public override bool? IsBundleMod { get; init; }
public override string License { get; init; } = "MIT";