From 677d85de1c04f7fc5ddabe31fb4b7815afd068e4 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 13 May 2017 02:01:22 -0700 Subject: [PATCH] node: make plugin methods optional. --- lib/node/node.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/node/node.js b/lib/node/node.js index d7014239..e600741e 100644 --- a/lib/node/node.js +++ b/lib/node/node.js @@ -296,8 +296,10 @@ Node.prototype.use = function use(plugin) { instance = plugin.init(this); - assert(typeof instance.open === 'function', '`open` must be a function.'); - assert(typeof instance.close === 'function', '`close` must be a function.'); + assert(!instance.open || typeof instance.open === 'function', + '`open` must be a function.'); + assert(!instance.close || typeof instance.close === 'function', + '`close` must be a function.'); if (plugin.id) { assert(typeof plugin.id === 'string', '`id` must be a string.'); @@ -407,7 +409,8 @@ Node.prototype.openPlugins = co(function* openPlugins() { for (i = 0; i < this.stack.length; i++) { plugin = this.stack[i]; - yield plugin.open(); + if (plugin.open) + yield plugin.open(); } }); @@ -421,7 +424,8 @@ Node.prototype.closePlugins = co(function* closePlugins() { for (i = 0; i < this.stack.length; i++) { plugin = this.stack[i]; - yield plugin.close(); + if (plugin.close) + yield plugin.close(); } });