koa-compose
Advanced tools
Comparing version 2.2.0 to 2.3.0
91
index.js
@@ -1,8 +0,2 @@ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var debug = require('debug')('koa-compose'); | ||
var fmt = require('util').inspect; | ||
/** | ||
@@ -12,5 +6,3 @@ * Expose compositor. | ||
module.exports = debug.enabled | ||
? instrumented | ||
: compose; | ||
module.exports = compose; | ||
@@ -43,83 +35,2 @@ /** | ||
/** | ||
* Compose `middleware` returning | ||
* an instrumented set of middleware | ||
* for debugging manipulation between | ||
* continuation. | ||
* | ||
* @param {Array} middleware | ||
* @return {Function} | ||
* @api public | ||
*/ | ||
function instrumented(middleware){ | ||
console.warn('Warning: do not run DEBUG=koa-compose in production'); | ||
console.warn('as it will greatly affect the performance of your'); | ||
console.warn('application - it is designed for a development'); | ||
console.warn('environment only.\n'); | ||
return function *(next){ | ||
var i = middleware.length; | ||
var prev = next || noop(); | ||
var name = prev._name || prev.name || 'noop'; | ||
var curr; | ||
while (i--) { | ||
curr = middleware[i]; | ||
prev = wrap.call(this, curr, prev, name); | ||
name = curr._name || curr.name; | ||
} | ||
yield *prev; | ||
} | ||
} | ||
/** | ||
* Wrap to output debugging info. | ||
* | ||
* @api private | ||
*/ | ||
function wrap(curr, prev, name) { | ||
return curr.call(this, function *(next){ | ||
if ('noop' == name) return yield next; | ||
this._level = this._level || 0; | ||
// downstream | ||
output(this, 'down', name); | ||
// yield | ||
this._level++; | ||
yield next; | ||
this._level--; | ||
// upstream | ||
output(this, 'up', name); | ||
}.call(this, prev)); | ||
} | ||
/** | ||
* Output debugging information. | ||
*/ | ||
function output(ctx, direction, name) { | ||
direction = 'up' == direction ? '<<' : '>>'; | ||
console.log(' \033[1m%d \033[0m%s \033[36m%s\033[0m', ctx._level, direction, name); | ||
console.log(' \033[90mstatus\033[0m: %s %s', ctx.status, ctx.response.statusString); | ||
console.log(' \033[90mheader\033[0m:'); | ||
header(ctx); | ||
console.log(' \033[90mbody\033[0m: %j', ctx.body); | ||
console.log(); | ||
} | ||
/** | ||
* Output header fields. | ||
*/ | ||
function header(ctx) { | ||
for (var key in ctx.response.header) { | ||
console.log(' \033[90m%s\033[0m: %s', key, ctx.response.header[key]); | ||
} | ||
} | ||
/** | ||
* Noop. | ||
@@ -126,0 +37,0 @@ * |
@@ -5,3 +5,3 @@ { | ||
"repository": "koajs/compose", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"keywords": [ | ||
@@ -15,5 +15,3 @@ "koa", | ||
], | ||
"dependencies": { | ||
"debug": "*" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -20,0 +18,0 @@ "co": "~3.0.1", |
@@ -12,18 +12,4 @@ | ||
## Debugging | ||
To debug the interactions between middleware, you may use | ||
the __DEBUG__ environment variable, for example: | ||
``` | ||
$ DEBUG=koa-compose node --harmony app.js | ||
``` | ||
When enabled this will output verbose response information and the | ||
middleware names to help visualize how they interact. | ||
![koa middleware debugging](https://dl.dropboxusercontent.com/u/6396913/koa/Screen%20Shot%202013-12-22%20at%208.46.46%20AM.png) | ||
## License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
0
0
1213
31
14
- Removeddebug@*
- Removeddebug@4.3.7(transitive)
- Removedms@2.1.3(transitive)