MCPcopy Index your code
hub / github.com/colbymchenry/codegraph / buildWindowsUpgradeScript

Function buildWindowsUpgradeScript

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

Source from the content-addressed store, hash-verified

436
437/** Build the in-place Windows upgrade script (exported for unit-testing). */
438export function buildWindowsUpgradeScript(bundleRoot: string, version: string, arch: string): string {
439 const target = `win32-${arch}`;
440 const url = `https://github.com/${REPO}/releases/download/${version}/codegraph-${target}.zip`;
441 // Windows can't DELETE a running exe but CAN rename it, so we upgrade IN
442 // PLACE: download → rename the locked node.exe aside → extract the new bundle
443 // over current\. Synchronous, no detached helper (which dies under SSH/job
444 // objects and has worse UX). The running process keeps its renamed node.exe
445 // mapped; the NEXT `codegraph` invocation uses the new one. We can't reuse
446 // install.ps1 here — it `Remove-Item`s current\, which fails on the locked exe.
447 return [
448 `$ErrorActionPreference='Stop'`,
449 `$dest='${bundleRoot}'`,
450 `$url='${url}'`,
451 `Write-Host "Downloading $url"`,
452 `$tmp=Join-Path $env:TEMP ('cg-up-'+[guid]::NewGuid().ToString('N'))`,
453 `New-Item -ItemType Directory -Force -Path $tmp | Out-Null`,
454 `$zip=Join-Path $tmp 'cg.zip'`,
455 `Invoke-WebRequest -Uri $url -OutFile $zip`,
456 `$stage=Join-Path $tmp 'stage'`,
457 `Expand-Archive -Path $zip -DestinationPath $stage -Force`,
458 `$inner=Join-Path $stage 'codegraph-${target}'`,
459 `$src=if(Test-Path $inner){$inner}else{$stage}`,
460 `$node=Join-Path $dest 'node.exe'`,
461 `if(Test-Path $node){Rename-Item -Path $node -NewName ('node.exe.old-'+[guid]::NewGuid().ToString('N')) -Force}`,
462 `Copy-Item -Path (Join-Path $src '*') -Destination $dest -Recurse -Force`,
463 `Get-ChildItem -Path $dest -Filter 'node.exe.old-*' -ErrorAction SilentlyContinue | ForEach-Object { try { Remove-Item $_.FullName -Force -ErrorAction Stop } catch {} }`,
464 `Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue`,
465 `Write-Host "Installed CodeGraph ${version} to $dest"`,
466 ].join(';');
467}
468
469function upgradeWindowsBundle(
470 method: Extract<InstallMethod, { kind: 'bundle' }>,

Callers 2

upgrade.test.tsFile · 0.90
upgradeWindowsBundleFunction · 0.85

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected