Skip to content

Commit 0ecd58d

Browse files
committed
add semantic comparision of apax packages
- packages defined in apax.yml and .apax folder are now compared taking into accoun ^ and ~
1 parent 950b6c3 commit 0ecd58d

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

src/AXSharp.compiler/src/AXSharp.Compiler/AxProject.cs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,50 @@ private static IEnumerable<string> SearchForApaxFiles(string directory, int curr
160160
return apaxFilesList;
161161
}
162162

163+
static bool AreVersionsCompatible(string v1, string v2)
164+
{
165+
var versionA = ParseVersion(v1);
166+
var versionB = ParseVersion(v2);
167+
168+
if (v1.StartsWith("^") || v2.StartsWith("^"))
169+
{
170+
if (versionA.Major == 0 || versionB.Major == 0)
171+
{
172+
// Compare both major and minor for versions starting with 0
173+
return versionA.Major == versionB.Major && versionA.Minor == versionB.Minor;
174+
}
175+
else
176+
{
177+
// Compare only major for other versions
178+
return versionA.Major == versionB.Major;
179+
}
180+
}
181+
else if (v1.StartsWith("~") || v2.StartsWith("~"))
182+
{
183+
// Compare both major and minor for tilde versions
184+
return versionA.Major == versionB.Major && versionA.Minor == versionB.Minor;
185+
}
186+
else
187+
{
188+
// Direct version comparison if no symbol is used
189+
return versionA.Equals(versionB);
190+
}
191+
}
192+
193+
static Version ParseVersion(string versionString)
194+
{
195+
// Check for caret or tilde and remove it
196+
if (versionString.StartsWith("^") || versionString.StartsWith("~"))
197+
{
198+
versionString = versionString.Substring(1);
199+
}
200+
201+
// Parsing version string and creating a Version object
202+
return Version.Parse(versionString);
203+
}
204+
205+
206+
163207
private IEnumerable<object> GetProjectDependencies()
164208
{
165209
var dependencies = ProjectInfo.Dependencies ?? new Dictionary<string, string>();
@@ -184,7 +228,7 @@ private IEnumerable<object> GetProjectDependencies()
184228
foreach (var dependency in dependencies)
185229
{
186230
var hasSuchProject =
187-
nearByProjects.FirstOrDefault(p => p.Apax.Name == dependency.Key && p.Apax.Version == dependency.Value);
231+
nearByProjects.FirstOrDefault(p => p.Apax.Name == dependency.Key && AreVersionsCompatible(p.Apax.Version, dependency.Value));
188232
if (hasSuchProject != null)
189233
{
190234
var pathAXSharpConfig =
@@ -199,7 +243,7 @@ private IEnumerable<object> GetProjectDependencies()
199243
foreach (var dependency in dependencies)
200244
{
201245
var dependencyWithCompanion = installedDependencies
202-
.FirstOrDefault(p => p.Apax != null && p.Apax.Name == dependency.Key && p.Apax.Version == dependency.Value);
246+
.FirstOrDefault(p => p.Apax != null && p.Apax.Name == dependency.Key && AreVersionsCompatible(p.Apax.Version, dependency.Value));
203247

204248

205249
if (dependencyWithCompanion?.Companion != null)

0 commit comments

Comments
 (0)