PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
485 stars 92 forks source link

macOS: `-Scope CurrentUser` targets a directory not listed in `$env:PSModulePath` #1454

Closed mklement0 closed 10 months ago

mklement0 commented 11 months ago

Prerequisites

Steps to reproduce

On macOS, Install-PSResource -Scope CurrentUser (the default scope) targets "$HOME/Library/Application Support/powershell/Modules", which isn't in listed in $env:PSModulePath.

Therefore, user-scoped modules are simply unavailable (not discoverable) after installation.

Note that PowerShellGet 2.x targets "$HOME/.local/share/powershell/Modules", which is in $env:PSModulePath

Expected behavior

Either target "$HOME/.local/share/powershell/Modules", as before, or update PowerShell to to also include "$HOME/Library/Application Support/powershell/Modules" in $env:PSModulePath by default, so that user-scope-installed modules become available as expected.

Actual behavior

User-scope-installed modules aren't discoverable.

Error details

No response

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.0.0                 Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository, Get-PSScriptFileInfo…}

Name                           Value
----                           -----
PSVersion                      7.4.0-preview.6
PSEdition                      Core
GitCommitId                    7.4.0-preview.6
OS                             Darwin 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

alerickson commented 10 months ago

$HOME/.local/share/powershell/Modules is where it should be installing. See: https://github.com/PowerShell/PSResourceGet/blob/edd5ff4a0b2ef1ef294fe46d488e2a1ff8a50145/src/code/Utils.cs#L994

v1.0.0 is installing to that directory for me.

Can you try running Install-PSResource -Scope CurrentUser -Debug -Verbose and sharing the output?

mklement0 commented 10 months ago

On macOS (13.5.2), the value of [Environment]::GetFolderPath('LocalApplicationData') is (abstract form used; in PowerShell terms, it is "$HOME/Library/Application Support"):

~/Library/Application Support

and that is also what I see when I run your command:

VERBOSE: All paths to search: '/Users/jdoe/Library/Application Support/powershell/Modules'
VERBOSE: All paths to search: '/Users/jdoe/Library/Application Support/powershell/Scripts'
VERBOSE: Retrieving directories in the path '/Users/jdoe/Library/Application Support/powershell/Modules'
VERBOSE: Retrieving directories in the path '/Users/jdoe/Library/Application Support/powershell/Scripts'
DEBUG: In GetHelper::GetPackagesFromPath()
DEBUG: In GetHelper::FilterPkgPathsByName()
DEBUG: In GetHelper::FilterPkgPathsByVersion()
DEBUG: In InstallPSResource::ProcessInstallHelper()
DEBUG: In InstallHelper::BeginInstallPackages()
DEBUG: Parameters passed in >>> Name: 'classexplorer'; VersionRange: ''; NuGetVersion: ''; VersionType: 'NoVersion'; Version: ''; Prerelease: 'False'; Repository: ''; AcceptLicense: 'False'; Quiet: 'False'; Reinstall: 'False'; TrustRepository: 'False'; NoClobber: 'False'; AsNupkg: 'False'; IncludeXml 'True'; SavePackage 'False'; TemporaryPath ''; SkipDependencyCheck: 'False'; AuthenticodeCheck: 'False'; PathsToInstallPkg: '/Users/jdoe/Library/Application Support/powershell/Modules,/Users/jdoe/Library/Application Support/powershell/Scripts'; Scope 'CurrentUser'
DEBUG: In InstallHelper::ProcessRepositories()
VERBOSE: Attempting to search for packages in 'PSGallery'
DEBUG: In InstallHelper::InstallPackages()
DEBUG: In InstallHelper::InstallPackage()
DEBUG: In V2ServerAPICalls::FindName()
DEBUG: In V2ServerAPICalls::HttpRequestCall()
DEBUG: Request url is 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='classexplorer'&$inlinecount=allpages&$filter=IsLatestVersion and Id eq 'classexplorer''
SteveL-MSFT commented 10 months ago

I wonder if .NET made a change here, but the problem is that the path is not in $PSModulePath so the module isn't found

mklement0 commented 10 months ago

Bingo, @SteveL-MSFT: GetFolderPath behavior on Unix: "Starting in .NET 8, the behavior of Environment.GetFolderPath on Unix operating systems has changed."

alerickson commented 10 months ago

@SteveL-MSFT is PowerShell going to continue to use $HOME/.local/share/powershell/Modules or migrate to $HOME/Library/Application Support/powershell/Modules?