From 8eba20f55e31967604b2c55e6eea393d84f6c2d2 Mon Sep 17 00:00:00 2001 From: harryadel Date: Fri, 21 Oct 2022 12:13:59 +0200 Subject: [PATCH] [webapp] Remove underscore --- packages/webapp/package.js | 4 ++-- packages/webapp/webapp_server.js | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/webapp/package.js b/packages/webapp/package.js index 5464ea7dc8..7459ba1903 100644 --- a/packages/webapp/package.js +++ b/packages/webapp/package.js @@ -15,6 +15,7 @@ Npm.depends({ qs: '6.10.1', useragent: '2.3.0', '@vlasky/whomst': '0.1.7', + 'lodash.has': '4.5.2' }); Npm.strip({ @@ -32,7 +33,6 @@ Package.onUse(function(api) { api.use( [ 'logging', - 'underscore', 'routepolicy', 'modern-browsers', 'boilerplate-generator', @@ -60,7 +60,7 @@ Package.onUse(function(api) { }); Package.onTest(function(api) { - api.use(['tinytest', 'ecmascript', 'webapp', 'http', 'underscore']); + api.use(['tinytest', 'ecmascript', 'webapp', 'http']); api.addFiles('webapp_tests.js', 'server'); api.addFiles('webapp_client_tests.js', 'client'); api.addFiles('socket_file_tests.js', 'server'); diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index 03d6de971b..8ad6c220d1 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -20,6 +20,7 @@ import { } from './socket_file.js'; import cluster from 'cluster'; import whomst from '@vlasky/whomst'; +import has from 'lodash.has'; var SHORT_SOCKET_TIMEOUT = 5 * 1000; var LONG_SOCKET_TIMEOUT = 120 * 1000; @@ -194,12 +195,12 @@ WebApp.categorizeRequest = function(req) { var htmlAttributeHooks = []; var getHtmlAttributes = function(request) { var combinedAttributes = {}; - _.each(htmlAttributeHooks || [], function(hook) { + (htmlAttributeHooks || []).forEach(function(hook) { var attributes = hook(request); if (attributes === null) return; if (typeof attributes !== 'object') throw Error('HTML attribute hook must return null or object'); - _.extend(combinedAttributes, attributes); + Object.assign(combinedAttributes, attributes); }); return combinedAttributes; }; @@ -282,7 +283,7 @@ WebApp._timeoutAdjustmentRequestCallback = function(req, res) { res.on('finish', function() { res.setTimeout(SHORT_SOCKET_TIMEOUT); }); - _.each(finishListeners, function(l) { + finishListeners.forEach(function(l) { res.on('finish', l); }); }; @@ -435,13 +436,14 @@ function getBoilerplateAsync(request, arch) { }); }); runtimeConfig.isUpdatedByArch[arch] = false; + const { dynamicHead, dynamicBody } = request; const data = Object.assign( {}, boilerplate.baseData, { htmlAttributes: getHtmlAttributes(request), }, - _.pick(request, 'dynamicHead', 'dynamicBody') + { dynamicHead, dynamicBody } ); let madeChanges = false; @@ -524,9 +526,8 @@ WebAppInternals.generateBoilerplateInstance = function( return pathJoin(archPath[arch], itemPath); }, baseDataExtension: { - additionalStaticJs: _.map(additionalStaticJs || [], function( - contents, - pathname + additionalStaticJs: (Object.entries(additionalStaticJs) || []).map(function( + [pathname, contents] ) { return { pathname: pathname, @@ -603,7 +604,7 @@ WebAppInternals.staticFilesMiddleware = async function( }; if ( - _.has(additionalStaticJs, pathname) && + has(additionalStaticJs, pathname) && !WebAppInternals.inlineScriptsAllowed() ) { serveStaticJs(additionalStaticJs[pathname]); @@ -1338,7 +1339,7 @@ function runWebAppServer() { }); // start up app - _.extend(WebApp, { + Object.assign(WebApp, { connectHandlers: packageAndAppHandlers, rawConnectHandlers: rawConnectHandlers, httpServer: httpServer,