MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / buildWindowsUpgradeScript

Function buildWindowsUpgradeScript

src/upgrade/index.ts:576–605  ·  view source on GitHub ↗
(bundleRoot: string, version: string, arch: string)

Source from the content-addressed store, hash-verified

574
575/** Build the in-place Windows upgrade script (exported for unit-testing). */
576export function buildWindowsUpgradeScript(bundleRoot: string, version: string, arch: string): string {
577 const target = `win32-${arch}`;
578 const url = `https://github.com/${REPO}/releases/download/${version}/codegraph-${target}.zip`;
579 // Windows can't DELETE a running exe but CAN rename it, so we upgrade IN
580 // PLACE: download → rename the locked node.exe aside → extract the new bundle
581 // over current\. Synchronous, no detached helper (which dies under SSH/job
582 // objects and has worse UX). The running process keeps its renamed node.exe
583 // mapped; the NEXT `codegraph` invocation uses the new one. We can't reuse
584 // install.ps1 here — it `Remove-Item`s current\, which fails on the locked exe.
585 return [
586 `$ErrorActionPreference='Stop'`,
587 `$dest='${bundleRoot}'`,
588 `$url='${url}'`,
589 `Write-Host "Downloading $url"`,
590 `$tmp=Join-Path $env:TEMP ('cg-up-'+[guid]::NewGuid().ToString('N'))`,
591 `New-Item -ItemType Directory -Force -Path $tmp | Out-Null`,
592 `$zip=Join-Path $tmp 'cg.zip'`,
593 `Invoke-WebRequest -Uri $url -OutFile $zip`,
594 `$stage=Join-Path $tmp 'stage'`,
595 `Expand-Archive -Path $zip -DestinationPath $stage -Force`,
596 `$inner=Join-Path $stage 'codegraph-${target}'`,
597 `$src=if(Test-Path $inner){$inner}else{$stage}`,
598 `$node=Join-Path $dest 'node.exe'`,
599 `if(Test-Path $node){Rename-Item -Path $node -NewName ('node.exe.old-'+[guid]::NewGuid().ToString('N')) -Force}`,
600 `Copy-Item -Path (Join-Path $src '*') -Destination $dest -Recurse -Force`,
601 `Get-ChildItem -Path $dest -Filter 'node.exe.old-*' -ErrorAction SilentlyContinue | ForEach-Object { try { Remove-Item $_.FullName -Force -ErrorAction Stop } catch {} }`,
602 `Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue`,
603 `Write-Host "Installed CodeGraph ${version} to $dest"`,
604 ].join(';');
605}
606
607function upgradeWindowsBundle(
608 method: Extract<InstallMethod, { kind: 'bundle' }>,

Callers 2

upgrade.test.tsFile · 0.90
upgradeWindowsBundleFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected