0x/lib/random-require.js
Ruben Bridgewater 52dfaee21c
Filter next tick
This also moves the main filter logic into the executed function.
This seemed cleaner instead of having to do this in the receiving
part.
2018-10-08 16:40:14 +02:00

30 lines
860 B
JavaScript

'use strict'
Error.stackTraceLimit = Infinity;
try {
throw new Error();
} catch (err) {
process.nextTick(() => {
Error.stackTraceLimit = 2;
try {
throw new Error();
} catch (innerErr) {
const filterNextTick = innerErr.stack.split('\n')[2].match(/ \(.+?:/g)[0].slice(2);
const stacks = err.stack
.match(/ \(.+?:/g)
.map((e) => e.slice(2))
// Filter Everything that has nothing to do with Node core and next
// ticks.
.filter((e) => e[0] !== '/' && e[0] !== '\\' && e !== filterNextTick);
let regExpStr = '';
let separator = '';
for (const frame of new Set(stacks)) {
regExpStr += `${separator} ${frame.replace(/\\/g, '\\\\').replace(/\./g, '\\.')}\\d+:\\d+`;
separator = '|';
}
regExpStr += '$';
console.log(regExpStr);
}
});
}