Comparing version 5.1.0 to 5.2.0
10
boot.js
@@ -163,3 +163,3 @@ 'use strict' | ||
if (typeof plugin === 'function') { | ||
this._addPlugin(plugin, opts) | ||
this._addPlugin(plugin, opts, false) | ||
} else { | ||
@@ -172,3 +172,3 @@ throw new Error('plugin must be a function') | ||
Boot.prototype._addPlugin = function (plugin, opts) { | ||
Boot.prototype._addPlugin = function (plugin, opts, isAfter) { | ||
if (typeof plugin !== 'function') { | ||
@@ -186,3 +186,3 @@ throw new Error('plugin must be a function') | ||
const obj = new Plugin(this, plugin, opts) | ||
const obj = new Plugin(this, plugin, opts, isAfter) | ||
@@ -201,4 +201,4 @@ if (current.loaded) { | ||
Boot.prototype.after = function (func, cb) { | ||
this.use(_after.bind(this), cb) | ||
Boot.prototype.after = function (func) { | ||
this._addPlugin(_after.bind(this), {}, true) | ||
@@ -205,0 +205,0 @@ function _after (s, opts, done) { |
{ | ||
"name": "avvio", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "Asynchronous bootstrapping of Node applications", | ||
@@ -5,0 +5,0 @@ "main": "boot.js", |
@@ -6,3 +6,3 @@ 'use strict' | ||
function Plugin (parent, func, opts) { | ||
function Plugin (parent, func, opts, isAfter) { | ||
this.func = func | ||
@@ -14,2 +14,3 @@ this.opts = opts | ||
this.name = func.name | ||
this.isAfter = isAfter | ||
@@ -30,2 +31,9 @@ this.q = fastq(parent, loadPlugin, 1) | ||
var name = this.name | ||
if (this.parent._error && !this.isAfter) { | ||
debug('skipping loading of plugin as parent errored and it is not an after', name) | ||
process.nextTick(cb) | ||
return | ||
} | ||
this.server = this.parent.override(server, func, this.opts) | ||
@@ -45,6 +53,11 @@ | ||
if (completed) { | ||
debug('loading complete', name) | ||
return | ||
} | ||
debug('exec completed', name) | ||
if (err) { | ||
debug('exec errored', name) | ||
} else { | ||
debug('exec completed', name) | ||
} | ||
@@ -51,0 +64,0 @@ completed = true |
@@ -180,2 +180,6 @@ # avvio | ||
When an error happens, the loading of plugins will stop until there is | ||
an [`after`](#after) callback specified. Otherwise, it will be handled | ||
in [`ready`](#ready). | ||
------------------------------------------------------- | ||
@@ -195,2 +199,5 @@ <a name="after"></a> | ||
In the "no parameter" and "one parameter" variants, the callback can also | ||
return a `Promise`. | ||
```js | ||
@@ -197,0 +204,0 @@ const server = {} |
@@ -503,1 +503,133 @@ 'use strict' | ||
}) | ||
test('stop loading plugins if it errors', (t) => { | ||
t.plan(2) | ||
const app = boot() | ||
app.use(function first (server, opts, done) { | ||
t.pass('first called') | ||
done(new Error('kaboom')) | ||
}) | ||
app.use(function second (server, opts, done) { | ||
t.fail('this should never be called') | ||
}) | ||
app.ready((err) => { | ||
t.equal(err.message, 'kaboom') | ||
}) | ||
}) | ||
test('keep loading if there is an .after', (t) => { | ||
t.plan(4) | ||
const app = boot() | ||
app.use(function first (server, opts, done) { | ||
t.pass('first called') | ||
done(new Error('kaboom')) | ||
}) | ||
app.after(function (err) { | ||
t.equal(err.message, 'kaboom') | ||
}) | ||
app.use(function second (server, opts, done) { | ||
t.pass('second called') | ||
done() | ||
}) | ||
app.ready((err) => { | ||
t.error(err) | ||
}) | ||
}) | ||
test('do not load nested plugin if parent errors', (t) => { | ||
t.plan(4) | ||
const app = boot() | ||
app.use(function first (server, opts, done) { | ||
t.pass('first called') | ||
server.use(function second (_, opts, done) { | ||
t.fail('this should never be called') | ||
}) | ||
done(new Error('kaboom')) | ||
}) | ||
app.after(function (err) { | ||
t.equal(err.message, 'kaboom') | ||
}) | ||
app.use(function third (server, opts, done) { | ||
t.pass('third called') | ||
done() | ||
}) | ||
app.ready((err) => { | ||
t.error(err) | ||
}) | ||
}) | ||
test('.after nested', (t) => { | ||
t.plan(4) | ||
const app = boot() | ||
app.use(function outer (app, opts, done) { | ||
app.use(function first (app, opts, done) { | ||
t.pass('first called') | ||
done(new Error('kaboom')) | ||
}) | ||
app.after(function (err) { | ||
t.equal(err.message, 'kaboom') | ||
}) | ||
app.use(function second (app, opts, done) { | ||
t.pass('second called') | ||
done() | ||
}) | ||
done() | ||
}) | ||
app.ready((err) => { | ||
t.error(err) | ||
}) | ||
}) | ||
test('nested error', (t) => { | ||
t.plan(4) | ||
const app = boot() | ||
app.use(function outer (app, opts, done) { | ||
app.use(function first (app, opts, done) { | ||
t.pass('first called') | ||
done(new Error('kaboom')) | ||
}) | ||
app.use(function second (app, opts, done) { | ||
t.fail('this should never be called') | ||
}) | ||
done() | ||
}) | ||
app.after(function (err) { | ||
t.equal(err.message, 'kaboom') | ||
}) | ||
app.use(function third (server, opts, done) { | ||
t.pass('third called') | ||
done() | ||
}) | ||
app.ready((err) => { | ||
t.error(err) | ||
}) | ||
}) |
'use strict' | ||
const test = require('tap').test | ||
const t = require('tap') | ||
const test = t.test | ||
const boot = require('..') | ||
@@ -5,0 +6,0 @@ |
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
66867
2122
450