error-w0u7biK-.mjs 2.9 KB

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