Comparing version 4.0.1 to 5.0.0
16
boot.js
@@ -161,13 +161,8 @@ 'use strict' | ||
// load a plugin | ||
Boot.prototype.use = function (plugin, opts, callback) { | ||
if (typeof opts === 'function') { | ||
callback = opts | ||
opts = null | ||
} | ||
Boot.prototype.use = function (plugin, opts) { | ||
if (typeof plugin === 'function') { | ||
this._addPlugin(plugin, opts, callback) | ||
this._addPlugin(plugin, opts) | ||
} else if (Array.isArray(plugin)) { | ||
for (var i = 0; i < plugin.length; i++) { | ||
this._addPlugin(plugin[i], opts, callback) | ||
this._addPlugin(plugin[i], opts) | ||
} | ||
@@ -181,3 +176,3 @@ } else { | ||
Boot.prototype._addPlugin = function (plugin, opts, callback) { | ||
Boot.prototype._addPlugin = function (plugin, opts) { | ||
if (typeof plugin !== 'function') { | ||
@@ -187,3 +182,2 @@ throw new Error('plugin must be a function') | ||
opts = opts || {} | ||
callback = callback || null | ||
@@ -197,3 +191,3 @@ if (this.booted) { | ||
const obj = new Plugin(this, plugin, opts, callback) | ||
const obj = new Plugin(this, plugin, opts) | ||
@@ -200,0 +194,0 @@ if (current.loaded) { |
{ | ||
"name": "avvio", | ||
"version": "4.0.1", | ||
"version": "5.0.0", | ||
"description": "Asynchronous bootstrapping of Node applications", | ||
@@ -36,3 +36,3 @@ "main": "boot.js", | ||
"standard": "^10.0.3", | ||
"tap": "^10.7.3", | ||
"tap": "^11.0.1", | ||
"then-sleep": "^1.0.1" | ||
@@ -39,0 +39,0 @@ }, |
@@ -6,6 +6,5 @@ 'use strict' | ||
function Plugin (parent, func, opts, callback) { | ||
function Plugin (parent, func, opts) { | ||
this.func = func | ||
this.opts = opts | ||
this.callback = callback | ||
this.deferred = false | ||
@@ -60,3 +59,2 @@ this.onFinish = null | ||
debug('finish', this.name) | ||
const callback = this.callback | ||
const done = () => { | ||
@@ -70,10 +68,3 @@ if (this.loaded) { | ||
// if 'use' has a callback | ||
if (callback) { | ||
callback(err) | ||
// if 'use' has a callback but does not have parameters | ||
cb(callback.length > 0 ? null : err) | ||
} else { | ||
cb(err) | ||
} | ||
cb(err) | ||
} | ||
@@ -80,0 +71,0 @@ |
@@ -189,3 +189,3 @@ # avvio | ||
### app.after(func(error, [context], [done]), [cb]) | ||
### app.after(func(error, [context], [done])) | ||
@@ -192,0 +192,0 @@ Calls a function after all the previously defined plugins are loaded, including |
@@ -68,5 +68,4 @@ 'use strict' | ||
t.error(err) | ||
t.pass('afterred finished') | ||
cb() | ||
}, function () { | ||
t.pass('afterred finished') | ||
}) | ||
@@ -316,3 +315,3 @@ | ||
test('if `use` has a callback with more then one parameter, the error must not reach ready', (t) => { | ||
t.plan(2) | ||
t.plan(1) | ||
@@ -324,8 +323,6 @@ const server = { my: 'server' } | ||
done(new Error('err')) | ||
}, err => { | ||
t.ok(err) | ||
}) | ||
app.ready(function (err) { | ||
t.error(err) | ||
t.ok(err) | ||
}) | ||
@@ -332,0 +329,0 @@ }) |
@@ -6,16 +6,2 @@ 'use strict' | ||
test('use a plugin and wait till that is loaded', (t) => { | ||
t.plan(3) | ||
const app = boot() | ||
app.use(function (server, opts, done) { | ||
t.equal(server, app, 'the first argument is the server') | ||
t.deepEqual(opts, {}, 'no options') | ||
done() | ||
}, () => { | ||
t.pass('booted') | ||
}) | ||
}) | ||
test('reentrant', (t) => { | ||
@@ -28,7 +14,8 @@ t.plan(7) | ||
app.use(first, () => { | ||
t.ok(firstLoaded, 'first is loaded') | ||
t.ok(secondLoaded, 'second is loaded') | ||
t.pass('booted') | ||
}) | ||
app.use(first) | ||
.after(() => { | ||
t.ok(firstLoaded, 'first is loaded') | ||
t.ok(secondLoaded, 'second is loaded') | ||
t.pass('booted') | ||
}) | ||
@@ -66,7 +53,10 @@ function first (s, opts, done) { | ||
firstLoaded = true | ||
s.use(second, function () { | ||
t.throws(() => { | ||
s.use(second) | ||
setTimeout(() => { | ||
try { | ||
s.use(third) | ||
}, 'Impossible to load "third" because the parent "first" was already loaded') | ||
}) | ||
} catch (err) { | ||
t.is(err.message, 'root plugin has already booted') | ||
} | ||
}, 500) | ||
done() | ||
@@ -73,0 +63,0 @@ } |
@@ -7,3 +7,3 @@ 'use strict' | ||
test('array of plugins', (t) => { | ||
t.plan(21) | ||
t.plan(16) | ||
@@ -14,5 +14,4 @@ const options = { hello: 'world' } | ||
app.use([first, second, third, fourth, fifth], options, (err) => { | ||
t.error(err) | ||
}) | ||
app.use([first, second, third, fourth, fifth], options) | ||
.after(t.error) | ||
@@ -19,0 +18,0 @@ app.on('start', () => { |
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
62533
1976