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

Function buildWindowsUpgradeScript

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

Source from the content-addressed store, hash-verified

779
780/** Build the in-place Windows upgrade script (exported for unit-testing). */
781export function buildWindowsUpgradeScript(bundleRoot: string, version: string, arch: string): string {
782 const target = `win32-${arch}`;
783 const url = `https://github.com/${REPO}/releases/download/${version}/codegraph-${target}.zip`;
784 // Synchronous, no detached helper (which dies under SSH/job objects and has
785 // worse UX). The bundle is unpacked into a sibling of current\ — the same
786 // volume, so the swap is renames, never a half-finished copy — and nothing
787 // in current\ changes until it is fully unpacked. The running process keeps
788 // its renamed node.exe mapped; the NEXT `codegraph` invocation uses the new
789 // one. Exit codes: 0 installed, 1 failed with the install unchanged,
790 // WINDOWS_UPGRADE_DAMAGED when the rollback could not restore every file.
791 return [
792 `$ErrorActionPreference='Stop'`,
793 // With no console to draw on (an agent, a pipe), PowerShell writes every
794 // progress update to stderr as CLIXML: about 30 KB for each megabyte
795 // downloaded, around the one line that says what went wrong (#3502).
796 `if ([Console]::IsOutputRedirected -or [Console]::IsErrorRedirected) { $ProgressPreference='SilentlyContinue' }`,
797 WINDOWS_SWAP_FUNCTION,
798 `$dest=${psQuote(bundleRoot)}`,
799 `$url=${psQuote(url)}`,
800 `$tmp=Join-Path $env:TEMP ('cg-up-'+[guid]::NewGuid().ToString('N'))`,
801 `$stage=Join-Path (Split-Path -Parent $dest) ('.staging-'+[guid]::NewGuid().ToString('N').Substring(0,8))`,
802 `$code=0`,
803 `try {`,
804 // Not Write-Host: with no console its text also goes to stderr as a CLIXML record.
805 ` [Console]::Out.WriteLine("Downloading $url")`,
806 ` New-Item -ItemType Directory -Force -Path $tmp | Out-Null`,
807 ` $zip=Join-Path $tmp 'cg.zip'`,
808 ` Invoke-WebRequest -Uri $url -OutFile $zip`,
809 ...IMPORT_OWN_ARCHIVE_MODULE.map((line) => ` ${line}`),
810 ` Expand-Archive -Path $zip -DestinationPath $stage -Force`,
811 ` $inner=Join-Path $stage 'codegraph-${target}'`,
812 ` Install-CodeGraphFiles $(if(Test-Path $inner){$inner}else{$stage}) $dest`,
813 ` [Console]::Out.WriteLine("Installed CodeGraph ${version} to $dest")`,
814 `} catch {`,
815 ` [Console]::Error.WriteLine($_.Exception.Message)`,
816 ` $code=if($_.Exception.Data['codegraphDamaged']){${WINDOWS_UPGRADE_DAMAGED}}else{1}`,
817 `}`,
818 `Remove-Item -LiteralPath $stage,$tmp -Recurse -Force -ErrorAction SilentlyContinue`,
819 `exit $code`,
820 ].join('\n');
821}
822
823function upgradeWindowsBundle(
824 method: Extract<InstallMethod, { kind: 'bundle' }>,

Callers 5

upgradeFunction · 0.90
upgrade.test.tsFile · 0.90
scriptFunction · 0.90
upgradeWindowsBundleFunction · 0.85

Calls 3

psQuoteFunction · 0.85
mapMethod · 0.80
joinMethod · 0.45

Tested by 2

upgradeFunction · 0.72
scriptFunction · 0.72