Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dependency override is not handled correctly when DependencyType is set to PSGalleryModule in PSDependOptions #131

Open
WiredSharp opened this issue Jun 8, 2021 · 2 comments

Comments

@WiredSharp
Copy link

Considering the following dependencies:

$dependencies = @{
    PSDependOptions = @{
        Target = '.\Tmp'
        AddToPath = $True
        DependencyType = 'PSGalleryModule'
        Parameters = @{
            Repository = 'LOPublic'
        }
    }

    PsDepend = @{
        Version = 'latest'
        Parameters = @{}
    }
}

If you call Get-Dependency -InputObject $dependencies

Parsed dependency is:

(...)
Name            : PsDepend
Version         : {Version, Parameters}
PSDependOptions : {AddToPath, DependencyType, Parameters, Target}
Raw             :

As you can see, the whole hashtable is used as version field value. Indeed the Parse-Dependency function in Get-Dependency.ps1 considers that when DependencyType is set to 'PSGalleryModule' in PSDependOptions, the dependency value is a string.
A solution is to always take into account the type of the $Dependencyhash variable.

@GreatTeacherBasshead
Copy link

The problem is quite simple. Get-Dependency.ps1, line:283:

            elseif( $DependencyHash -is [string] -and
                $Dependency -notmatch '/' -and
                -not $DependencyType -or
                $DependencyType -eq 'PSGalleryModule')

This condition evaluates to $true even when $DependencyHash is hashtable and $DependencyType is PSGalleryModule, because of not using parenthesis in complex conditions. The fix is quite simple also:

            elseif( $DependencyHash -is [string] -and
                $Dependency -notmatch '/' -and
                (-not $DependencyType -or $DependencyType -eq 'PSGalleryModule'))

There are multiple places having this bug for different dependency types in the file.

Actually I wanted to use this Package... I have not found any good alternatives to PSDepend. And I would like to submit a PR with the fix... But, it seems, the project is dead. The latest Package update on PSGallery was more than 1 year ago. And I'm not sure that new fixes will be available on PSGallery soon.
That's really sad.

@TechDufus
Copy link

The problem is quite simple. Get-Dependency.ps1, line:283:

            elseif( $DependencyHash -is [string] -and
                $Dependency -notmatch '/' -and
                -not $DependencyType -or
                $DependencyType -eq 'PSGalleryModule')

This condition evaluates to $true even when $DependencyHash is hashtable and $DependencyType is PSGalleryModule, because of not using parenthesis in complex conditions. The fix is quite simple also:

            elseif( $DependencyHash -is [string] -and
                $Dependency -notmatch '/' -and
                (-not $DependencyType -or $DependencyType -eq 'PSGalleryModule'))

There are multiple places having this bug for different dependency types in the file.

Actually I wanted to use this Package... I have not found any good alternatives to PSDepend. And I would like to submit a PR with the fix... But, it seems, the project is dead. The latest Package update on PSGallery was more than 1 year ago. And I'm not sure that new fixes will be available on PSGallery soon. That's really sad.

Any thoughts on someone Publishing a new PSDepend module from a fork that is maintained? o.O

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants