From 4d08f515817531a54978539584a79068fad157aa Mon Sep 17 00:00:00 2001 From: fangliquanflq Date: Tue, 18 Aug 2026 17:37:50 +0800 Subject: [PATCH] fix(install): reject prerelease Node toolchains --- scripts/install.ps1 | 7 ++++--- scripts/install.sh | 5 +++-- tests-js/node-engine-alignment.test.ts | 20 ++++++++++++++------ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/scripts/install.ps1 b/scripts/install.ps1 index f790c4ff39..3a8f49d665 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -1649,8 +1649,9 @@ function Set-GitBashEnvVar { # with the root package.json. function Test-NodeVersionOk { param([string]$Version) + if ($Version -match '-') { return $false } try { - $v = [version]($Version -replace '^v', '' -replace '-.*$', '') + $v = [version]($Version -replace '^v', '') } catch { return $false } @@ -3992,8 +3993,8 @@ function Install-Desktop { # Always re-resolve Node here. Stages run in separate PowerShell processes, # so $script:HasNode from Stage-Node isn't visible; more importantly Test-Node - # enforces the build floor (Node >=22.22.0) and prepends the Hermes-managed - # Node to PATH, so the build never runs on a too-old system Node -- the cause + # enforces the supported Node lines and prepends the Hermes-managed Node to + # PATH, so the build never runs on an unsupported system Node -- the cause # of the opaque "Build desktop app ... exit code 1" failure (Vite crashes on # old Node). Test-Node | Out-Null diff --git a/scripts/install.sh b/scripts/install.sh index 67e326842e..6bc89d5d7e 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -889,6 +889,7 @@ check_cxx_compiler() { # replaced with the Hermes-managed Node $NODE_VERSION. node_satisfies_build() { local ver="${1#v}" + case "$ver" in *-*) return 1 ;; esac local major="${ver%%.*}" local minor="${ver#*.}"; minor="${minor%%.*}" case "$major" in ''|*[!0-9]*) return 1 ;; esac @@ -3218,8 +3219,8 @@ install_desktop() { # failure, not a silent skip — a silent skip yields a "complete" install # with no app and a confusing "couldn't find a built desktop" at launch. # Always re-resolve Node here. Stages run in separate processes, so we can't - # trust an earlier check; more importantly check_node now enforces the build - # floor (Node >=26) and prepends the Hermes-managed Node to PATH, so + # trust an earlier check; more importantly check_node now enforces the + # supported Node lines and prepends the Hermes-managed Node to PATH, so # the build never runs on a too-old system Node — the cause of the opaque # "Build desktop app … exit code 1" failure (Vite crashes on old Node). check_node diff --git a/tests-js/node-engine-alignment.test.ts b/tests-js/node-engine-alignment.test.ts index eadd2e0b5e..98c62500cd 100644 --- a/tests-js/node-engine-alignment.test.ts +++ b/tests-js/node-engine-alignment.test.ts @@ -58,12 +58,9 @@ function satisfiesClause(version: string, clause: string): boolean { } function satisfiesRange(version: string, range: string): boolean { - return range.split('||').some(alternative => - alternative - .trim() - .split(/\s+/) - .every(clause => satisfiesClause(version, clause)) - ) + const alternatives = range.split('||').map(alternative => alternative.trim().split(/\s+/)) + alternatives.flat().forEach(clause => satisfiesClause(version, clause)) + return alternatives.some(clauses => clauses.every(clause => satisfiesClause(version, clause))) } const rootManifest = readJson('package.json') @@ -96,4 +93,15 @@ describe('Node engine alignment', () => { assert.equal(nodeRange(lockfile.packages?.[''] ?? {}, 'root lock entry'), rootRange) assert.equal(nodeRange(lockfile.packages?.['apps/desktop'] ?? {}, 'desktop lock entry'), desktopRange) }) + + test.each(['~22.22.0', '22.x', '>=26.0.0-rc.1'])( + 'the alignment helper rejects unsupported semver clause %s instead of misclassifying it', + clause => { + assert.throws(() => satisfiesRange('26.0.0', clause), /unsupported semver clause/) + } + ) + + test('unsupported clauses are rejected even after a matching alternative', () => { + assert.throws(() => satisfiesRange('26.0.0', '>=26.0.0 || ~28.0.0'), /unsupported semver clause/) + }) })