From 85e544afd95a5890761a613263a5eba0c9a18a93 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 4 Jun 2020 14:42:12 +0200 Subject: [PATCH] fix: remove explicit require of uws So that bundlers like webpack do not try to include it in the build. As a side-effect, any implementation which matches the API of the ws module can now be used. Before that change, you had to explicitly exclude uws: ``` // webpack.config.js module.exports = { // ... externals: { uws: 'uws' } }; ``` Related: https://github.com/socketio/engine.io/issues/575 Backported from master: https://github.com/socketio/engine.io/commit/82cdca23bab0ed69b61b60961900d456a3065e6a --- lib/server.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/server.js b/lib/server.js index 3fbee3e07..6d998e8fb 100644 --- a/lib/server.js +++ b/lib/server.js @@ -102,12 +102,8 @@ Server.prototype.init = function () { if (this.ws) this.ws.close(); - var wsModule; - switch (this.wsEngine) { - case 'uws': wsModule = require('uws'); break; - case 'ws': wsModule = require('ws'); break; - default: throw new Error('unknown wsEngine'); - } + // add explicit require for bundlers like webpack + var wsModule = this.wsEngine === 'ws' ? require('ws') : require(this.wsEngine); this.ws = new wsModule.Server({ noServer: true, clientTracking: false,