diff --git a/packages/node_modules/@node-red/registry/lib/loader.js b/packages/node_modules/@node-red/registry/lib/loader.js index cfb227c92..f3762ef36 100644 --- a/packages/node_modules/@node-red/registry/lib/loader.js +++ b/packages/node_modules/@node-red/registry/lib/loader.js @@ -344,30 +344,9 @@ function loadNodeSet(node) { } else { } try { - var loadPromise = null; var r = require(node.file); r = r.__esModule ? r.default : r; - if (typeof r === "function") { - - var red = registryUtil.createNodeApi(node); - var promise = r(red); - if (promise != null && typeof promise.then === "function") { - loadPromise = promise.then(function() { - node.enabled = true; - node.loaded = true; - return node; - }).catch(function(err) { - node.err = err; - return node; - }); - } - } - if (loadPromise == null) { - node.enabled = true; - node.loaded = true; - loadPromise = Promise.resolve(node); - } - return loadPromise; + return createLoadPromise(node, r); } catch(err) { node.err = err; var stack = err.stack; @@ -391,6 +370,31 @@ function loadNodeSet(node) { } return Promise.resolve(node); } + + function createLoadPromise(node, r) { + var loadPromise = null; + if (typeof r === "function") { + + var red = registryUtil.createNodeApi(node); + var promise = r(red); + if (promise != null && typeof promise.then === "function") { + loadPromise = promise.then(function () { + node.enabled = true; + node.loaded = true; + return node; + }).catch(function (err) { + node.err = err; + return node; + }); + } + } + if (loadPromise == null) { + node.enabled = true; + node.loaded = true; + loadPromise = Promise.resolve(node); + } + return loadPromise; + } } async function loadPlugin(plugin) {