diff --git a/CHANGELOG.md b/CHANGELOG.md index fb01fbc..aaa0e86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `Get-Dependency -InputObject` no longer mutates the caller's hashtable: + `PSDependOptions` is now preserved after the call, so a second invocation + with the same object still honors global options such as `Target` (#35). + ## [0.4.1] - 2026-06-12 ### Added diff --git a/PSDepend/Public/Get-Dependency.ps1 b/PSDepend/Public/Get-Dependency.ps1 index 96f1544..b1935cc 100644 --- a/PSDepend/Public/Get-Dependency.ps1 +++ b/PSDepend/Public/Get-Dependency.ps1 @@ -437,7 +437,7 @@ elseif ($PSCmdlet.ParameterSetName -eq 'Hashtable') { $DependencyFile = 'Hashtable' $ParsedDependencies = foreach ($InputDependency in $InputObject) { - $Dependencies = $InputDependency + $Dependencies = $InputDependency.Clone() Parse-Dependency -ParamSet $PSCmdlet.ParameterSetName } diff --git a/Tests/PSDepend.Tests.ps1 b/Tests/PSDepend.Tests.ps1 index c7c094d..4bf53cd 100644 --- a/Tests/PSDepend.Tests.ps1 +++ b/Tests/PSDepend.Tests.ps1 @@ -119,6 +119,27 @@ Describe "Get-Dependency PS$PSVersion" -Tag 'Unit' { $Dependencies | Should -BeNullOrEmpty } + It 'Does not mutate the caller''s InputObject — PSDependOptions key survives after Get-Dependency' { + $inputObj = @{ + PSDependOptions = @{ Target = 'CurrentUser' } + Pester = 'latest' + } + $null = Get-Dependency -InputObject $inputObj + $inputObj.ContainsKey('PSDependOptions') | Should -Be $True + } + + It 'Does not mutate the caller''s InputObject — PSDependOptions honored on a second Get-Dependency call' { + $inputObj = @{ + PSDependOptions = @{ Target = 'CurrentUser' } + Pester = 'latest' + } + $null = Get-Dependency -InputObject $inputObj + $deps2 = Get-Dependency -InputObject $inputObj + $inputObj.ContainsKey('PSDependOptions') | Should -Be $True + $inputObj.PSDependOptions.Target | Should -Be 'CurrentUser' + ($deps2 | Where-Object DependencyName -eq 'Pester').Target | Should -Be 'CurrentUser' + } + It 'Parses -InputObject hashtable as PSGalleryModule by default' { $Dependencies = Get-Dependency -InputObject @{ Pester = 'latest' } $Dependencies.DependencyName | Should -Be 'Pester'