From 72ab0f064f118820af757a1d19b2e48b2af8d9ef Mon Sep 17 00:00:00 2001 From: Benjamin Staneck Date: Sat, 24 Mar 2018 00:01:08 +0100 Subject: [PATCH] update psget to the latest version --- vendor/psmodules/PsGet/PsGet.psm1 | 81 ++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/vendor/psmodules/PsGet/PsGet.psm1 b/vendor/psmodules/PsGet/PsGet.psm1 index 1a2412f..ad3f886 100644 --- a/vendor/psmodules/PsGet/PsGet.psm1 +++ b/vendor/psmodules/PsGet/PsGet.psm1 @@ -9,8 +9,16 @@ #region Setup Write-Debug 'Set up the global scope config variables.' -$global:UserModuleBasePath = Join-Path -Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath 'WindowsPowerShell\Modules' -$global:CommonGlobalModuleBasePath = Join-Path -Path $env:CommonProgramFiles -ChildPath 'Modules' +if ([Environment]::GetFolderPath('MyDocuments')) { + $global:UserModuleBasePath = Join-Path -Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath 'WindowsPowerShell\Modules' +} +else { + # Support scenarios where PSGet is running without a MyDocuments special folder (e.g. executing within a DSC resource) + $global:UserModuleBasePath = Join-Path -Path $env:ProgramFiles -ChildPath 'WindowsPowerShell\Modules' +} + +# NOTE: Path changed to align with current MS conventions +$global:CommonGlobalModuleBasePath = Join-Path -Path $env:ProgramFiles -ChildPath 'WindowsPowerShell\Modules' if (-not (Test-Path -Path:variable:global:PsGetDirectoryUrl)) { $global:PsGetDirectoryUrl = 'https://github.com/psget/psget/raw/master/Directory.xml' @@ -96,16 +104,16 @@ Set-Variable -Name PSGET_PSD1 -Value 'PSD1' -Option Constant -Scope Script .PARAMETER DoNotPostInstall If defined, the PostInstallHook is not executed. - .PARAMERTER PostInstallHook + .PARAMETER PostInstallHook Defines the name of a script inside the installed module folder which should be executed after installation. Default: definition in directory file or 'Install.ps1' .PARAMETER Force - OBSOLATE + OBSOLETE Alternative name for 'Update'. .PARAMETER Startup - OBSOLATE + OBSOLETE Alternative name for 'AddToProfile'. .LINK @@ -349,7 +357,7 @@ function Install-Module { .PARAMETER DoNotPostInstall If defined, the PostInstallHook is not executed. - .PARAMERTER PostInstallHook + .PARAMETER PostInstallHook Defines the name of a script inside the installed module folder which should be executed after installation. Will not be check in combination with -All switch. Default: 'Install.ps1' @@ -414,7 +422,7 @@ function Update-Module { } else { - Install-Module -Module:$Module -Destination:$Destination -ModuleHash:$ModuleHash -Global:$Global -DoNotImport:$DoNotImport -AddToProfile:$AddToProfile -DirectoryUrl:$DirectoryUrl -Updat -DoNotPostInstall:$DoNotPostInstall -PostInstallHook:$PostInstallHook + Install-Module -Module:$Module -Destination:$Destination -ModuleHash:$ModuleHash -Global:$Global -DoNotImport:$DoNotImport -AddToProfile:$AddToProfile -DirectoryUrl:$DirectoryUrl -Update -DoNotPostInstall:$DoNotPostInstall -PostInstallHook:$PostInstallHook } } } @@ -480,7 +488,9 @@ function Get-PsGetModuleInfo { try { Write-Verbose "Downloading modules repository from $DirectoryUrl" - $repoRaw = $client.DownloadString($DirectoryUrl) + $stream = $client.OpenRead($DirectoryUrl) + $repoXmlTemp = New-Object -TypeName System.Xml.XmlDocument + $repoXmlTemp.Load($stream) $StatusCode = 200 } catch [System.Net.WebException] { @@ -489,7 +499,7 @@ function Get-PsGetModuleInfo { } if ($StatusCode -eq 200) { - $repoXml = [xml]$repoRaw + $repoXml = [xml]$repoXmlTemp $CacheEntry.ETag = $client.ResponseHeaders['ETag'] if (-not (Test-Path -Path $PsGetDataPath)) { @@ -629,7 +639,7 @@ function Get-PsGetModuleHash { .PARAMETER DoNotPostInstall If defined, the PostInstallHook is not executed. - .PARAMERTER PostInstallHook + .PARAMETER PostInstallHook Defines the name of a script inside the installed module folder which should be executed after installation. Default: definition in directory file or 'Install.ps1' #> @@ -754,7 +764,7 @@ function Install-ModuleFromDirectory { .PARAMETER DoNotPostInstall If defined, the PostInstallHook is not executed. - .PARAMERTER PostInstallHook + .PARAMETER PostInstallHook Defines the name of a script inside the installed module folder which should be executed after installation. Default: 'Install.ps1' #> @@ -863,7 +873,7 @@ function Install-ModuleFromWeb { .PARAMETER DoNotPostInstall If defined, the PostInstallHook is not executed. - .PARAMERTER PostInstallHook + .PARAMETER PostInstallHook Defines the name of a script inside the installed module folder which should be executed after installation. Default: 'Install.ps1' #> @@ -1010,7 +1020,7 @@ function Install-ModuleFromLocal { .PARAMETER DoNotPostInstall If defined, the PostInstallHook is not executed. - .PARAMERTER PostInstallHook + .PARAMETER PostInstallHook Defines the name of a script inside the installed module folder which should be executed after installation. Default: 'Install.ps1' #> @@ -1311,6 +1321,13 @@ function Import-ModuleGlobally { Write-Verbose "Importing installed module '$ModuleName' from '$($installedModule.ModuleBase)'" Import-Module -Name $ModuleBase -Global -Force:$Force + # For psget no further checks are needed and their execution cause + # an error for the update process of 'psget' + # https://github.com/psget/psget/issues/186 + if ($ModuleName -eq 'PsGet') { + return + } + $IdentityExtension = [System.IO.Path]::GetExtension((Get-ModuleFile -Path $ModuleBase -ModuleName $ModuleName)) if ($IdentityExtension -eq '.dll') { # import module twice for binary modules to workaround PowerShell bug: @@ -1514,7 +1531,7 @@ function Invoke-DownloadModuleFromWeb { .PARAMETER DoNotPostInstall If defined, the PostInstallHook is not executed. - .PARAMERTER PostInstallHook + .PARAMETER PostInstallHook Defines the name of a script inside the installed module folder which should be executed after installation. #> function Install-ModuleToDestination { @@ -1628,7 +1645,7 @@ function Install-ModuleToDestination { $isDestinationInPSModulePath = $env:PSModulePath.Contains($Destination) if ($isDestinationInPSModulePath) { - if (-not (Get-Module $ModuleName -ListAvailable)) { + if (-not (Get-Module $InstallWithModuleName -ListAvailable)) { throw 'For some unexpected reasons module was not installed.' } } @@ -1639,14 +1656,14 @@ function Install-ModuleToDestination { } if ($Update) { - Write-Host "Module $ModuleName was successfully updated." -Foreground Green + Write-Host "Module $InstallWithModuleName was successfully updated." -Foreground Green } else { - Write-Host "Module $ModuleName was successfully installed." -Foreground Green + Write-Host "Module $InstallWithModuleName was successfully installed." -Foreground Green } if (-not $DoNotImport) { - Import-ModuleGlobally -ModuleName:$ModuleName -ModuleBase:$targetFolderPath -Force:$Update + Import-ModuleGlobally -ModuleName:$InstallWithModuleName -ModuleBase:$targetFolderPath -Force:$Update } if ($isDestinationInPSModulePath -and $AddToProfile) { @@ -1657,8 +1674,8 @@ function Install-ModuleToDestination { New-Item $PROFILE -Type File -Force -ErrorAction Stop } - if (Select-String $PROFILE -Pattern "Import-Module $ModuleName") { - Write-Verbose "Import-Module $ModuleName command already in your profile" + if (Select-String $PROFILE -Pattern "Import-Module $InstallWithModuleName") { + Write-Verbose "Import-Module $InstallWithModuleName command already in your profile" } else { $signature = Get-AuthenticodeSignature -FilePath $PROFILE @@ -1667,8 +1684,8 @@ function Install-ModuleToDestination { Write-Error "PsGet cannot modify code-signed profile '$PROFILE'." } else { - Write-Verbose "Add Import-Module $ModuleName command to the profile" - "`nImport-Module $ModuleName" | Add-Content $PROFILE + Write-Verbose "Add Import-Module $InstallWithModuleName command to the profile" + "`nImport-Module $InstallWithModuleName" | Add-Content $PROFILE } } } @@ -1736,7 +1753,7 @@ function Test-ModuleInstalledAndImport { return $false } - Write-Warning "The module '$ModuleName' was installed at more then one location. Installed paths:`n`t$($installedModule.ModuleBase | Format-List | Out-String)`n'$($firstInstalledModule.ModuleBase)' is the searched destination." + Write-Warning "The module '$ModuleName' was installed at more than one location. Installed paths:`n`t$($installedModule.ModuleBase | Format-List | Out-String)`n'$($firstInstalledModule.ModuleBase)' is the searched destination." $installedModule = $targetModule } elseif ((Split-Path $installedModule.ModuleBase) -ne $Destination) { @@ -1801,7 +1818,7 @@ function Expand-ZipModule { # Check if powershell v3+ and .net v4.5 is available $netFailed = $true - if ( $PSVersionTable.PSVersion.Major -ge 3 -and (Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4' -Recurse | Get-ItemProperty -Name Version | Where-Object { $_.Version -like '4.5*' }) ) { + if ( $PSVersionTable.PSVersion.Major -ge 3 -and (Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4' -Recurse | Get-ItemProperty -Name Version | Where-Object { $_.Version -like '4.5*' -Or $_.Version -ge '4.5' }) ) { Write-Debug 'Attempting unzip using the .NET Framework...' try { @@ -1910,14 +1927,20 @@ function Invoke-DownloadNuGetPackage { } Write-Verbose "Querying '$Source' repository for package with Id '$NuGetPackageId'" - $Url = "{1}Packages()?`$filter=tolower(Id)+eq+'{0}'&`$orderby=Id" -f $NuGetPackageId.ToLower(), $Source - Write-Debug "NuGet query url: $Url" - try { + $Url = "{1}Packages()?`$filter=tolower(Id)+eq+'{0}'&`$orderby=Id" -f $NuGetPackageId.ToLower(), $Source + Write-Debug "Trying NuGet query url: $Url" $XmlDoc = [xml]$WebClient.DownloadString($Url) } catch { - throw "Unable to download from NuGet feed: $($_.Exception.InnerException.Message)" + try { + $Url = "{1}Packages(Id='{0}')?`$orderby=Id" -f $NuGetPackageId, $Source + Write-Debug "Trying NuGet query url: $Url" + $XmlDoc = [xml]$WebClient.DownloadString($Url) + } + catch { + throw "Unable to download from NuGet feed: $($_.Exception.InnerException.Message)" + } } if ($PackageVersion) { @@ -2110,7 +2133,7 @@ function TabExpansion { Get-PsGetModuleInfo -ModuleName "$lastword*" | % { $_.Id } | sort -Unique } elseif ( Test-Path -Path Function:\$tabExpansionBackup ) { - & $teBackup $line $lastWord + & $tabExpansionBackup $line $lastWord } } }