getSocketClientPath.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. function getSocketClientPath(options) {
  3. let ClientImplementation;
  4. let clientImplFound = true;
  5. switch (typeof options.transportMode.client) {
  6. case 'string':
  7. // could be 'sockjs', 'ws', or a path that should be required
  8. if (options.transportMode.client === 'sockjs') {
  9. ClientImplementation = require('../../client/clients/SockJSClient');
  10. } else if (options.transportMode.client === 'ws') {
  11. ClientImplementation = require('../../client/clients/WebsocketClient');
  12. } else {
  13. try {
  14. // eslint-disable-next-line import/no-dynamic-require
  15. ClientImplementation = require(options.transportMode.client);
  16. } catch (e) {
  17. clientImplFound = false;
  18. }
  19. }
  20. break;
  21. default:
  22. clientImplFound = false;
  23. }
  24. if (!clientImplFound) {
  25. throw new Error(
  26. "transportMode.client must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to " +
  27. 'a JS file which exports a class extending BaseClient (webpack-dev-server/client-src/clients/BaseClient) ' +
  28. 'via require.resolve(...)'
  29. );
  30. }
  31. return ClientImplementation.getClientPath(options);
  32. }
  33. module.exports = getSocketClientPath;