ws.ts — vite Source File
Architecture documentation for ws.ts, a typescript file in the vite codebase. 20 imports, 3 dependents.
Entity Profile
Dependency Diagram
graph LR cab2c96f_4573_f58d_dd64_51e96c3e5033["ws.ts"] 031bc221_67a8_c579_f2bf_bb30a08beeb2["utils.ts"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> 031bc221_67a8_c579_f2bf_bb30a08beeb2 2aff86e8_0c9d_22cb_6536_c1321e1aaa1d["isObject"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> 2aff86e8_0c9d_22cb_6536_c1321e1aaa1d 18db4f26_79f1_5b7d_b291_4feeaf95538f["hmr.ts"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> 18db4f26_79f1_5b7d_b291_4feeaf95538f f5cc9b75_d630_dfc5_77e6_726986e86c3b["NormalizedHotChannel"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> f5cc9b75_d630_dfc5_77e6_726986e86c3b f787c9f6_73f0_9da8_98fc_e766cf9bfafe["NormalizedHotChannelClient"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> f787c9f6_73f0_9da8_98fc_e766cf9bfafe 743fd3ce_caa4_d18b_5e53_7a8e20b91e4c["normalizeHotChannel"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> 743fd3ce_caa4_d18b_5e53_7a8e20b91e4c 51e96894_3556_ed5c_1ede_97d449867adf["node:path"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> 51e96894_3556_ed5c_1ede_97d449867adf 946bdba3_227b_3fc0_1b4c_ddbdb281f454["node:http"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> 946bdba3_227b_3fc0_1b4c_ddbdb281f454 d3247ce3_3db4_c9bd_3925_57eb350e29ff["node:https"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> d3247ce3_3db4_c9bd_3925_57eb350e29ff 689e5a7c_b7c2_0909_a0c2_a9564d811346["node:net"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> 689e5a7c_b7c2_0909_a0c2_a9564d811346 72ef175c_11fd_f61f_3882_864645ae978a["node:stream"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> 72ef175c_11fd_f61f_3882_864645ae978a 9e678916_202a_edec_9e08_b4e120d4b153["node:crypto"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> 9e678916_202a_edec_9e08_b4e120d4b153 bff4f846_ab01_b5ba_74d4_c1608e434d2c["picocolors"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> bff4f846_ab01_b5ba_74d4_c1608e434d2c c451f58f_4c4a_55a5_821f_db2d75f1115d["ws"] cab2c96f_4573_f58d_dd64_51e96c3e5033 --> c451f58f_4c4a_55a5_821f_db2d75f1115d style cab2c96f_4573_f58d_dd64_51e96c3e5033 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import path from 'node:path'
import type { IncomingMessage, Server } from 'node:http'
import { STATUS_CODES, createServer as createHttpServer } from 'node:http'
import type { ServerOptions as HttpsServerOptions } from 'node:https'
import { createServer as createHttpsServer } from 'node:https'
import type { Socket } from 'node:net'
import type { Duplex } from 'node:stream'
import crypto from 'node:crypto'
import colors from 'picocolors'
import type { WebSocket as WebSocketRaw } from 'ws'
import { WebSocketServer as WebSocketServerRaw_ } from 'ws'
import { isHostAllowed } from 'host-validation-middleware'
import type { WebSocket as WebSocketTypes } from '#dep-types/ws'
import type {
ErrorPayload,
FullReloadPayload,
HotPayload,
} from '#types/hmrPayload'
import type { InferCustomEventPayload } from '#types/customEvent'
import type { ResolvedConfig } from '..'
import { isObject } from '../utils'
import type { NormalizedHotChannel, NormalizedHotChannelClient } from './hmr'
import { normalizeHotChannel } from './hmr'
import type { HttpServer } from '.'
/* In Bun, the `ws` module is overridden to hook into the native code. Using the bundled `js` version
* of `ws` will not work as Bun's req.socket does not allow reading/writing to the underlying socket.
*/
const WebSocketServerRaw = process.versions.bun
? // @ts-expect-error: Bun defines `import.meta.require`
import.meta.require('ws').WebSocketServer
: WebSocketServerRaw_
export const HMR_HEADER = 'vite-hmr'
export type WebSocketCustomListener<T> = (
data: T,
client: WebSocketClient,
) => void
export const isWebSocketServer: unique symbol = Symbol('isWebSocketServer')
export interface WebSocketServer extends NormalizedHotChannel {
/**
* Handle custom event emitted by `import.meta.hot.send`
*/
on: WebSocketTypes.Server['on'] & {
<T extends string>(
event: T,
listener: WebSocketCustomListener<InferCustomEventPayload<T>>,
): void
}
/**
* Unregister event listener.
*/
off: WebSocketTypes.Server['off'] & {
(event: string, listener: Function): void
}
/**
* Listen on port and host
// ... (408 more lines)
Domain
Subdomains
Dependencies
- .
- ..
- NormalizedHotChannel
- NormalizedHotChannelClient
- customEvent
- hmr.ts
- hmrPayload
- host-validation-middleware
- isObject
- node:crypto
- node:http
- node:https
- node:net
- node:path
- node:stream
- normalizeHotChannel
- picocolors
- utils.ts
- ws
- ws
Imported By
Source
Frequently Asked Questions
What does ws.ts do?
ws.ts is a source file in the vite codebase, written in typescript. It belongs to the ViteCore domain, ConfigEngine subdomain.
What functions are defined in ws.ts?
ws.ts defines 4 function(s): createWebSocketServer, data, hasValidToken, noop.
What does ws.ts depend on?
ws.ts imports 20 module(s): ., .., NormalizedHotChannel, NormalizedHotChannelClient, customEvent, hmr.ts, hmrPayload, host-validation-middleware, and 12 more.
What files import ws.ts?
ws.ts is imported by 3 file(s): config.ts, environment.ts, index.ts.
Where is ws.ts in the architecture?
ws.ts is located at packages/vite/src/node/server/ws.ts (domain: ViteCore, subdomain: ConfigEngine, directory: packages/vite/src/node/server).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free