diff --git a/PSFramework.NuGet/PSFramework.NuGet.psd1 b/PSFramework.NuGet/PSFramework.NuGet.psd1 index 1a445e9..dd2c564 100644 --- a/PSFramework.NuGet/PSFramework.NuGet.psd1 +++ b/PSFramework.NuGet/PSFramework.NuGet.psd1 @@ -3,7 +3,7 @@ RootModule = 'PSFramework.NuGet.psm1' # Version number of this module. - ModuleVersion = '0.9.0' + ModuleVersion = '0.9.2' # ID used to uniquely identify this module GUID = 'ad0f2a25-552f-4dd6-bd8e-5ddced2a5d88' diff --git a/PSFramework.NuGet/changelog.md b/PSFramework.NuGet/changelog.md index 79dd119..21d94f8 100644 --- a/PSFramework.NuGet/changelog.md +++ b/PSFramework.NuGet/changelog.md @@ -1,5 +1,10 @@ # Changelog +## 0.9.2 (2025-01-17) + ++ Fix: Get-PSFRepository - writes error when searching for a specific repository that only exists in one PSGet version ++ Fix: Update-PSFRepository - will update the "Trusted" status of a configured repository, even if the base properties have not yet been configured + ## 0.9.0 (2025-01-03) + Initial Preview Release diff --git a/PSFramework.NuGet/functions/Repository/Get-PSFRepository.ps1 b/PSFramework.NuGet/functions/Repository/Get-PSFRepository.ps1 index 2a9aea4..56f9e16 100644 --- a/PSFramework.NuGet/functions/Repository/Get-PSFRepository.ps1 +++ b/PSFramework.NuGet/functions/Repository/Get-PSFRepository.ps1 @@ -44,7 +44,8 @@ } process { if ($script:psget.V3 -and $Type -in 'All','V3') { - foreach ($repository in Get-PSResourceRepository -Name $Name) { + foreach ($repository in Get-PSResourceRepository -Name $Name -ErrorAction Ignore) { + if (-not $repository) { continue } [PSCustomObject]@{ PSTypeName = 'PSFramework.NuGet.Repository' Name = $repository.Name @@ -63,7 +64,8 @@ if (-not $script:psget.v2CanPublish) { $status = 'NoPublish' } if (-not $script:psget.v2CanInstall) { $status = 'NoInstall' } - foreach ($repository in Get-PSRepository -Name $Name) { + foreach ($repository in Get-PSRepository -Name $Name -ErrorAction Ignore) { + if (-not $repository) { continue } [PSCustomObject]@{ PSTypeName = 'PSFramework.NuGet.Repository' Name = $repository.Name diff --git a/PSFramework.NuGet/functions/Repository/Update-PSFRepository.ps1 b/PSFramework.NuGet/functions/Repository/Update-PSFRepository.ps1 index 14c5759..1ad784a 100644 --- a/PSFramework.NuGet/functions/Repository/Update-PSFRepository.ps1 +++ b/PSFramework.NuGet/functions/Repository/Update-PSFRepository.ps1 @@ -54,88 +54,93 @@ $supportedTypes = 'Any', 'Update', 'All', 'V2', 'V2Preferred', 'V3' foreach ($configuredRepo in $Configured) { - # Incomplete configurations are ignored (e.g. just storing credentials) - if (-not $configuredRepo.Type -or -not $configuredRepo.Uri) { continue } + # Incomplete configurations are processed in a limited manner, as not enough information is present to create or delete + $isIncomplete = -not $configuredRepo.Type -or -not $configuredRepo.Uri - if ($configuredRepo.Type -notin $supportedTypes) { + if (-not $isIncomplete -and $configuredRepo.Type -notin $supportedTypes) { Write-PSFMessage -Level Warning -String 'Update-PSFRepository.Error.InvalidType' -StringValues $configuredRepo.Type, ($supportedTypes -join ', ') continue } $matching = $Actual | Where-Object Name -EQ $configuredRepo._Name - $shouldExist = -not ($configuredRepo.PSObject.Properties.Name -contains 'Present' -and -not $configuredRepo.Present) + # An incomplete configuration can only be used to modify an existing repository, so skip if nothing matches + if ($isIncomplete -and -not $matching) { continue } - $mayBeV2 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V2', 'V2Preferred' - if ('Update' -eq $configuredRepo.Type -and $script:psget.V3) { $mayBeV2 = $false } - $mustBeV2 = $configuredRepo.Type -in 'All', 'V2' - $mayBeV3 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V3', 'V2Preferred' - if ('V2Preferred' -eq $configuredRepo.Type -and $script:psget.V2) { $mayBeV3 = $false } - $mustBeV3 = $configuredRepo.Type -in 'Update', 'All', 'V3' + if (-not $isIncomplete) { + $shouldExist = -not ($configuredRepo.PSObject.Properties.Name -contains 'Present' -and -not $configuredRepo.Present) - # Case: Should not exist and does not - if (-not $shouldExist -and -not $matching) { - continue - } + $mayBeV2 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V2', 'V2Preferred' + if ('Update' -eq $configuredRepo.Type -and $script:psget.V3) { $mayBeV2 = $false } + $mustBeV2 = $configuredRepo.Type -in 'All', 'V2' + $mayBeV3 = $configuredRepo.Type -in 'Any', 'Update', 'All', 'V3', 'V2Preferred' + if ('V2Preferred' -eq $configuredRepo.Type -and $script:psget.V2) { $mayBeV3 = $false } + $mustBeV3 = $configuredRepo.Type -in 'Update', 'All', 'V3' - #region Deletion - foreach ($matchingRepo in $matching) { - if ( - # Should exist - $shouldExist -and - ( - $matchingRepo.Type -eq 'V2' -and $mayBeV2 -or - $matchingRepo.Type -eq 'V3' -and $mayBeV3 - ) - ) { + # Case: Should not exist and does not + if (-not $shouldExist -and -not $matching) { continue } - [PSCustomObject]@{ - Type = 'Delete' - Configured = $configuredRepo - Actual = $matchingRepo - Changes = @{ } + #region Deletion + foreach ($matchingRepo in $matching) { + if ( + # Should exist + $shouldExist -and + ( + $matchingRepo.Type -eq 'V2' -and $mayBeV2 -or + $matchingRepo.Type -eq 'V3' -and $mayBeV3 + ) + ) { + continue + } + + [PSCustomObject]@{ + Type = 'Delete' + Configured = $configuredRepo + Actual = $matchingRepo + Changes = @{ } + } } - } - if (-not $shouldExist) { continue } - #endregion Deletion + if (-not $shouldExist) { continue } + #endregion Deletion - #region Creation - # Case: Should exist but does not - if ($shouldExist -and -not $matching) { - [PSCustomObject]@{ - Type = 'Create' - Configured = $configuredRepo - Actual = $null - Changes = @{ } + #region Creation + # Case: Should exist but does not + if ($shouldExist -and -not $matching) { + [PSCustomObject]@{ + Type = 'Create' + Configured = $configuredRepo + Actual = $null + Changes = @{ } + } + continue } - continue - } - # Case: Must exist on V2 but does not - if ($mustBeV2 -and $matching.Type -notcontains 'V2' -and $script:psget.V2) { - [PSCustomObject]@{ - Type = 'Create' - Configured = $configuredRepo - Actual = $matching - Changes = @{ } + # Case: Must exist on V2 but does not + if ($mustBeV2 -and $matching.Type -notcontains 'V2' -and $script:psget.V2) { + [PSCustomObject]@{ + Type = 'Create' + Configured = $configuredRepo + Actual = $matching + Changes = @{ } + } } - } - # Case: Must exist on V3 but does not - if ($mustBeV3 -and $matching.Type -notcontains 'V3' -and $script:psget.V3) { - [PSCustomObject]@{ - Type = 'Create' - Configured = $configuredRepo - Actual = $matching - Changes = @{ } + # Case: Must exist on V3 but does not + if ($mustBeV3 -and $matching.Type -notcontains 'V3' -and $script:psget.V3) { + [PSCustomObject]@{ + Type = 'Create' + Configured = $configuredRepo + Actual = $matching + Changes = @{ } + } } + + # If there is no matching, existing repository, there is no need to update + if (-not $matching) { continue } + #endregion Creation } - # If there is no matching, existing repository, there is no need to update - if (-not $matching) { continue } - #endregion Creation - #region Update foreach ($matchingRepo in $matching) { $intendedUri = $configuredRepo.Uri @@ -147,7 +152,7 @@ if ($null -eq $trusted) { $trusted = $true } $changes = @{ } - if ($matchingRepo.Uri -ne $intendedUri) { $changes.Uri = $intendedUri } + if (-not $isIncomplete -and $matchingRepo.Uri -ne $intendedUri) { $changes.Uri = $intendedUri } if ($matchingRepo.Trusted -ne $trusted) { $changes.Trusted = $trusted -as [bool] } if ( $configuredRepo.Priority -and @@ -208,10 +213,10 @@ $uri = $Change.Configured.Uri -replace 'v3/index.json$', 'v2' $param = @{ - Name = $Change.Configured._Name - SourceLocation = $uri + Name = $Change.Configured._Name + SourceLocation = $uri PublishLocation = $uri - ErrorAction = 'Stop' + ErrorAction = 'Stop' } if ($trusted) { $param.InstallationPolicy = 'Trusted' } if ($Change.Configured.Proxy) { $param.Proxy = $Change.Configured.Proxy } @@ -222,9 +227,9 @@ } if ($registerV3) { $param = @{ - Name = $Change.Configured._Name - Uri = $Change.Configured.Uri - Trusted = $trusted + Name = $Change.Configured._Name + Uri = $Change.Configured.Uri + Trusted = $trusted ErrorAction = 'Stop' } if ($null -ne $Change.Configured.Priority) {