From e5a824d6dca51d1abaf000d0dc5da4ceb6a2432b Mon Sep 17 00:00:00 2001 From: Nazar Leush Date: Thu, 14 Oct 2021 17:34:36 +0300 Subject: [PATCH] remove all old exports --- .../templates/config.local.js.j2 | 8 ++----- app.js | 7 ++---- config.js | 4 ++-- config.local.js.SAMPLE | 8 ++----- config.test.js | 10 ++------ config.test_with_custom_plugins.js | 9 ++----- lib/cache-engines/memcached.js | 20 ++++++++-------- lib/cache-engines/no-cache.js | 10 +++----- lib/cache-engines/redis.js | 20 +++++++--------- lib/loader/pluginLoader.js | 4 ---- .../CollectingHandlerForMutliTarget.js | 6 ++--- lib/plugins/system/meta/HTMLMetaHandler.js | 8 +++---- lib/plugins/system/meta/ld-json.js | 4 ++-- lib/plugins/system/meta/utils.js | 4 ++-- lib/plugins/system/oembed/oembedUtils.js | 6 ++--- modules/tests-ui/models.js | 11 ++++----- modules/tests-ui/utils.js | 24 +++++++++---------- plugins/custom/noindex/utils.js | 4 ++-- plugins/meta/description-from-p-tag.js | 2 +- server.js | 4 +--- 20 files changed, 64 insertions(+), 109 deletions(-) diff --git a/ansible-docker-iframely/templates/config.local.js.j2 b/ansible-docker-iframely/templates/config.local.js.j2 index bde5aaa8c..bbf786599 100644 --- a/ansible-docker-iframely/templates/config.local.js.j2 +++ b/ansible-docker-iframely/templates/config.local.js.j2 @@ -1,5 +1,4 @@ -(function() { - var config = { + export default { // Specify a path for custom plugins. Custom plugins will override core plugins. // CUSTOM_PLUGINS_PATH: __dirname + '/yourcustom-plugin-folder', @@ -259,7 +258,4 @@ } } */ - }; - - module.exports = config; -})(); + }; \ No newline at end of file diff --git a/app.js b/app.js index 77c03a36d..2718ae0ba 100644 --- a/app.js +++ b/app.js @@ -8,13 +8,12 @@ if (!CONFIG.baseAppUrl) { console.warn('Warning: CONFIG.baseAppUrl not set, default value used'); } -import * as path from 'path'; import * as express from 'express'; import * as jsonxml from 'jsontoxml'; var NotFound = sysUtils.NotFound; -var app = express(); +export const app = express(); app.set('view engine', 'ejs'); @@ -174,6 +173,4 @@ app.get('/', function(req, res) { }); process.title = "iframely"; -process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; - -module.exports = app; +process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; \ No newline at end of file diff --git a/config.js b/config.js index 6da7fe620..83472b6ab 100644 --- a/config.js +++ b/config.js @@ -12,7 +12,7 @@ const json = JSON.parse(await readFile(new URL('./package.json', import.meta.url))); var version = json.version; - var config = { + const config = { baseAppUrl: "", port: 8061, @@ -430,4 +430,4 @@ config.HTTP2_RETRY_CODES[item] = 1; }); - export default config; + export default config; \ No newline at end of file diff --git a/config.local.js.SAMPLE b/config.local.js.SAMPLE index 02382972b..88a8cf8e6 100644 --- a/config.local.js.SAMPLE +++ b/config.local.js.SAMPLE @@ -1,5 +1,4 @@ -(function() { - var config = { + export default { // Specify a path for custom plugins. Custom plugins will override core plugins. // CUSTOM_PLUGINS_PATH: __dirname + '/yourcustom-plugin-folder', @@ -325,7 +324,4 @@ // Endpoint for prerender service, if you need it. Used to parse React apps. Very slow. // Tested with https://github.com/prerender/prerender // PRERENDER_URL: "https://domain/render?url=" - }; - - module.exports = config; -})(); + }; \ No newline at end of file diff --git a/config.test.js b/config.test.js index 1a4ee3ee1..0461a4ef4 100644 --- a/config.test.js +++ b/config.test.js @@ -1,7 +1,4 @@ -(function() { - - var config = { - +export default { DEBUG: true, RICH_LOG_ENABLED: true, @@ -11,7 +8,4 @@ RESPONSE_TIMEOUT: 1 * 100, //ms IGNORE_DOMAINS_RE: /blacklisted.*/ - }; - - module.exports = config; -})(); \ No newline at end of file +}; \ No newline at end of file diff --git a/config.test_with_custom_plugins.js b/config.test_with_custom_plugins.js index 2e36a421a..690852dbe 100644 --- a/config.test_with_custom_plugins.js +++ b/config.test_with_custom_plugins.js @@ -1,6 +1,4 @@ -(function() { - - var config = { + export default { CUSTOM_PLUGINS_PATH: __dirname + '/test/fixtures/custom-plugins', @@ -14,7 +12,4 @@ RESPONSE_TIMEOUT: 1 * 100, //ms IGNORE_DOMAINS_RE: /blacklisted.*/ - }; - - module.exports = config; -})(); \ No newline at end of file + }; \ No newline at end of file diff --git a/lib/cache-engines/memcached.js b/lib/cache-engines/memcached.js index 1868c3f94..3cb04fa1b 100644 --- a/lib/cache-engines/memcached.js +++ b/lib/cache-engines/memcached.js @@ -1,7 +1,9 @@ -(function(engine) { -import * as sysUtils from '../../logging.js'; -import * as crypto from 'crypto'; -import * as Memcached from 'memcached'; + + import * as sysUtils from '../../logging.js'; + import * as crypto from 'crypto'; + import * as Memcached from 'memcached'; + import * as _ from 'underscore'; + var memcached = new Memcached(CONFIG.MEMCACHED_OPTIONS && CONFIG.MEMCACHED_OPTIONS.locations, CONFIG.MEMCACHED_OPTIONS && CONFIG.MEMCACHED_OPTIONS.options); var timeout = CONFIG.MEMCACHED_OPTIONS && CONFIG.MEMCACHED_OPTIONS.options && CONFIG.MEMCACHED_OPTIONS.options.timeout; @@ -13,7 +15,7 @@ import * as Memcached from 'memcached'; } function _findKeyMeta(k) { -import * as _ from 'underscore'; + var sk = safeKey(k); @@ -51,7 +53,7 @@ import * as _ from 'underscore'; }); } - engine.set = function(_key, data, options) { + export function set(_key, data, options) { var key = (!options || !options.raw) ? safeKey(_key) : _key; @@ -75,7 +77,7 @@ import * as _ from 'underscore'; } }; - engine.get = function(_key, cb) { + export function get(_key, cb) { var key = safeKey(_key); @@ -127,8 +129,6 @@ import * as _ from 'underscore'; }); }; - engine.getClient = function() { + export function getClient() { return memcached; }; - -})(exports); \ No newline at end of file diff --git a/lib/cache-engines/no-cache.js b/lib/cache-engines/no-cache.js index 2bd2cc32b..500c6ebb3 100644 --- a/lib/cache-engines/no-cache.js +++ b/lib/cache-engines/no-cache.js @@ -1,11 +1,7 @@ -(function(engine) { - - engine.set = function(key, data) { + export function set(key, data) { }; - engine.get = function(key, cb) { + export function get(key, cb) { cb(null, null); - }; - -})(exports); \ No newline at end of file + }; \ No newline at end of file diff --git a/lib/cache-engines/redis.js b/lib/cache-engines/redis.js index 33ffc6c2a..68c42d956 100644 --- a/lib/cache-engines/redis.js +++ b/lib/cache-engines/redis.js @@ -1,18 +1,16 @@ -(function(engine) { -import * as sysUtils from '../../logging.js'; + import * as sysUtils from '../../logging.js'; var client; if (CONFIG.REDIS_MODE === 'cluster') { -import * as RedisClustr from 'redis-clustr'; - - client = new RedisClustr(CONFIG.REDIS_CLUSTER_OPTIONS); + var pkg = await import('redis-clustr'); + client = new pkg.RedisClustr(CONFIG.REDIS_CLUSTER_OPTIONS); } else { -import * as redis from 'redis'; - client = redis.createClient(CONFIG.REDIS_OPTIONS); + var pkg = await import('redis'); + client = pkg.redis.createClient(CONFIG.REDIS_OPTIONS); } - engine.set = function(key, data, options) { + export function set(key, data, options) { var multi = client.multi(); multi.set(key, JSON.stringify(data)); multi.expire(key, options && options.ttl || CONFIG.CACHE_TTL); @@ -24,7 +22,7 @@ import * as redis from 'redis'; }); }; - engine.get = function(key, cb) { + export function get(key, cb) { client.get(key, function(error, data) { @@ -45,6 +43,4 @@ import * as redis from 'redis'; cb(null, parsedData); }); - }; - -})(exports); + }; \ No newline at end of file diff --git a/lib/loader/pluginLoader.js b/lib/loader/pluginLoader.js index 8c53d3501..93be9a359 100644 --- a/lib/loader/pluginLoader.js +++ b/lib/loader/pluginLoader.js @@ -162,10 +162,6 @@ return; } - if (!plugin) { - console.error("Error loading plugin", pluginPath); - } - if (notPlugin || plugin.notPlugin) { // Skip utils modules. return; diff --git a/lib/plugins/system/htmlparser/CollectingHandlerForMutliTarget.js b/lib/plugins/system/htmlparser/CollectingHandlerForMutliTarget.js index 4956f13fa..a9aa4ce54 100644 --- a/lib/plugins/system/htmlparser/CollectingHandlerForMutliTarget.js +++ b/lib/plugins/system/htmlparser/CollectingHandlerForMutliTarget.js @@ -5,7 +5,7 @@ * * */ -function CollectingHandlerForMutliTarget(cbsArray){ +export function CollectingHandlerForMutliTarget(cbsArray){ this._cbsArray = cbsArray || []; this.events = []; } @@ -143,6 +143,4 @@ CollectingHandlerForMutliTarget.prototype._emitEventsFor = function(cbs) { } }; -module.exports = CollectingHandlerForMutliTarget; - -module.exports.notPlugin = true; \ No newline at end of file +export const notPlugin = true; \ No newline at end of file diff --git a/lib/plugins/system/meta/HTMLMetaHandler.js b/lib/plugins/system/meta/HTMLMetaHandler.js index 7827d5715..590ea2bc9 100644 --- a/lib/plugins/system/meta/HTMLMetaHandler.js +++ b/lib/plugins/system/meta/HTMLMetaHandler.js @@ -2,7 +2,7 @@ import { decodeHTML5 } from 'entities'; import * as _ from 'underscore'; import * as url from 'url'; import * as utils from '../../../utils.js'; -import * as ldParser from './ld-json.js'; +import { ldParser } from './ld-json.js'; var getCharset = utils.getCharset; var encodeText = utils.encodeText; @@ -23,7 +23,7 @@ var LINK_REL_ARRAY_VALUES = [ 'alternative' ]; -function HTMLMetaHandler(uri, contentType, callback) { +export function HTMLMetaHandler(uri, contentType, callback) { this._uri = uri; this._charset = getCharset(contentType); this._callback = callback; @@ -582,6 +582,4 @@ function merge(parentObj, props, value) { } } -module.exports = HTMLMetaHandler; - -module.exports.notPlugin = true; +export const notPlugin = true; diff --git a/lib/plugins/system/meta/ld-json.js b/lib/plugins/system/meta/ld-json.js index b5d7abe4a..9984702b7 100644 --- a/lib/plugins/system/meta/ld-json.js +++ b/lib/plugins/system/meta/ld-json.js @@ -1,7 +1,7 @@ import * as sysUtils from '../../../../logging.js'; import * as utils from '../../../utils.js'; -module.exports = function(result, decode, uri) { +export function ldParser(result, decode, uri) { var ld = result["ld-json"]; delete result["ld-json"]; @@ -51,4 +51,4 @@ module.exports = function(result, decode, uri) { } }; -module.exports.notPlugin = true; \ No newline at end of file +export const notPlugin = true; \ No newline at end of file diff --git a/lib/plugins/system/meta/utils.js b/lib/plugins/system/meta/utils.js index 90305ab42..ff5c1fa70 100644 --- a/lib/plugins/system/meta/utils.js +++ b/lib/plugins/system/meta/utils.js @@ -1,4 +1,4 @@ -exports.getMetaCacheKey = function(url, whitelistRecord, options) { +export function getMetaCacheKey(url, whitelistRecord, options) { var meta_key = 'meta:' + url; @@ -15,4 +15,4 @@ exports.getMetaCacheKey = function(url, whitelistRecord, options) { return meta_key; }; -module.exports.notPlugin = true; \ No newline at end of file +export const notPlugin = true; \ No newline at end of file diff --git a/lib/plugins/system/oembed/oembedUtils.js b/lib/plugins/system/oembed/oembedUtils.js index 6f339a39c..1e87a119c 100644 --- a/lib/plugins/system/oembed/oembedUtils.js +++ b/lib/plugins/system/oembed/oembedUtils.js @@ -11,7 +11,7 @@ var getCharset = utils.getCharset; var encodeText = utils.encodeText; var lowerCaseKeys = utils.lowerCaseKeys; -exports.notPlugin = true; +export const notPlugin = true; /** * @private @@ -84,7 +84,7 @@ function lookupStaticProviders(uri) { return links; } -module.exports.findOembedLinks = function(uri, meta) { +export function findOembedLinks(uri, meta) { // Filter oembed from meta. // allow misspelled discovery links @@ -126,7 +126,7 @@ module.exports.findOembedLinks = function(uri, meta) { * @param {String} uri Full oEmbed endpoint plus URL and any needed format parameter. * @param {Function} callback Completion callback function. The callback gets two arguments (error, oembed) where oembed is json parsed oEmbed object. * */ -module.exports.getOembed = function(uri, options, callback) { + export function getOembed(uri, options, callback) { if (typeof options === 'function') { callback = options; diff --git a/modules/tests-ui/models.js b/modules/tests-ui/models.js index 0b70bcf27..2c6320141 100644 --- a/modules/tests-ui/models.js +++ b/modules/tests-ui/models.js @@ -1,6 +1,3 @@ - if (!CONFIG.tests) { - return; - } import * as moment from 'moment'; var mongoose, db; @@ -166,7 +163,7 @@ return moment(this.created_at).format("DD-MM-YY HH:mm"); }; - exports.PluginTest = db.model('PluginTest', PluginTestSchema); - exports.PageTestLog = db.model('PageTestLog', PageTestLogSchema); - exports.TestUrlsSet = db.model('TestUrlsSet', TestUrlsSetSchema); - exports.TestingProgress = db.model('TestingProgress', TestingProgressSchema); + export const PluginTest = db.model('PluginTest', PluginTestSchema); + export const PageTestLog = db.model('PageTestLog', PageTestLogSchema); + export const TestUrlsSet = db.model('TestUrlsSet', TestUrlsSetSchema); + export const TestingProgress = db.model('TestingProgress', TestingProgressSchema); \ No newline at end of file diff --git a/modules/tests-ui/utils.js b/modules/tests-ui/utils.js index 583fae091..c9445205b 100644 --- a/modules/tests-ui/utils.js +++ b/modules/tests-ui/utils.js @@ -3,14 +3,12 @@ import * as FeedParser from 'feedparser'; import * as request from 'request'; import * as async from 'async'; import * as url from 'url'; -import * as models from './models.js'; -var PageTestLog = models.PageTestLog; -var TestUrlsSet = models.TestUrlsSet; -var PluginTest = models.PluginTest; -import { findWhitelistRecordFor as findWhitelistRecordFor } from '../../lib/whitelist'; +import { PageTestLog, TestUrlsSet, PluginTest } from './models.js'; +import { findWhitelistRecordFor } from '../../lib/whitelist'; import { getPluginData as iframelyGetPluginData } from '../../lib/core'; import * as pluginLoader from '../../lib/loader/pluginLoader.js'; import * as pluginUtils from '../../lib/loader/utils.js'; + var plugins = pluginLoader._plugins, pluginsList = pluginLoader._pluginsList, DEFAULT_PARAMS = [].concat(pluginUtils.DEFAULT_PARAMS, pluginUtils.POST_PLUGIN_DEFAULT_PARAMS), @@ -33,7 +31,7 @@ const COLORS = { const SLACK_USERNAME = "Testy"; -exports.sendQANotification = function(logEntry, data) { +export function sendQANotification(logEntry, data) { if (CONFIG.SLACK_WEBHOOK_FOR_QA && CONFIG.SLACK_CHANNEL_FOR_QA) { @@ -89,7 +87,7 @@ exports.sendQANotification = function(logEntry, data) { } function getTestsSummary(cb) { - exports.loadPluginTests(function(error, pluginTests) { + loadPluginTests(function(error, pluginTests) { pluginTests.forEach(function(pluginTest) { @@ -125,7 +123,7 @@ function getTestsSummary(cb) { }); } -exports.loadPluginTests = function(cb) { +export function loadPluginTests(cb) { var pluginTests; @@ -212,7 +210,7 @@ exports.loadPluginTests = function(cb) { }); } -exports.getPluginUnusedMethods = function(pluginId, debugData) { +export function getPluginUnusedMethods(pluginId, debugData) { var usedMethods = getAllUsedMethods(debugData); var pluginMethods = findAllPluginMethods(pluginId, plugins); @@ -224,7 +222,7 @@ exports.getPluginUnusedMethods = function(pluginId, debugData) { }; }; -exports.getErrors = function(debugData) { +export function getErrors(debugData) { var errors = []; @@ -244,7 +242,7 @@ exports.getErrors = function(debugData) { var MAX_FEED_URLS = 5; -var fetchFeedUrls = exports.fetchFeedUrls = function(feedUrl, options, cb) { +export function fetchFeedUrls(feedUrl, options, cb) { if (typeof options === "function") { cb = options; @@ -296,7 +294,7 @@ var fetchFeedUrls = exports.fetchFeedUrls = function(feedUrl, options, cb) { }); }; -exports.fetchUrlsByPageOnFeed = function(pageWithFeed, otpions, cb) { +export function fetchUrlsByPageOnFeed(pageWithFeed, otpions, cb) { if (typeof options === "function") { cb = options; @@ -339,7 +337,7 @@ exports.fetchUrlsByPageOnFeed = function(pageWithFeed, otpions, cb) { ], cb); }; -exports.fetchUrlsByPageAndSelector = function(page, selector, options, cb) { +export function fetchUrlsByPageAndSelector(page, selector, options, cb) { if (typeof options === "function") { cb = options; diff --git a/plugins/custom/noindex/utils.js b/plugins/custom/noindex/utils.js index 4f8e0889c..2b653581d 100644 --- a/plugins/custom/noindex/utils.js +++ b/plugins/custom/noindex/utils.js @@ -1,8 +1,8 @@ -exports.notPlugin = true; +export const notPlugin = true; var NO_INDEX_TAGS = ['noindex']; -exports.checkRobots = function(noindexHeader, cb) { +export function checkRobots(noindexHeader, cb) { if (noindexHeader) { var i; for(i = 0; i < NO_INDEX_TAGS.length; i++) { diff --git a/plugins/meta/description-from-p-tag.js b/plugins/meta/description-from-p-tag.js index 7a4659590..9bd81dfba 100644 --- a/plugins/meta/description-from-p-tag.js +++ b/plugins/meta/description-from-p-tag.js @@ -1,4 +1,4 @@ -import { decodeHTML5 as decodeHTML5 } from 'entities'; +import { decodeHTML5 } from 'entities'; export default { diff --git a/server.js b/server.js index b82637a72..cf5b8edd2 100644 --- a/server.js +++ b/server.js @@ -22,6 +22,4 @@ if (!CONFIG.DEBUG) { log: sysUtils.log, shutdownTimeout: CONFIG.SHUTDOWN_TIMEOUT }); -} - -module.exports = server; +} \ No newline at end of file