fix(start-web): adiciona fallback de rebuild para better-sqlite3

This commit is contained in:
Esdras Renan 2025-11-25 13:23:57 -03:00
parent e9ba1790fb
commit 24656afff3

View file

@ -95,10 +95,30 @@ try {
EOF EOF
} }
copy_fallback_binding() {
local temp_dir="/tmp/bsql-fallback"
rm -rf "$temp_dir"
mkdir -p "$temp_dir"
(
cd "$temp_dir" &&
npm install better-sqlite3@11.10.0 --build-from-source --no-save >/dev/null 2>&1
) || {
echo "[start-web] fallback npm install falhou"
return 1
}
local src_pkg="$temp_dir/node_modules/better-sqlite3"
local dest_pkg="/app/node_modules/.bun/better-sqlite3@11.10.0/node_modules/better-sqlite3"
mkdir -p "$dest_pkg"
cp -R "$src_pkg/"* "$dest_pkg/" || return 1
echo "[start-web] fallback: pacote better-sqlite3 copiado para .bun store"
return 0
}
rebuild_and_repin_sqlite() { rebuild_and_repin_sqlite() {
echo "[start-web] rebuilding better-sqlite3 para a runtime atual" echo "[start-web] rebuilding better-sqlite3 para a runtime atual"
npm rebuild better-sqlite3 --build-from-source >/dev/null 2>&1 || { npm rebuild better-sqlite3 --build-from-source >/dev/null 2>&1 || {
echo "[start-web] rebuild falhou; continuando com bindings existentes" >&2 echo "[start-web] rebuild falhou; tentando fallback" >&2
copy_fallback_binding || echo "[start-web] fallback também falhou" >&2
} }
node - <<'EOF' node - <<'EOF'
const fs = require("node:fs") const fs = require("node:fs")
@ -131,9 +151,12 @@ EOF
else else
rebuild_and_repin_sqlite rebuild_and_repin_sqlite
check_better_sqlite3 || { check_better_sqlite3 || {
echo "[start-web] ERRO: better-sqlite3 inválido após rebuild" >&2 echo "[start-web] ERRO: better-sqlite3 inválido após rebuild; tentando fallback"
copy_fallback_binding && check_better_sqlite3 || {
echo "[start-web] ERRO: better-sqlite3 continua inválido após fallback" >&2
exit 1 exit 1
} }
}
fi fi
fi fi