JustinGrote / ModuleFast

A "fast and loose" way to install modules from Powershell Gallery quickly. Meant for CICD, not production
Other
74 stars 5 forks source link

CurrentUser does not operate consistently #64

Closed trackd closed 6 months ago

trackd commented 6 months ago

Hey,

was testing this out a bit,

I was just curious if this wouldnt make more sense to be changed,

Install-ModuleFast -Name Az.CosmosDB -Destination CurrentUser
WARNING: Parameter -Destination is set to a custom path not in your current PSModulePath. We will add it to your PSModulePath for this session. You can suppress this behavior with the -NoPSModulePathUpdate switch.

# it needs to be 
Install-ModuleFast 'Az.CosmosDB' -Destination 'CurrentUser' -NoProfileUpdate -NoPSModulePathUpdate

But the implication when you choose 'CurrentUser' (on Windows)

elseif ($IsWindows -and $Destination -eq 'CurrentUser') {
      $windowsDefaultDocumentsPath = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'PowerShell/Modules'
      $Destination = $windowsDefaultDocumentsPath
      # so you could add
      $NoPSModulePathUpdate = $true
      $NoProfileUpdate = $true
}

That already means we do not need to update the $env:PSModulePath or the $Profile so could just disable the updates.


as i was typing this out i found the bug that was causing it. $PSModulePaths is not defined

    if (-not $NoPSModulePathUpdate) {
      if ($defaultRepoPath -ne $Destination -and $Destination -notin $PSModulePaths) {
        Write-Warning 'Parameter -Destination is set to a custom path not in your current PSModulePath. We will add it to your PSModulePath for this session. You can suppress this behavior with the -NoPSModulePathUpdate switch.'
        $NoProfileUpdate = $true
      }

just needs to add

    $PSModulePaths = $env:PSModulePath.Split([Path]::PathSeparator, [StringSplitOptions]::RemoveEmptyEntries)

to Install-ModuleFast function

could still set the values in the'CurrentUser' block so it skips NoPSModulePathUpdate check for that scenario.

JustinGrote commented 6 months ago

Good note, I don't think I actually did a test for CurrentUser, it was kind of an afterthought because one of the goals of modulefast is to not use that terrible Documents directory on windows due to all the onedrive sync issues. I'll consider fixing this up though.

trackd commented 6 months ago

the bug was not related to CurrentUser.

the "bug" is that $PSModulePaths is a nonexistant variable.

      if ($defaultRepoPath -ne $Destination -and $Destination -notin $PSModulePaths) {

i cannot find that variable in the code atleast. https://github.com/search?q=repo%3AJustinGrote%2FModuleFast%20%24PSModulePaths&type=code

so that will always be $true

i should probably have restructured my first post a bit.

my point regarding CurrentUser was that would allow for similar syntax as Install-Module/Install-PSResource

I'll consider fixing this up though.

i can submit a pr if you prefer.

JustinGrote commented 6 months ago

oh probably just a goof on my part. If you want to PR it I'll definitely review it

JustinGrote commented 6 months ago

Try it with the latest commit instructions: https://github.com/JustinGrote/ModuleFast?tab=readme-ov-file#testing-latest-commit