fix(setup): require Node 22.12 for sanitize-html

This commit is contained in:
Paul Nothaft
2026-09-07 09:00:01 +02:00
parent 65831785a2
commit e06d0b4513
3 changed files with 11 additions and 19 deletions
+1 -1
View File
@@ -71,7 +71,7 @@
"supertest": "^6.3.3" "supertest": "^6.3.3"
}, },
"engines": { "engines": {
"node": "^20.19.0 || >=22" "node": ">=22.12.0"
} }
}, },
"node_modules/@apidevtools/json-schema-ref-parser": { "node_modules/@apidevtools/json-schema-ref-parser": {
+1 -1
View File
@@ -4,7 +4,7 @@
"description": "Backend for PicPeak event photo sharing platform", "description": "Backend for PicPeak event photo sharing platform",
"main": "server.js", "main": "server.js",
"engines": { "engines": {
"node": "^20.19.0 || >=22.12.0" "node": ">=22.12.0"
}, },
"scripts": { "scripts": {
"start": "node server.js", "start": "node server.js",
+9 -17
View File
@@ -14,8 +14,8 @@ IFS=$'\n\t'
readonly SCRIPT_VERSION="2.1.0" readonly SCRIPT_VERSION="2.1.0"
readonly APP_NAME="PicPeak" readonly APP_NAME="PicPeak"
readonly REPO_URL="https://github.com/PicPeak/picpeak.git" readonly REPO_URL="https://github.com/PicPeak/picpeak.git"
readonly NODE_VERSION="20" readonly NODE_VERSION="22"
readonly NODE_MIN_VERSION="20.19.0" # backend engines: ^20.19.0 || >=22.12.0 (sharp 0.35, html-to-text 10; sanitize-html 2.17.7 needs require(esm), unflagged in 20.19 and 22.12) readonly NODE_MIN_VERSION="22.12.0" # backend engines: >=22.12.0 (sanitize-html 2.17.7)
readonly MIN_RAM_DOCKER=2048 readonly MIN_RAM_DOCKER=2048
readonly MIN_RAM_NATIVE=1024 readonly MIN_RAM_NATIVE=1024
readonly MIN_DISK_GB=2 readonly MIN_DISK_GB=2
@@ -822,17 +822,11 @@ EOF
# Native Installation # Native Installation
################################################################################ ################################################################################
# True when a Node.js version satisfies the backend's engines range # True when a Node.js version satisfies the backend's engines range (>=22.12.0).
# (^20.19.0 || >=22.12.0). 21.x is out, and so is 22.0-22.11.
node_version_supported() { node_version_supported() {
local ver="$1" major minor local ver="$1"
major="${ver%%.*}" [[ "$ver" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || return 1
minor="${ver#*.}"; minor="${minor%%.*}" [[ "$(printf '%s\n' "$NODE_MIN_VERSION" "$ver" | sort -V | head -1)" == "$NODE_MIN_VERSION" ]]
[[ "$major" =~ ^[0-9]+$ && "$minor" =~ ^[0-9]+$ ]] || return 1
[[ "$(printf '%s\n' "$NODE_MIN_VERSION" "$ver" | sort -V | head -1)" == "$NODE_MIN_VERSION" ]] || return 1
[[ "$major" == "21" ]] && return 1
[[ "$major" == "22" && "$minor" -lt 12 ]] && return 1
return 0
} }
install_nodejs() { install_nodejs() {
@@ -843,9 +837,7 @@ install_nodejs() {
local node_ver local node_ver
node_ver=$(command_exists node && node -v | cut -d'v' -f2 || echo "0") node_ver=$(command_exists node && node -v | cut -d'v' -f2 || echo "0")
# backend engines range is ^20.19.0 || >=22.12.0 (Node 21 is excluded by the glob/minimatch # Match sanitize-html's declared Node minimum, including strict npm installs.
# family; 22.0-22.11 lack unflagged require(esm), which sanitize-html 2.17.7's ESM-only
# htmlparser2 needs — the backend would not start)
if node_version_supported "$node_ver"; then if node_version_supported "$node_ver"; then
log_success "Node.js $(node -v) is already installed" log_success "Node.js $(node -v) is already installed"
return return
@@ -864,10 +856,10 @@ install_nodejs() {
;; ;;
esac esac
# Package managers won't downgrade a newer Node (e.g. 21), so re-verify before continuing # Re-verify in case the package manager did not replace an unsupported Node.
node_ver=$(command_exists node && node -v | cut -d'v' -f2 || echo "0") node_ver=$(command_exists node && node -v | cut -d'v' -f2 || echo "0")
if ! node_version_supported "$node_ver"; then if ! node_version_supported "$node_ver"; then
die "Node.js v$node_ver does not satisfy the backend requirement (^$NODE_MIN_VERSION || >=22.12.0); remove the current Node.js, install a supported version, then re-run this script" die "Node.js v$node_ver does not satisfy the backend requirement (>=$NODE_MIN_VERSION); remove the current Node.js, install a supported version, then re-run this script"
fi fi
log_success "Node.js installed: $(node -v)" log_success "Node.js installed: $(node -v)"
} }