UNPKG

stack-trace-fixer

Version:

Modify Node.js error stack traces to display relative paths in a Docker container

29 lines (25 loc) 975 B
let _prepareStackTrace; export function installFix(pwd = process.env.PWD || process.env.INIT_CWD?.replaceAll("\\", "/")) { if (_prepareStackTrace) { throw new Error("You can't installFix twice"); } _prepareStackTrace = Error.prepareStackTrace; if (pwd) { // prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]) Error.prepareStackTrace = (err, stackTraces) => { console.log('prepareStackTrace') // need to call original prepareStackTrace to correctly process typescript files const original = _prepareStackTrace(err, stackTraces); return original.replaceAll('file://'+pwd, '.').replaceAll(pwd, '.'); }; } else { throw new Error('Please provide "pwd" parameter'); } } export function uninstallFix() { if (!_prepareStackTrace) { throw new Error("You need to installFix before uninstallFix and can't uninstallFix twice"); } Error.prepareStackTrace = _prepareStackTrace; _prepareStackTrace = null; }