/* eslint-disable no-console */ const fs = require("node:fs"); const path = require("node:path"); function patchIfNeeded(targetPath) { if (!fs.existsSync(targetPath)) { console.warn(`[opennext patch] Skip: missing file: ${targetPath}`); return false; } const text = fs.readFileSync(targetPath, "utf8"); const oldStr = "throw new Error(`Unexpected loadManifest(${path2}) call!`)"; const newStr = "return{}"; const count = text.split(oldStr).length - 1; if (count === 0) { console.log("[opennext patch] handler already patched (or no-op)."); return false; } if (count !== 1) { console.warn(`[opennext patch] Unexpected match count: ${count}`); } const patched = text.replace(oldStr, newStr); fs.writeFileSync(targetPath, patched, "utf8"); console.log(`[opennext patch] Patched handler loadManifest in ${path.relative(process.cwd(), targetPath)}`); return true; } const target = path.join( process.cwd(), ".open-next", "server-functions", "default", "handler.mjs", ); patchIfNeeded(target);