svelte-adapter-uws 0.4.4 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +1 -0
  2. package/package.json +1 -1
  3. package/vite.js +14 -3
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Adapter } from '@sveltejs/kit';
2
2
  import type { WebSocket } from 'uWebSockets.js';
3
+ export type { WebSocket } from 'uWebSockets.js';
3
4
 
4
5
  /**
5
6
  * ## Environment variables (runtime)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-adapter-uws",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "SvelteKit adapter for uWebSockets.js - high-performance C++ HTTP server with built-in WebSocket support",
5
5
  "author": "Kevin Radziszewski",
6
6
  "license": "MIT",
package/vite.js CHANGED
@@ -1,4 +1,3 @@
1
- import { WebSocketServer } from 'ws';
2
1
  import path from 'node:path';
3
2
  import { existsSync } from 'node:fs';
4
3
  import { parseCookies } from './files/cookies.js';
@@ -34,7 +33,7 @@ function esc(s) {
34
33
  export default function uws(options = {}) {
35
34
  const wsPath = options.path || '/ws';
36
35
 
37
- /** @type {WebSocketServer} */
36
+ /** @type {import('ws').WebSocketServer | undefined} */
38
37
  let wss;
39
38
 
40
39
  /** @type {Map<import('ws').WebSocket, Set<string>>} */
@@ -240,7 +239,7 @@ export default function uws(options = {}) {
240
239
  }
241
240
  }
242
241
  },
243
- configureServer(server) {
242
+ async configureServer(server) {
244
243
  // In middleware mode Vite does not own the HTTP server, so WS upgrade cannot be attached.
245
244
  if (!server.httpServer) {
246
245
  server.config.logger.warn(
@@ -251,6 +250,18 @@ export default function uws(options = {}) {
251
250
  return;
252
251
  }
253
252
 
253
+ /** @type {typeof import('ws').WebSocketServer} */
254
+ let WebSocketServer;
255
+ try {
256
+ ({ WebSocketServer } = await import('ws'));
257
+ } catch {
258
+ server.config.logger.warn(
259
+ '[svelte-adapter-uws] The "ws" package is not installed. ' +
260
+ 'WebSocket features are disabled in dev. Install with: npm i -D ws'
261
+ );
262
+ return;
263
+ }
264
+
254
265
  // E7: warn if our WS path collides with the Vite HMR WebSocket path.
255
266
  const hmrConfig = server.config.server?.hmr;
256
267
  if (hmrConfig && typeof hmrConfig === 'object' && hmrConfig.path === wsPath) {