okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221desktop: Windows node.exe in the Tauri shell, hidden host console, and fetch-node.ps1 (win-x64, same SHA-256 pin as fetch-node.sh)8a11d125d

main
3.4 KiB72 linesraw
1# Fetch and verify the private Node runtime the Windows desktop bundle ships (win-x64).
2#
3# The PowerShell twin of fetch-node.sh: same pinned version, same SHA-256 pin, same refusal to
4# install anything whose digest does not match. Not committed output: node.exe is a ~90 MB binary.
5#
6# Usage:
7#   powershell -NoProfile -ExecutionPolicy Bypass -File apps\desktop\scripts\fetch-node.ps1
8#   ... -File fetch-node.ps1 -Check                  # verify what is already installed
9#   ... -File fetch-node.ps1 -FromFile node.zip      # verify and install a zip you already have (offline)
10#
11# The Node version must satisfy the App Host's own engines.node (>= 24.12.0).
12[CmdletBinding()]
13param(
14    [switch]$Check,
15    [string]$FromFile = '',
16    [string]$Dest = ''
17)
18$ErrorActionPreference = 'Stop'
19
20$NodeVersion = if ($env:STRATA_NODE_VERSION) { $env:STRATA_NODE_VERSION } else { '24.12.0' }
21$Target = 'win-x64'
22# SHA-256 of node-v24.12.0-win-x64.zip from nodejs.org's SHASUMS256.txt; keep equal to fetch-node.sh.
23$Expected = '9c125f61ae947b52e779095830f9cac267846a043ef7192183c84016aaad2812'
24if (-not $Dest) { $Dest = Join-Path $PSScriptRoot '..\src-tauri\resources\node' }
25$Installed = Join-Path $Dest 'node.exe'
26
27function Fail([string]$Message) { [Console]::Error.WriteLine("fetch-node: $Message"); exit 1 }
28
29if ($Check) {
30    if (-not (Test-Path -LiteralPath $Installed)) { Fail "not installed at $Installed" }
31    $got = (& $Installed --version).Trim()
32    Write-Output "fetch-node: $Installed is $got"
33    if ($got -ne "v$NodeVersion") { Fail "expected v$NodeVersion" }
34    exit 0
35}
36
37$Archive = "node-v$NodeVersion-$Target.zip"
38$Work = Join-Path ([IO.Path]::GetTempPath()) ("strata-node-" + [Guid]::NewGuid().ToString('N'))
39New-Item -ItemType Directory -Path $Work | Out-Null
40try {
41    $Zip = Join-Path $Work $Archive
42    if ($FromFile) {
43        Copy-Item -LiteralPath $FromFile -Destination $Zip
44    } else {
45        $Url = "https://nodejs.org/dist/v$NodeVersion/$Archive"
46        Write-Output "fetch-node: $Url"
47        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
48        $ProgressPreference = 'SilentlyContinue'
49        Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $Zip
50    }
51    $Actual = (Get-FileHash -Algorithm SHA256 -LiteralPath $Zip).Hash.ToLowerInvariant()
52    if ($NodeVersion -ne '24.12.0') {
53        # another version has no recorded digest: say so rather than implying a verification
54        [Console]::Error.WriteLine("fetch-node: WARNING - no recorded digest for v$NodeVersion; this download is NOT authenticated.")
55        [Console]::Error.WriteLine("fetch-node: computed sha256 $Actual - record it in this script and fetch-node.sh.")
56    } elseif ($Actual -ne $Expected) {
57        Fail "REFUSING - $Archive hashes $Actual, expected $Expected"
58    } else {
59        Write-Output 'fetch-node: sha256 verified against the recorded digest'
60    }
61    Add-Type -AssemblyName System.IO.Compression.FileSystem
62    $zipFile = [IO.Compression.ZipFile]::OpenRead($Zip)
63    try {
64        $entry = $zipFile.GetEntry("node-v$NodeVersion-$Target/node.exe")
65        if (-not $entry) { Fail "node.exe is not inside $Archive" }
66        New-Item -ItemType Directory -Force -Path $Dest | Out-Null
67        [IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $Installed, $true)
68    } finally { $zipFile.Dispose() }
69    Write-Output "fetch-node: installed at $Installed"
70} finally {
71    Remove-Item -LiteralPath $Work -Recurse -Force -ErrorAction SilentlyContinue
72}