From 20d8a08d6bcb8dc4cbe516e19eaccfdb2fc7a80f Mon Sep 17 00:00:00 2001 From: Felipe Plets Date: Sun, 25 Mar 2018 10:17:42 -0300 Subject: [PATCH 1/2] Fix express-load when using ES6 classes --- lib/express-load.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/express-load.js b/lib/express-load.js index cc3f4f8..3d8ec08 100644 --- a/lib/express-load.js +++ b/lib/express-load.js @@ -238,7 +238,17 @@ ExpressLoad.prototype.into = function(instance, done) { next(); }); } else if (typeof mod === 'function') { - mod = mod.call(script, instance); + // Instance it as function os class + try { + mod = mod.call(script, instance); + } catch(e) { + // If the error is a TypeError, try to call it as a class constructor + if (e.name === 'TypeError') { + mod = new mod(instance); + } else { + throw e; + } + } } } From dd16994d0b0ed2edc654d97a08a9f6da16bc288c Mon Sep 17 00:00:00 2001 From: Felipe Plets Date: Thu, 29 Nov 2018 00:36:25 -0200 Subject: [PATCH 2/2] Update express-load.js --- lib/express-load.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/express-load.js b/lib/express-load.js index 3d8ec08..c4a511e 100644 --- a/lib/express-load.js +++ b/lib/express-load.js @@ -238,7 +238,7 @@ ExpressLoad.prototype.into = function(instance, done) { next(); }); } else if (typeof mod === 'function') { - // Instance it as function os class + // Instance it as function or class try { mod = mod.call(script, instance); } catch(e) {