npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-yield-breakpoint

v2.1.0

Published

Add breakpoints around `yield` expression especially for koa@1.

Downloads

17

Readme

koa-yield-breakpoint

Add breakpoints around yield expression especially for koa@1.

Install

$ npm i koa-yield-breakpoint --save

Example

$ DEBUG=koa-yield-breakpoint node example/app
$ curl -XPOST localhost:3000/users

Usage

// Generally, on top of the main file
const koaYieldBreakpoint = require('koa-yield-breakpoint')({
  name: 'api',
  files: ['./routes/*.js'],
  // store: new require('koa-yield-breakpoint-mongodb')({
  //   url: 'mongodb://localhost:27017/test',
  //   coll: 'koa-yield-breakpoint-loggers'
  // })
})

const koa = require('koa')
const routes = require('./routes')
const app = koa()

// Generally, above other middlewares
app.use(koaYieldBreakpoint)

routes(app)

app.listen(3000, () => {
  console.log('listening on 3000')
})

NB: You'd better put require('koa-yield-breakpoint') on the top of the main file, because koa-yield-breakpoint rewrite Module.prototype._compile.

koa-yield-breakpoint will wrap YieldExpression with:

global.logger(
  this,
  function*(){
    return yield YieldExpression
  },
  YieldExpressionString,
  filename
)

log like:

{
  "name": "api",
  "requestId": "222f66ec-7259-4d20-930f-2ac035c16e7b",
  "timestamp": "2018-01-15T05:02:18.827Z",
  "this": {
    "state": {},
    "params": {},
    "request": {
      "method": "POST",
      "path": "/users",
      "header": {
        "host": "localhost:3000",
        "user-agent": "curl/7.54.0",
        "accept": "*/*"
      },
      "query": {}
    },
    "response": {
      "status": 404
    }
  },
  "type": "start",
  "step": 1,
  "take": 0
}

koa-yield-breakpoint will print logs to console by default, if you want to save these logs to db, set store option, eg: koa-yield-breakpoint-mongodb.

NB: type in ['start', 'beforeYield', 'afterYield', 'error', 'end'], take is ms.

SourceMap

After v1.1.0, koa-yield-breakpoint support source map:

example/routes/users.js

const Mongolass = require('mongolass')
const mongolass = new Mongolass()
mongolass.connect('mongodb://localhost:27017/test')

exports.getUsers = function* getUsers() {
  yield mongolass.model('users').create({
    name: 'xx',
    age: 18
  })

  const users = yield mongolass.model('users').find()


  console.log(haha)
  this.body = users
}

Will output:

ReferenceError: haha is not defined
    at Object.getUsers (/Users/nswbmw/node/koa-yield-breakpoint/example/routes/users.js:16:15)
    at next (native)
    at Object.<anonymous> (/Users/nswbmw/node/koa-yield-breakpoint/node_modules/koa-route/index.js:34:19)
    at next (native)
    at onFulfilled (/Users/nswbmw/node/koa-yield-breakpoint/node_modules/koa/node_modules/co/index.js:65:19)

Options

require('koa-yield-breakpoint')(option)

  • name{String}: service name added to log.
  • sourcemap{Boolean}: whether open sourcemap, default: true, will increase memory usage.
  • files{String[]}: files pattern, see glob, required.
  • exclude_files{String[]}: exclude files pattern, default [].
  • store{Object}: backend store instance, see koa-yield-breakpoint-mongodb, default print to console.
  • filter{Object}: reserved field in koa's this, default:
{
  ctx: ['state', 'params'],
  request: ['method', 'path', 'header', 'query', 'body'],
  response: ['status', 'body']
}
  • loggerName{String}: global logger name, default logger.
  • requestIdPath{String}: requestId path in this, default requestId.
  • yieldCondition{Function}: parameters (filename, yieldExpression, parsedYieldExpression), return a object:
    • wrapYield{Boolean}: if true return wraped yieldExpression, default true.
    • deep{Boolean}: if true deep wrap yieldExpression, default true.
  • others: see glob.