-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathinstallSourceMapSupport.ts
More file actions
32 lines (30 loc) · 1.05 KB
/
installSourceMapSupport.ts
File metadata and controls
32 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sourceMapSupport from "source-map-support";
/**
* Installs source-map-support with a workaround for Bun's source map handling.
*
* Bun's runtime can produce source maps with column values of -1, which causes
* source-map@0.6.1 (used by source-map-support) to throw:
* "Column must be greater than or equal to 0, got -1"
*
* This wraps the prepareStackTrace hook so that if source map processing fails,
* it falls back to default stack trace formatting instead of crashing.
*
* See: https://github.com/oven-sh/bun/issues/8087
*/
export function installSourceMapSupport() {
sourceMapSupport.install({
handleUncaughtExceptions: false,
environment: "node",
hookRequire: false,
});
const _prepareStackTrace = (Error as any).prepareStackTrace;
if (_prepareStackTrace) {
(Error as any).prepareStackTrace = (error: Error, stackTraces: NodeJS.CallSite[]) => {
try {
return _prepareStackTrace(error, stackTraces);
} catch {
return `${error}\n` + stackTraces.map((s) => ` at ${s}`).join("\n");
}
};
}
}