From 5c629bc726183d1fbf3b981638658d3a18c49dd1 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 12 Aug 2026 05:37:50 +0000 Subject: [PATCH] fix: install.ps1 persists PATH instead of printing manual instructions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the Windows installer only printed manual PATH instructions — including a setx suggestion that would bake the merged Machine+User PATH into the User value and truncate anything over 1024 chars. Now it appends the install dir to the user PATH via [Environment]::SetEnvironmentVariable (User scope only, no setx), prepends it to $env:Path for the current session, and keeps a manual PowerShell one-liner only as a fallback when the write throws. Membership check is case-insensitive and tolerant of trailing backslashes. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01Kr1tfSNy6gvd6vwwD2vayo --- install/install.ps1 | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/install/install.ps1 b/install/install.ps1 index 0c6cebc..3c9cc8a 100644 --- a/install/install.ps1 +++ b/install/install.ps1 @@ -3,7 +3,7 @@ # irm https://polylane.com/install.ps1 | iex # # Installs the bundled CLI to $env:USERPROFILE\.polylane\bin\ and (if needed) -# prints the line to add to your PATH. Node 20+ must be installed. +# adds it to your user PATH. Node 20+ must be installed. # Override the version or install prefix with env vars: # # $env:POLYLANE_VERSION='v0.1.0'; irm https://polylane.com/install.ps1 | iex @@ -24,6 +24,23 @@ function Die([string]$msg) { function Info([string]$msg) { Write-Host $msg -ForegroundColor DarkGray } function Ok([string]$msg) { Write-Host "✓ $msg" -ForegroundColor Green } +# True if $PathString (a ';'-separated PATH value) already contains $Dir, +# comparing case-insensitively and ignoring trailing backslashes. +function Test-PathHasDir([string]$PathString, [string]$Dir) { + $norm = $Dir.TrimEnd('\') + foreach ($entry in ($PathString -split ';')) { + if ($entry -and ($entry.TrimEnd('\') -ieq $norm)) { return $true } + } + return $false +} + +# Returns $PathString with $Dir appended (unchanged if already present). +function Add-DirToPath([string]$PathString, [string]$Dir) { + if (Test-PathHasDir $PathString $Dir) { return $PathString } + if ([string]::IsNullOrWhiteSpace($PathString)) { return $Dir } + return $PathString.TrimEnd(';') + ';' + $Dir +} + # --- preflight -------------------------------------------------------------- $node = Get-Command node -ErrorAction SilentlyContinue @@ -83,15 +100,26 @@ try { # non-fatal — user can still run it manually } -# --- PATH hint ------------------------------------------------------------- +# --- PATH ------------------------------------------------------------------- +# Persist $PrefixDir on the user PATH (never setx — it truncates long PATHs, +# and never the merged Machine+User value — only the User value is rewritten). $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') -if ($userPath -notlike "*$PrefixDir*") { - Write-Host '' - Info "Add $PrefixDir to your PATH:" - Write-Host " setx PATH `"$PrefixDir;%PATH%`"" - Info 'Or set permanently with PowerShell:' - Write-Host " [Environment]::SetEnvironmentVariable('Path', '$PrefixDir;' + [Environment]::GetEnvironmentVariable('Path','User'), 'User')" +if (-not (Test-PathHasDir $userPath $PrefixDir)) { + try { + [Environment]::SetEnvironmentVariable('Path', (Add-DirToPath $userPath $PrefixDir), 'User') + Ok "added $PrefixDir to your PATH" + Info 'New terminals pick it up automatically.' + } catch { + Info "could not add $PrefixDir to your PATH automatically ($_)" + Info 'Add it yourself with PowerShell:' + Write-Host " [Environment]::SetEnvironmentVariable('Path', '$PrefixDir;' + [Environment]::GetEnvironmentVariable('Path','User'), 'User')" + } +} + +# Make `polylane` work in this session too, without a restart. +if (-not (Test-PathHasDir $env:Path $PrefixDir)) { + $env:Path = "$PrefixDir;$env:Path" } Write-Host ''