From af2322b95c2e36d5287c7c25c4c29c8ccaacbb63 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 26 Apr 2026 23:49:26 +0530 Subject: [PATCH] Fix fallback in Install-PSPackage on Windows --- src/scripts/win32.ps1 | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 1fb43b2b..cfb6100c 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -203,16 +203,20 @@ Function Install-PSPackage() { $cmdlet ) $module_path = "$bin_dir\$psm1_path.psm1" - if(-not (Test-Path $module_path -PathType Leaf)) { - $zip_file = "$bin_dir\$package.zip" - Get-File -Url $url -OutFile $zip_file - Expand-Archive -Path $zip_file -DestinationPath $bin_dir -Force - } - Import-Module $module_path - if($null -eq (Get-Command $cmdlet -ErrorAction SilentlyContinue)) { - Install-Module -Name $package -Force - } else { + $imported = $false + try { + if(-not (Test-Path $module_path -PathType Leaf)) { + $zip_file = "$bin_dir\$package.zip" + Get-File -Url $url -OutFile $zip_file + Expand-Archive -Path $zip_file -DestinationPath $bin_dir -Force -ErrorAction Stop + } + Import-Module $module_path -ErrorAction Stop + $imported = $null -ne (Get-Command $cmdlet -ErrorAction SilentlyContinue) + } catch { } + if($imported) { Add-ToProfile $current_profile "$package-search" "Import-Module $module_path" + } else { + Install-Module -Name $package -Force } }