UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

132 lines 3.65 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var install_error_handlers_exports = {}; __export(install_error_handlers_exports, { formatErrorSafely: () => formatErrorSafely, installPrepareStackTraceGuard: () => installPrepareStackTraceGuard, installSafeUncaughtHandler: () => installSafeUncaughtHandler }); module.exports = __toCommonJS(install_error_handlers_exports); let userPrepare; let depth = 0; const restoreTrail = []; function defaultFormat(error, stack) { const name = error?.name ?? "Error"; const message = error?.message ?? ""; const head = `${name}: ${message}`; try { const lines = stack.map(frame => { try { return ` at ${frame}`; } catch { return " at <frame>"; } }); return `${head} ${lines.join("\n")}`; } catch { return head; } } function guardedPrepare(error, stack) { if (depth > 0) return defaultFormat(error, stack); if (typeof userPrepare !== "function") return defaultFormat(error, stack); depth++; try { return userPrepare(error, stack); } catch { return defaultFormat(error, stack); } finally { depth--; } } let installed = false; function installPrepareStackTraceGuard() { if (installed) return; installed = true; const existing = Error.prepareStackTrace; if (typeof existing === "function" && existing !== guardedPrepare) { userPrepare = existing; } Object.defineProperty(Error, "prepareStackTrace", { configurable: true, get() { return guardedPrepare; }, set(value) { if (value === guardedPrepare) { if (restoreTrail.length > 0) { userPrepare = restoreTrail.pop(); } return; } restoreTrail.push(userPrepare); userPrepare = typeof value === "function" ? value : void 0; } }); } function formatErrorSafely(err) { const prevPrepare = Error.prepareStackTrace; Error.prepareStackTrace = void 0; try { if (err instanceof Error) { let stack = ""; try { stack = err.stack ?? ""; } catch {} if (stack) return stack; const name = err.name || "Error"; const message = err.message || ""; return `${name}: ${message}`; } return String(err); } catch { try { return String(err); } catch { return "<unprintable error>"; } } finally { Error.prepareStackTrace = prevPrepare; } } function installSafeUncaughtHandler(label) { installPrepareStackTraceGuard(); process.on("uncaughtException", err => { try { const formatted = formatErrorSafely(err); process.stderr.write(`[${label}] uncaught exception ${formatted} `); } catch {} process.exit(1); }); process.on("unhandledRejection", reason => { try { const formatted = formatErrorSafely(reason); process.stderr.write(`[${label}] unhandled rejection ${formatted} `); } catch {} }); }