Avoid listing node_modules in stacks.

This commit is contained in:
Julien Fontanet 2015-10-07 12:18:53 +02:00
parent 6055ac182b
commit 1603df3503
6 changed files with 37 additions and 10 deletions

View File

@ -1,3 +0,0 @@
try { require('clarify') } catch (_) {}
try { require('trace') } catch (_) {}
try { require('source-map-support/register') } catch (_) {}

View File

@ -1 +1 @@
--require ./.mocha.js
--require ./better-stacks.js

33
better-stacks.js Normal file
View File

@ -0,0 +1,33 @@
try { require('source-map-support/register') } catch (_) {}
// Async stacks.
try { require('trace') } catch (_) {}
// Removes node_modules and internal modules.
try {
var sep = require('path').sep
var path = __dirname + sep + 'node_modules' + sep
require('stack-chain').filter.attach(function (_, frames) {
var filtered = frames.filter(function (frame) {
var name = frame && frame.getFileName()
return (
// has a filename
name &&
// contains a separator (no internal modules)
// name.indexOf(sep) !== -1 &&
// does not start with the current path followed by node_modules.
name.lastIndexOf(path, 0) !== 0
)
})
// depd (used amongst other by express requires at least 3 frames
// in the stack.
return filtered.length > 2
? filtered
: frames
})
} catch (_) {}

View File

@ -4,4 +4,7 @@
// ===================================================================
// Better stack traces if possible.
require('../better-stacks')
require('exec-promise')(require('../'))

View File

@ -7,10 +7,5 @@ if (process.env.DEBUG === undefined) {
process.env.DEBUG = 'app-conf,xen-api,xo:*'
}
// Better stack traces if possible.
try { require('clarify') } catch (_) {}
try { require('source-map-support/register') } catch (_) {}
try { require('trace') } catch (_) {}
// Import the real main module.
module.exports = require('./dist')

View File

@ -35,7 +35,6 @@
"blocked": "^1.1.0",
"bluebird": "^2.9.14",
"body-parser": "^1.13.3",
"clarify": "^1.0.5",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.3.5",
"cron": "^1.0.9",