error-Bj1xBdEY.mjs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { t as require_binding } from "./binding-B4m_2rFW.mjs";
  2. //#region src/types/sourcemap.ts
  3. function bindingifySourcemap(map) {
  4. if (map == null) return;
  5. return { inner: typeof map === "string" ? map : {
  6. file: map.file ?? void 0,
  7. mappings: map.mappings,
  8. sourceRoot: "sourceRoot" in map ? map.sourceRoot ?? void 0 : void 0,
  9. sources: map.sources?.map((s) => s ?? void 0),
  10. sourcesContent: map.sourcesContent?.map((s) => s ?? void 0),
  11. names: map.names,
  12. ignoreList: map.ignoreList,
  13. x_google_ignoreList: map.x_google_ignoreList,
  14. debugId: "debugId" in map ? map.debugId : void 0
  15. } };
  16. }
  17. require_binding();
  18. function unwrapBindingResult(container) {
  19. if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) throw aggregateBindingErrorsIntoJsError(container.errors);
  20. return container;
  21. }
  22. function normalizeBindingResult(container) {
  23. if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) return aggregateBindingErrorsIntoJsError(container.errors);
  24. return container;
  25. }
  26. function normalizeBindingError(e) {
  27. return e.type === "JsError" ? e.field0 : Object.assign(/* @__PURE__ */ new Error(), {
  28. code: e.field0.kind,
  29. kind: e.field0.kind,
  30. message: e.field0.message,
  31. id: e.field0.id,
  32. exporter: e.field0.exporter,
  33. loc: e.field0.loc,
  34. pos: e.field0.pos,
  35. stack: void 0
  36. });
  37. }
  38. function aggregateBindingErrorsIntoJsError(rawErrors) {
  39. const errors = rawErrors.map(normalizeBindingError);
  40. let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
  41. for (let i = 0; i < errors.length; i++) {
  42. summary += "\n";
  43. if (i >= 5) {
  44. summary += "...";
  45. break;
  46. }
  47. summary += getErrorMessage(errors[i]);
  48. }
  49. const wrapper = new Error(summary);
  50. Object.defineProperty(wrapper, "errors", {
  51. configurable: true,
  52. enumerable: true,
  53. get: () => errors,
  54. set: (value) => Object.defineProperty(wrapper, "errors", {
  55. configurable: true,
  56. enumerable: true,
  57. value
  58. })
  59. });
  60. return wrapper;
  61. }
  62. function getErrorMessage(e) {
  63. if (Object.hasOwn(e, "kind")) return e.message;
  64. let s = "";
  65. if (e.plugin) s += `[plugin ${e.plugin}]`;
  66. const id = e.id ?? e.loc?.file;
  67. if (id) {
  68. s += " " + id;
  69. if (e.loc) s += `:${e.loc.line}:${e.loc.column}`;
  70. }
  71. if (s) s += "\n";
  72. const message = `${e.name ?? "Error"}: ${e.message}`;
  73. s += message;
  74. if (e.frame) s = joinNewLine(s, e.frame);
  75. if (e.stack) s = joinNewLine(s, e.stack.replace(message, ""));
  76. if (e.cause) {
  77. s = joinNewLine(s, "Caused by:");
  78. s = joinNewLine(s, getErrorMessage(e.cause).split("\n").map((line) => " " + line).join("\n"));
  79. }
  80. return s;
  81. }
  82. function joinNewLine(s1, s2) {
  83. return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
  84. }
  85. //#endregion
  86. export { bindingifySourcemap as a, unwrapBindingResult as i, normalizeBindingError as n, normalizeBindingResult as r, aggregateBindingErrorsIntoJsError as t };