Skip to content

Commit af2322b

Browse files
committed
Fix fallback in Install-PSPackage on Windows
1 parent 45e37a5 commit af2322b

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/scripts/win32.ps1

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,20 @@ Function Install-PSPackage() {
203203
$cmdlet
204204
)
205205
$module_path = "$bin_dir\$psm1_path.psm1"
206-
if(-not (Test-Path $module_path -PathType Leaf)) {
207-
$zip_file = "$bin_dir\$package.zip"
208-
Get-File -Url $url -OutFile $zip_file
209-
Expand-Archive -Path $zip_file -DestinationPath $bin_dir -Force
210-
}
211-
Import-Module $module_path
212-
if($null -eq (Get-Command $cmdlet -ErrorAction SilentlyContinue)) {
213-
Install-Module -Name $package -Force
214-
} else {
206+
$imported = $false
207+
try {
208+
if(-not (Test-Path $module_path -PathType Leaf)) {
209+
$zip_file = "$bin_dir\$package.zip"
210+
Get-File -Url $url -OutFile $zip_file
211+
Expand-Archive -Path $zip_file -DestinationPath $bin_dir -Force -ErrorAction Stop
212+
}
213+
Import-Module $module_path -ErrorAction Stop
214+
$imported = $null -ne (Get-Command $cmdlet -ErrorAction SilentlyContinue)
215+
} catch { }
216+
if($imported) {
215217
Add-ToProfile $current_profile "$package-search" "Import-Module $module_path"
218+
} else {
219+
Install-Module -Name $package -Force
216220
}
217221
}
218222

0 commit comments

Comments
 (0)