* @template T * @private * @returns {Promise } server transport
()
| 1562 | * @returns {Promise<T>} server transport |
| 1563 | */ |
| 1564 | async getServerTransport() { |
| 1565 | let implementation; |
| 1566 | let implementationFound = true; |
| 1567 | |
| 1568 | switch ( |
| 1569 | typeof ( |
| 1570 | /** @type {WebSocketServerConfiguration} */ |
| 1571 | (this.options.webSocketServer).type |
| 1572 | ) |
| 1573 | ) { |
| 1574 | case "string": |
| 1575 | // Could be 'ws', or a path that should be required |
| 1576 | if ( |
| 1577 | /** @type {WebSocketServerConfiguration} */ ( |
| 1578 | this.options.webSocketServer |
| 1579 | ).type === "ws" |
| 1580 | ) { |
| 1581 | implementation = (await import("./servers/WebsocketServer.js")) |
| 1582 | .default; |
| 1583 | } else { |
| 1584 | try { |
| 1585 | const mod = cjsRequire( |
| 1586 | /** @type {string} */ ( |
| 1587 | /** @type {WebSocketServerConfiguration} */ |
| 1588 | (this.options.webSocketServer).type |
| 1589 | ), |
| 1590 | ); |
| 1591 | |
| 1592 | implementation = mod.default || mod; |
| 1593 | } catch { |
| 1594 | implementationFound = false; |
| 1595 | } |
| 1596 | } |
| 1597 | break; |
| 1598 | case "function": |
| 1599 | implementation = |
| 1600 | /** @type {WebSocketServerConfiguration} */ |
| 1601 | (this.options.webSocketServer).type; |
| 1602 | break; |
| 1603 | default: |
| 1604 | implementationFound = false; |
| 1605 | } |
| 1606 | |
| 1607 | if (!implementationFound) { |
| 1608 | throw new Error( |
| 1609 | "webSocketServer (webSocketServer.type) must be a string denoting a default implementation (e.g. 'ws'), a resolvable module specifier or absolute file path " + |
| 1610 | "which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer.js), " + |
| 1611 | "or the class itself which extends BaseServer", |
| 1612 | ); |
| 1613 | } |
| 1614 | |
| 1615 | return implementation; |
| 1616 | } |
| 1617 | |
| 1618 | /** |
| 1619 | * @returns {string} |
no outgoing calls
no test coverage detected