Socket
Socket
Sign inDemoInstall

avvio

Package Overview
Dependencies
Maintainers
2
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

avvio - npm Package Compare versions

Comparing version 6.1.1 to 6.2.0

test/pretty-print.test.js

25

boot.js

@@ -6,2 +6,3 @@ 'use strict'

const inherits = require('util').inherits
const TimeTree = require('./time-tree')
const Plugin = require('./plugin')

@@ -117,2 +118,3 @@ const debug = require('debug')('avvio')

this.booted = false
this.pluginTree = new TimeTree()

@@ -138,2 +140,9 @@ this._readyQ = fastq(this, callWithCbOrNextTick, 1)

main.once('start', (serverName, funcName, time) => {
const nodeId = this.pluginTree.start(null, funcName, time)
main.once('loaded', (serverName, funcName, time) => {
this.pluginTree.stop(nodeId, time)
})
})
Plugin.loadPlugin.call(this, main, (err) => {

@@ -201,2 +210,10 @@ debug('root plugin ready')

const obj = new Plugin(this, plugin, opts, isAfter)
if (!isAfter) {
obj.once('start', (serverName, funcName, time) => {
const nodeId = this.pluginTree.start(current.name, funcName, time)
obj.once('loaded', (serverName, funcName, time) => {
this.pluginTree.stop(nodeId, time)
})
})
}

@@ -295,2 +312,10 @@ if (current.loaded) {

Boot.prototype.prettyPrint = function () {
return this.pluginTree.prittyPrint()
}
Boot.prototype.toJSON = function () {
return this.pluginTree.toJSON()
}
function noop () { }

@@ -297,0 +322,0 @@

16

example.js

@@ -7,2 +7,3 @@ 'use strict'

.use(first, { hello: 'world' })
.use(duplicate, { count: 0 })
.after((err, cb) => {

@@ -16,2 +17,3 @@ if (err) {

})
.use(duplicate, { count: 4 })
.use(third, (err) => {

@@ -32,6 +34,10 @@ if (err) {

avvio.on('preReady', () => {
console.log(avvio.prettyPrint())
})
function first (instance, opts, cb) {
console.log('first loaded', opts)
instance.use(second)
cb()
setTimeout(cb, 42)
}

@@ -48,1 +54,9 @@

}
function duplicate (instance, opts, cb) {
console.log('duplicate loaded', opts.count)
if (opts.count > 0) {
instance.use(duplicate, { count: opts.count - 1 })
}
setTimeout(cb, 20)
}

@@ -46,2 +46,6 @@ import { EventEmitter } from "events";

toJSON(): Object;
prettyPrint(): string;
override: (

@@ -48,0 +52,0 @@ server: context<I>,

3

package.json
{
"name": "avvio",
"version": "6.1.1",
"version": "6.2.0",
"description": "Asynchronous bootstrapping of Node applications",

@@ -43,2 +43,3 @@ "main": "boot.js",

"dependencies": {
"archy": "^1.0.0",
"debug": "^4.0.0",

@@ -45,0 +46,0 @@ "fastq": "^1.6.0"

'use strict'
const fastq = require('fastq')
const EE = require('events').EventEmitter
const inherits = require('util').inherits
const debug = require('debug')('avvio')

@@ -48,2 +50,4 @@ const CODE_PLUGIN_TIMEOUT = 'ERR_AVVIO_PLUGIN_TIMEOUT'

inherits(Plugin, EE)
Plugin.prototype.exec = function (server, cb) {

@@ -85,2 +89,3 @@ const func = this.func

this.emit('start', this.server ? this.server.name : null, this.name, Date.now())
var promise = func(this.server, this.opts, done)

@@ -118,2 +123,3 @@ if (promise && typeof promise.then === 'function') {

debug('enqueue', this.name, obj.name)
this.emit('enqueue', this.server ? this.server.name : null, this.name, Date.now())
this.q.push(obj, cb)

@@ -130,2 +136,3 @@ }

debug('loaded', this.name)
this.emit('loaded', this.server ? this.server.name : null, this.name, Date.now())
this.loaded = true

@@ -132,0 +139,0 @@

@@ -85,2 +85,4 @@ # avvio

* <a href="#express"><code>avvio.<b>express()</b></code></a>
* <a href="#toJSON"><code>avvio.<b>toJSON()</b></code></a>
* <a href="#prettyPrint"><code>avvio.<b>prettyPrint()</b></code></a>

@@ -512,2 +514,79 @@ -------------------------------------------------------

<a name="toJSON"></a>
### avvio.toJSON()
Return a JSON tree rappresenting the state of the plugins and the loading time.
Call it on `preReady` to get the complete tree.
```js
const avvio = require('avvio')()
avvio.on('preReady', () => {
avvio.toJSON()
})
```
The ouput is like this:
```json
{
"label": "bound root",
"start": 1550245184665,
"nodes": [
{
"parent": "bound root",
"start": 1550245184665,
"label": "first",
"nodes": [
{
"parent": "first",
"start": 1550245184708,
"label": "second",
"nodes": [],
"stop": 1550245184709,
"diff": 1
}
],
"stop": 1550245184709,
"diff": 44
},
{
"parent": "bound root",
"start": 1550245184709,
"label": "third",
"nodes": [],
"stop": 1550245184709,
"diff": 0
}
],
"stop": 1550245184709,
"diff": 44
}
```
-------------------------------------------------------
<a name="prettyPrint"></a>
### avvio.prettyPrint()
This method will return a printable string with the tree returned by the `toJSON()` method.
```js
const avvio = require('avvio')()
avvio.on('preReady', () => {
console.log(avvio.prettyPrint())
})
```
The output will be like:
```
avvio 56 ms
├── first 52 ms
├── second 1 ms
└── third 2 ms
```
-------------------------------------------------------
## Acknowledgements

@@ -514,0 +593,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc