2018-04-18 16:18:06 +00:00
|
|
|
const filenameRE = /\(([^)]+\.js):(\d+):(\d+)\)$/
|
|
|
|
|
2018-11-21 15:04:37 +00:00
|
|
|
export function rewriteStacktrace (e, distDir) {
|
2018-07-24 09:24:40 +00:00
|
|
|
if (!e || typeof e.stack !== 'string') {
|
2018-04-18 16:18:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const lines = e.stack.split('\n')
|
|
|
|
|
2018-07-24 09:24:40 +00:00
|
|
|
const result = lines.map((line) => {
|
|
|
|
return rewriteTraceLine(line, distDir)
|
|
|
|
})
|
2018-04-18 16:18:06 +00:00
|
|
|
|
|
|
|
e.stack = result.join('\n')
|
|
|
|
}
|
|
|
|
|
2018-11-21 15:04:37 +00:00
|
|
|
function rewriteTraceLine (trace, distDir) {
|
2018-04-18 16:18:06 +00:00
|
|
|
const m = trace.match(filenameRE)
|
|
|
|
if (m == null) {
|
|
|
|
return trace
|
|
|
|
}
|
2018-07-24 09:24:40 +00:00
|
|
|
const filename = m[1]
|
|
|
|
const filenameLink = filename.replace(distDir, '/_next/development').replace(/\\/g, '/')
|
|
|
|
trace = trace.replace(filename, filenameLink)
|
2018-04-18 16:18:06 +00:00
|
|
|
return trace
|
|
|
|
}
|