From e13bd4e9f5495ae2d9a2e910516a162e9a91cf10 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Mon, 26 Apr 2021 12:11:14 +0200 Subject: [PATCH] Make certain fetchers environment-aware --- src/fetcher/dns.js | 9 ++++++++- src/fetcher/irc.js | 11 +++++++++-- src/fetcher/xmpp.js | 15 +++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/fetcher/dns.js b/src/fetcher/dns.js index 967f7b8..23f79de 100644 --- a/src/fetcher/dns.js +++ b/src/fetcher/dns.js @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const dns = require('dns') +const jsEnv = require("browser-or-node") /** * @module fetcher/dns @@ -25,6 +25,13 @@ const dns = require('dns') */ module.exports.timeout = 5000 +if (!jsEnv.isNode) { + module.exports.fn = null + return +} + +const dns = require('dns') + /** * Execute a fetch request * @function diff --git a/src/fetcher/irc.js b/src/fetcher/irc.js index 19bb39c..7a1f863 100644 --- a/src/fetcher/irc.js +++ b/src/fetcher/irc.js @@ -13,8 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const irc = require('irc-upd') -const validator = require('validator') +const jsEnv = require("browser-or-node") /** * @module fetcher/irc @@ -26,6 +25,14 @@ const validator = require('validator') */ module.exports.timeout = 20000 +if (!jsEnv.isNode) { + module.exports.fn = null + return +} + +const irc = require('irc-upd') +const validator = require('validator') + /** * Execute a fetch request * @function diff --git a/src/fetcher/xmpp.js b/src/fetcher/xmpp.js index 27ea6b3..f75c075 100644 --- a/src/fetcher/xmpp.js +++ b/src/fetcher/xmpp.js @@ -13,10 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -const jsdom = require('jsdom') -const { client, xml } = require('@xmpp/client') -const debug = require('@xmpp/debug') -const validator = require('validator') +const jsEnv = require("browser-or-node") /** * @module fetcher/xmpp @@ -28,6 +25,16 @@ const validator = require('validator') */ module.exports.timeout = 5000 +if (!jsEnv.isNode) { + module.exports.fn = null + return +} + +const jsdom = require('jsdom') +const { client, xml } = require('@xmpp/client') +const debug = require('@xmpp/debug') +const validator = require('validator') + let xmpp = null, iqCaller = null