Last active
March 12, 2020 19:46
-
-
Save Restuta/b2ee29ccda90123a93c827b28e92597f to your computer and use it in GitHub Desktop.
neat-stack.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cleanStack from 'clean-stack'; | |
// dims non-useful log lines in stack traces | |
const neatStack = (colorize, stack) => { | |
// add parts of stack trace lines here that should be ignored | |
const regexParts = [ | |
'(node_modules)', | |
'(WEBPACK_IMPORTED)', | |
'(next_tick.js)', | |
'(domain.js)', | |
'(timers.js)', | |
'(overloadSequlizeFind)', | |
'(Array.)', | |
'(at new Promise)', | |
'(_next)', | |
'(_callee)', | |
'(__webpack_require__)', | |
].join('|'); | |
const internalStackRegex = new RegExp(`at.*${regexParts}`); | |
const cleanedStack = cleanStack(String(stack)); | |
const stackLines = cleanedStack.split('\n'); | |
const title = R.head(stackLines); | |
const colorizedStackLines = R.pipe( | |
R.tail, | |
R.map(line => | |
line.match(internalStackRegex) || line.match('From previous event') | |
? chalk.dim(line) | |
: colorize(line), | |
), | |
R.join('\n'), | |
)(stackLines); | |
return colorize(`${title}\n${colorizedStackLines}`); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment