Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/Process-PSModule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ jobs:
Process-PSModule:
uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@v1
secrets: inherit
with:
SkipTests: true
36 changes: 36 additions & 0 deletions src/PSSemVer/PSSemVer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Define the types to export with type accelerators.
$ExportableTypes = @(
[PSSemVer]
)
# Get the internal TypeAccelerators class to use its static methods.
$TypeAcceleratorsClass = [psobject].Assembly.GetType(
'System.Management.Automation.TypeAccelerators'
)
# Ensure none of the types would clobber an existing type accelerator.
# If a type accelerator with the same name exists, throw an exception.
$ExistingTypeAccelerators = $TypeAcceleratorsClass::Get
foreach ($Type in $ExportableTypes) {
if ($Type.FullName -in $ExistingTypeAccelerators.Keys) {
$Message = @(
"Unable to register type accelerator '$($Type.FullName)'"
'Accelerator already exists.'
) -join ' - '

throw [System.Management.Automation.ErrorRecord]::new(
[System.InvalidOperationException]::new($Message),
'TypeAcceleratorAlreadyExists',
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$Type.FullName
)
}
}
# Add type accelerators for every exportable type.
foreach ($Type in $ExportableTypes) {
$TypeAcceleratorsClass::Add($Type.FullName, $Type)
}
# Remove type accelerators when the module is removed.
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
foreach ($Type in $ExportableTypes) {
$TypeAcceleratorsClass::Remove($Type.FullName)
}
}.GetNewClosure()
2 changes: 1 addition & 1 deletion src/PSSemVer/PSSemVer.psd1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@{
ModuleVersion = '0.0.0'
ModuleVersion = '99.0.0'
}
6 changes: 3 additions & 3 deletions src/PSSemVer/classes/PSSemVer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
}

PSSemVer([version]$version) {
$this.Major = $version.Major -lt 0 ? 0 : $version.Major
$this.Minor = $version.Minor -lt 0 ? 0 : $version.Minor
$this.Patch = $version.Build -lt 0 ? 0 : $version.Build
$this.Major = if ($version.Major -lt 0) { 0 } else { $version.Major }
$this.Minor = if ($version.Minor -lt 0) { 0 } else { $version.Minor }
$this.Patch = if ($version.Build -lt 0) { 0 } else { $version.Build }
}
#endregion Constructors

Expand Down
2 changes: 1 addition & 1 deletion src/PSSemVer/public/ConvertTo-PSSemVer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
[string] $Version
)

if ($Version | IsNullOrEmpty) {
if ([string]::IsNullOrEmpty($Version)) {
return New-PSSemVer
}

Expand Down