Skip to content

Commit e3da88c

Browse files
fix: add PS5.1 SemanticVersion shim for consistent Resolve-ModuleVersionString return type (#463)
Closes #460 ## Summary - `[System.Management.Automation.SemanticVersion]` is PS6+ only; on PS5.1 `Resolve-ModuleVersionString` was falling back to `[System.Version]`, causing two test assertions to fail - Adds `Plaster/Private/Initialize-SemanticVersion.ps1`: a top-level `Add-Type` shim that defines `System.Management.Automation.SemanticVersion` in C# when the native type is absent - Simplifies `Resolve-ModuleVersionString` to always construct `SemanticVersion` — the shim ensures the type exists on PS5.1 at module load time (alphabetical load order puts `Initialize-SemanticVersion` before `Resolve-ModuleVersionString`) - Tests require no changes ## Test plan - [ ] Run Pester suite on PS5.1 — both `Resolve-ModuleVersionString` tests pass - [ ] Run Pester suite on PS7 — no regression 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 64dc31c commit e3da88c

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
if (-not ([System.Management.Automation.PSTypeName]'System.Management.Automation.SemanticVersion').Type) {
2+
Add-Type -TypeDefinition @'
3+
namespace System.Management.Automation {
4+
public class SemanticVersion {
5+
public int Major { get; private set; }
6+
public int Minor { get; private set; }
7+
public int Patch { get; private set; }
8+
public SemanticVersion(string version) {
9+
var parts = version.Split('.');
10+
Major = int.Parse(parts[0]);
11+
Minor = parts.Length > 1 ? int.Parse(parts[1]) : 0;
12+
Patch = parts.Length > 2 ? int.Parse(parts[2]) : 0;
13+
}
14+
public override string ToString() {
15+
return Major + "." + Minor + "." + Patch;
16+
}
17+
}
18+
}
19+
'@
20+
}

Plaster/Private/Resolve-ModuleVersionString.ps1

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,9 @@ function Resolve-ModuleVersionString {
3636
$VersionString = "$VersionString.0"
3737
}
3838

39-
if ($PSVersionTable.PSEdition -eq "Core") {
40-
$newObjectSplat = @{
41-
TypeName = "System.Management.Automation.SemanticVersion"
42-
ArgumentList = $VersionString
43-
}
44-
return New-Object @newObjectSplat
45-
} else {
46-
$newObjectSplat = @{
47-
TypeName = "System.Version"
48-
ArgumentList = $VersionString
49-
}
50-
return New-Object @newObjectSplat
39+
$newObjectSplat = @{
40+
TypeName = "System.Management.Automation.SemanticVersion"
41+
ArgumentList = $VersionString
5142
}
43+
return New-Object @newObjectSplat
5244
}

0 commit comments

Comments
 (0)