Skip to content

Commit 05c01a5

Browse files
committed
Refactor + Tests for Get-ModuleExtension
1 parent e944909 commit 05c01a5

File tree

5 files changed

+3968
-134
lines changed

5 files changed

+3968
-134
lines changed

Plaster/Private/Get-ModuleExtension.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,18 @@ function Get-ModuleExtension {
6161

6262
Write-Verbose "Comparing against module extension: $($extension.Module)"
6363

64-
$minimumVersion = Resolve-ModuleVersionString $extension.MinimumVersion
65-
$maximumVersion = Resolve-ModuleVersionString $extension.MaximumVersion
64+
if ([String]::IsNullOrEmpty($extension.MinimumVersion)) {
65+
# Fill with a default value if not specified
66+
$minimumVersion = $null
67+
} else {
68+
$minimumVersion = Resolve-ModuleVersionString $extension.MinimumVersion
69+
}
70+
if ([String]::IsNullOrEmpty($extension.MaximumVersion)) {
71+
# Fill with a default value if not specified
72+
$maximumVersion = $null
73+
} else {
74+
$maximumVersion = Resolve-ModuleVersionString $extension.MaximumVersion
75+
}
6676

6777
if (($extension.Module -eq $ModuleName) -and
6878
(!$minimumVersion -or $ModuleVersion -ge $minimumVersion) -and

Plaster/Private/Resolve-ModuleVersionString.ps1

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,30 @@ function Resolve-ModuleVersionString {
2323
It is not intended for direct use outside of the Plaster context.
2424
#>
2525
param(
26-
[Parameter(Mandatory)]
26+
[Parameter(Mandatory, Position = 0)]
2727
[ValidateNotNullOrEmpty()]
28-
[string]
29-
$versionString
28+
$VersionString
3029
)
31-
$parsedVersion = $null
3230

33-
if ($versionString) {
34-
# We're targeting Semantic Versioning 2.0 so make sure the version has
35-
# at least 3 components (X.X.X). This logic ensures that the "patch"
36-
# (third) component has been specified.
37-
$versionParts = $versionString.Split('.')
38-
if ($versionParts.Length -lt 3) {
39-
$versionString = "$versionString.0"
40-
}
31+
# We're targeting Semantic Versioning 2.0 so make sure the version has
32+
# at least 3 components (X.X.X). This logic ensures that the "patch"
33+
# (third) component has been specified.
34+
$versionParts = $VersionString.Split('.')
35+
if ($versionParts.Length -lt 3) {
36+
$VersionString = "$VersionString.0"
37+
}
4138

42-
if ($PSVersionTable.PSEdition -eq "Core") {
43-
$newObjectSplat = @{
44-
TypeName = "System.Management.Automation.SemanticVersion"
45-
ArgumentList = $versionString
46-
}
47-
$parsedVersion = New-Object @newObjectSplat
48-
} else {
49-
$newObjectSplat = @{
50-
TypeName = "System.Version"
51-
ArgumentList = $versionString
52-
}
53-
$parsedVersion = New-Object @newObjectSplat
39+
if ($PSVersionTable.PSEdition -eq "Core") {
40+
$newObjectSplat = @{
41+
TypeName = "System.Management.Automation.SemanticVersion"
42+
ArgumentList = $VersionString
5443
}
44+
return New-Object @newObjectSplat
45+
} else {
46+
$newObjectSplat = @{
47+
TypeName = "System.Version"
48+
ArgumentList = $VersionString
49+
}
50+
return New-Object @newObjectSplat
5551
}
56-
57-
return $parsedVersion
5852
}

docs/en-US/Get-ModuleExtension.md

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)