JustinGrote / ModuleFast

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

Command added to my Profile throws errors on load #4

Closed ninmonkey closed 8 months ago

ninmonkey commented 1 year ago

At first I thought it your PSModulePath covered this, but then the profile code broke.

Summary

After it writes to my profile, and restart wt, the profile code throws this error

$env:PSModulePath: The term '$env:PSModulePath' is not recognized as a name of a cmdlet, function, script file, or executable program.
# The module is installed correctly
> Test-Path C:\Users\cppmo_000\AppData\Local\powershell\Modules\ugit
True
impo C:\Users\cppmo_000\AppData\Local\powershell\Modules\ugit\0.4.0\ugit.psd1
 # loads..

Code added to the profile:

if ('$Destination' -notin ($env:PSModulePath.split([IO.Path]::PathSeparator))) { `$env:PSModulePath = '$Destination' + $([IO.Path]::PathSeparator + $env:PSModulePath) } <#Added by ModuleFast. DO NOT EDIT THIS LINE. If you do not want this, add -NoProfileUpdate to Install-ModuleFast or add the default destination to your powershell.config.json or to your PSModulePath another way.#>

which runs as

image

Before running, I have:

Path Exists
C:\Users\cppmo_000\SkyDrive\Documents\PowerShell\Modules True
C:\Users\cppmo_000\AppData\Local\powershell True
C:\Users\cppmo_000\AppData\Local\powershell\Modules False

image

image

Location of Exception

Cannot find path 'C:\Users\cppmo_000\AppData\Local\powershell\Modules' because it does not exist.
C:\Users\cppmo_000\SkyDrive\Documents\PowerShell\Modules\ModuleFast\0.0.4\ModuleFast.psm1:60 char:25
                           +     [string]$Destination = Resolve-Path $Destination
ninmonkey commented 1 year ago

In case it helps, here's the full contents

$Env:PSModulePath = @(
    $Env:PSModulePath
    $toAdd = gi 'E:\PSModulePath.2023.root\Main' # assume this exists
) | Join-String -sep ([IO.Path]::PathSeparator)

# $Profile.CurrentUserAllHosts: shared (all3): VSCode, VSCode Debug Term, and windows term (external)

if($global:__nin_enableTraceVerbosity) { "⊢🐸 ↪ enter Pid: '$pid' `"$PSCommandPath`". source: VsCode, term: regular, prof: AllUsersCurrentHost" | Write-Warning; }[Collections.Generic.List[Object]]$global:__ninPathInvokeTrace ??= @(); $global:__ninPathInvokeTrace.Add($PSCommandPath); <# 2023.02 #>

. (Get-Item -ea 'continue' (Join-Path $Env:Nin_Dotfiles 'pwsh/profile.ps1'))

if($global:__nin_enableTraceVerbosity) { "⊢🐸 ↩ exit  Pid: '$pid' `"$PSCommandPath`". source: VsCode, term: regular, prof: AllUsersCurrentHost" | Write-Warning; }[Collections.Generic.List[Object]]$global:__ninPathInvokeTrace ??= @(); $global:__ninPathInvokeTrace.Add($PSCommandPath); <# 2023.02 #>

 if ('$Destination' -notin ($env:PSModulePath.split([IO.Path]::PathSeparator))) { `$env:PSModulePath = '$Destination' + $([IO.Path]::PathSeparator + $env:PSModulePath) } <#Added by ModuleFast. DO NOT EDIT THIS LINE. If you do not want this, add -NoProfileUpdate to Install-ModuleFast or add the default destination to your powershell.config.json or to your PSModulePath another way.#> 
JustinGrote commented 8 months ago

@ninmonkey I'll have a release soon that should fix this, you can try the instructions in README to test the latest MAIN version and see if it still happens.

JustinGrote commented 8 months ago

@ninmonkey should be fixed, though it may cause a duplicate profile entry now as I think the format changed slightly. If you have your destination in your PSModulePath, already, it should skip the profile add step.

Let me know if not and we can reopen.