diff --git a/scripts/install.ps1 b/scripts/install.ps1 index bdee3ac5e1b..a596137a77e 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -1837,6 +1837,106 @@ function Install-NodeDeps { } } +function Initialize-ElectronBuilderCache { + # Pre-warm electron-builder's winCodeSign cache so it never tries to + # extract the .7z archive itself. + # + # The bug we're working around: winCodeSign-2.6.0.7z contains macOS + # symbolic links under darwin/10.12/lib/ (libcrypto.dylib, libssl.dylib + # pointing at versioned siblings). On Windows, 7-Zip's extraction of + # those symlinks requires SeCreateSymbolicLinkPrivilege — a per-user + # right that non-admin accounts on stock Windows don't have. So + # electron-builder fails the extraction every time it pulls a fresh + # cache, on every grandma-class box. + # + # The fix: do the extraction ourselves with `-x!darwin` to skip the + # entire macOS subtree. electron-builder is doing a WINDOWS build — + # it never reads anything under darwin/ on this code path. As long + # as the cache directory exists with the Windows-relevant files, + # electron-builder's "is the cache present?" check passes and it + # skips its own extraction entirely. + # + # Tooling: we use 7za.exe from the 7zip-bin npm package that + # electron-builder itself depends on (so we know it's present after + # the workspace `npm install` finishes). Falls back to no-op if + # neither is found — electron-builder will then attempt its own + # broken extraction and fail with a recognizable error. + + $cacheRoot = "$env:LOCALAPPDATA\electron-builder\Cache\winCodeSign" + $extractedDir = "$cacheRoot\winCodeSign-2.6.0" + $sentinel = "$extractedDir\windows-10\x64\signtool.exe" + + # Fast-path: already populated from a prior run. + if (Test-Path $sentinel) { + Write-Info "electron-builder winCodeSign cache already populated" + return + } + + # Locate 7za.exe. electron-builder hoists 7zip-bin to the workspace + # root node_modules so apps/desktop's pack step can find it. + $sevenZip = "$InstallDir\node_modules\7zip-bin\win\x64\7za.exe" + if (-not (Test-Path $sevenZip)) { + # Some npm versions don't hoist; check apps/desktop's local copy. + $sevenZip = "$InstallDir\apps\desktop\node_modules\7zip-bin\win\x64\7za.exe" + } + if (-not (Test-Path $sevenZip)) { + Write-Warn "7za.exe not found in node_modules; electron-builder may fail to extract winCodeSign" + Write-Warn " Looked at: $InstallDir\node_modules\7zip-bin\win\x64\7za.exe" + Write-Warn " and: $InstallDir\apps\desktop\node_modules\7zip-bin\win\x64\7za.exe" + return + } + + New-Item -ItemType Directory -Force -Path $cacheRoot | Out-Null + + # Download to a TEMP path; electron-builder doesn't care about the + # archive itself once the extracted dir exists. + $tmpArchive = "$env:TEMP\hermes-wincodesign-$(Get-Random).7z" + $url = "https://github.com/electron-userland/electron-builder-binaries/releases/download/winCodeSign-2.6.0/winCodeSign-2.6.0.7z" + + Write-Info "Pre-extracting winCodeSign to skip electron-builder's broken extraction..." + try { + Invoke-WebRequest -Uri $url -OutFile $tmpArchive -UseBasicParsing -ErrorAction Stop + } catch { + Write-Warn "Failed to download winCodeSign: $_" + Write-Warn " electron-builder will fall back to its own extraction (which fails on non-admin Windows)" + return + } + + # 7-Zip flags: + # x extract with full paths + # -y assume yes on all prompts + # -bd no progress bar (silent) + # -snl do NOT extract symbolic links as links — store as the + # resolved file content instead. This is what stops the + # privilege-not-held crash on the darwin/*.dylib symlinks. + # -x!darwin exclude the entire darwin/ subtree (macOS-specific + # code-signing tools that a Windows build doesn't need) + # -o