Skip to content

Commit 6551944

Browse files
authored
Handle prerelease module version specifications (#603)
1 parent e04925d commit 6551944

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/DependencyManagement/InstalledDependenciesLocator.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ private bool IsAcceptableVersionInstalled(string snapshotPath, DependencyManifes
3838
{
3939
case VersionSpecificationType.ExactVersion:
4040
return _storage.IsModuleVersionInstalled(
41-
snapshotPath, dependency.Name, dependency.VersionSpecification);
41+
snapshotPath, dependency.Name, dependency.VersionSpecification)
42+
|| _storage.IsModuleVersionInstalled(
43+
snapshotPath, dependency.Name, StripVersionPostfix(dependency.VersionSpecification));
4244

4345
case VersionSpecificationType.MajorVersion:
4446
return IsMajorVersionInstalled(
@@ -49,6 +51,13 @@ private bool IsAcceptableVersionInstalled(string snapshotPath, DependencyManifes
4951
}
5052
}
5153

54+
private string StripVersionPostfix(string versionSpecification)
55+
{
56+
const char PostfixSeparator = '-';
57+
var separatorPos = versionSpecification.IndexOf(PostfixSeparator);
58+
return separatorPos == -1 ? versionSpecification : versionSpecification.Substring(0, separatorPos);
59+
}
60+
5261
private bool IsMajorVersionInstalled(string snapshotPath, string name, string majorVersion)
5362
{
5463
var installedVersions = _storage.GetInstalledModuleVersions(snapshotPath, name, majorVersion);

test/Unit/DependencyManagement/InstalledDependenciesLocatorTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,39 @@ public void ReturnsNull_WhenExactModuleVersionIsNotInstalled()
8686

8787
Assert.Null(result);
8888
}
89+
90+
// Any version with a postfix starting with '-' will be considered a preview version.
91+
// Preview versions may be installed into a folder with the base version name, without the postfix
92+
// (for example '4.0.2-preview' may be installed into a folder with the name '4.0.2'),
93+
// so we need to take this into account and look for both.
94+
[Theory]
95+
[InlineData("-preview")]
96+
[InlineData("-alfa")]
97+
[InlineData("-prerelease")]
98+
[InlineData("-anything")]
99+
public void ReturnsLatestSnapshotPath_WhenPreviewVersionInstalled(string postfix)
100+
{
101+
var baseVersion = "4.0.2";
102+
var fullVersion = baseVersion + postfix;
103+
104+
DependencyManifestEntry[] dependencyManifestEntries =
105+
{
106+
new DependencyManifestEntry("A", VersionSpecificationType.ExactVersion, fullVersion)
107+
};
108+
109+
_mockStorage.Setup(_ => _.GetDependencies()).Returns(dependencyManifestEntries);
110+
111+
_mockStorage.Setup(_ => _.GetLatestInstalledSnapshot()).Returns("snapshot");
112+
113+
// No exact match...
114+
_mockStorage.Setup(_ => _.IsModuleVersionInstalled("snapshot", "A", fullVersion)).Returns(false);
115+
// ...but the base version is here
116+
_mockStorage.Setup(_ => _.IsModuleVersionInstalled("snapshot", "A", baseVersion)).Returns(true);
117+
118+
var installedDependenciesLocator = new InstalledDependenciesLocator(_mockStorage.Object);
119+
var result = installedDependenciesLocator.GetPathWithAcceptableDependencyVersionsInstalled();
120+
121+
Assert.Equal("snapshot", result);
122+
}
89123
}
90124
}

0 commit comments

Comments
 (0)