JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.38k stars 2.38k forks source link

[PowerShell 7] Az.Accounts module is loaded even if a theme doesn't contain Azure blocks #642

Closed joshtransient closed 3 years ago

joshtransient commented 3 years ago

Prerequisites

Description

I load a theme that doesn't contain Azure or Azure Functions blocks, and the Az.Accounts module loads regardless. With PowerShell 7+, this prevents loading any other module that relies on a different version of MSAL.NET to do authentication. Can a check be added to only load Az.Accounts if a theme uses it?

Environment

Steps to Reproduce

  1. Open PowerShell -noprofile
  2. Import-Module oh-my-posh
  3. Try to Import-Module any module that uses MSAL.NET (e.g. MSAL.PS
  4. Receive error "Import-Module: Assembly with same name is already loaded"

Expected behavior: No error message

Actual behavior: Error message from step (4) above

JanDeDobbeleer commented 3 years ago

@joshtransient I don't want to open the jar of parsing the config in Powershell. You can however set $env:AZ_ENABLED=$false to avoid the module being loaded.

JanDeDobbeleer commented 3 years ago

@joshtransient any update on your end?

joshtransient commented 3 years ago

Env variable works. I'll close it

gibwar commented 3 years ago

Ended up coming to the same conclusion, for some reason, Get-AzContext takes 1 to 3 seconds to run and it was absolutely killing performance and driving me insane (thinking the Git perf issues came back). If we don't want to open the can of worms (which I understand), can we add something to the install docs mentioning that, if you have the Az module installed and you do not use the Az segment, it'd be worth your time to disable support?

JanDeDobbeleer commented 3 years ago

@gibwar where would you look for that information?

gibwar commented 3 years ago

I was originally thinking on the pwsh section, but that may be too narrow, since I guess it could happen on other platforms (though I only use pwsh on Windows). Since I know there have been issues past with outdated Git versions and slowness and whatnot, maybe a troubleshooting page may be beneficial?

Putting it on the Azure segment wouldn't make sense, since I am not using it, I wouldn't have looked there. The way I ended up identifying the cause was originally wrapping the prompt function with stopwatch calls to see the 3s lag, then running Write-PoshDebug was about 100ms (on a Git repo), and eventually added Set-PSDebug -Trace 2 to see the calls inside Initialize-ModuleSupport where the delay occurred.

https://github.com/JanDeDobbeleer/oh-my-posh/blob/016d981baa73629daae1ebd97db55b92a68657b5/src/init/omp.ps1#L39-L48

JanDeDobbeleer commented 3 years ago

@gibwar FAQ section coming

github-actions[bot] commented 6 months ago

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.