fix: show electron change server header for localserver

This commit is contained in:
LukeGus
2026-05-27 13:54:13 -05:00
parent f81587888f
commit abb1f60b71
3 changed files with 447 additions and 405 deletions
+12 -3
View File
@@ -1,7 +1,12 @@
const fs = require("node:fs");
const path = require("node:path");
const betterSqlite3Dir = path.join(__dirname, "..", "node_modules", "better-sqlite3");
const betterSqlite3Dir = path.join(
__dirname,
"..",
"node_modules",
"better-sqlite3",
);
const macrosPath = path.join(betterSqlite3Dir, "src", "util", "macros.cpp");
const helpersPath = path.join(betterSqlite3Dir, "src", "util", "helpers.cpp");
const entryPath = path.join(betterSqlite3Dir, "src", "better_sqlite3.cpp");
@@ -91,7 +96,11 @@ const entryPatched = patchFile(entryPath, [
]);
if (macrosPatched || helpersPatched || entryPatched) {
console.log("[patch-better-sqlite3] Applied compatibility patches for newer Electron/V8");
console.log(
"[patch-better-sqlite3] Applied compatibility patches for newer Electron/V8",
);
} else {
console.log("[patch-better-sqlite3] Already patched or target code not found");
console.log(
"[patch-better-sqlite3] Already patched or target code not found",
);
}
+12 -5
View File
@@ -45,7 +45,12 @@ const nanHeaderPatched = patchFile(path.join(nanDir, "nan.h"), [
// cpu-features binding.cc includes <node.h> before <nan.h>, so the nan.h patch
// above is too late. Patch binding.cc directly to inject the compat define first.
const cpuFeaturesDir = path.join(__dirname, "..", "node_modules", "cpu-features");
const cpuFeaturesDir = path.join(
__dirname,
"..",
"node_modules",
"cpu-features",
);
const bindingPath = path.join(cpuFeaturesDir, "src", "binding.cc");
const bindingPatched = patchFile(bindingPath, [
{
@@ -70,11 +75,11 @@ if (fs.existsSync(implPath)) {
if (!src.includes(TAG)) {
src = src.replace(
/v8::External::New\(v8::Isolate::GetCurrent\(\),\s*value\)/g,
`v8::External::New(v8::Isolate::GetCurrent(), value, ${TAG})`
`v8::External::New(v8::Isolate::GetCurrent(), value, ${TAG})`,
);
src = src.replace(
/v8::External::New\(isolate,\s*reinterpret_cast<void \*>\(callback\)\)/g,
`v8::External::New(isolate, reinterpret_cast<void *>(callback), ${TAG})`
`v8::External::New(isolate, reinterpret_cast<void *>(callback), ${TAG})`,
);
}
@@ -97,7 +102,7 @@ if (fs.existsSync(callbacksPath)) {
// Pattern: .As<v8::External>()->Value()) — always followed by ))
src = src.replace(
/\.As<v8::External>\(\)->Value\(\)\)/g,
`.As<v8::External>()->Value(${TAG}))`
`.As<v8::External>()->Value(${TAG}))`,
);
}
@@ -108,7 +113,9 @@ if (fs.existsSync(callbacksPath)) {
}
if (nanHeaderPatched || bindingPatched || implPatched || callbacksPatched) {
console.log("[patch-nan] Applied compatibility patches for Electron 42 / V8 13+");
console.log(
"[patch-nan] Applied compatibility patches for Electron 42 / V8 13+",
);
} else {
console.log("[patch-nan] Already patched or target code not found");
}