From 3bf1667181ce8929bae58f7621780503147c7dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20L=C3=B8vdal?= Date: Sun, 17 Sep 2023 18:58:00 +0200 Subject: [PATCH] Refactor: extract method createLoadPromise No variable renames, just lines moved. --- .../@node-red/registry/lib/loader.js | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) 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) {