Home / File/ moduleRunnerTransport.ts — vite Source File

moduleRunnerTransport.ts — vite Source File

Architecture documentation for moduleRunnerTransport.ts, a typescript file in the vite codebase. 8 imports, 5 dependents.

File typescript HMRClient WebSocketTransport 8 imports 5 dependents 5 functions

Entity Profile

Dependency Diagram

graph LR
  a469d907_868c_e1c2_3f7a_7aaf42cc6a7a["moduleRunnerTransport.ts"]
  abfc9e70_3c15_b3f0_a595_3cf27afb7e64["utils.ts"]
  a469d907_868c_e1c2_3f7a_7aaf42cc6a7a --> abfc9e70_3c15_b3f0_a595_3cf27afb7e64
  5b95806c_6cb8_a9a6_1dd6_709fd3849415["promiseWithResolvers"]
  a469d907_868c_e1c2_3f7a_7aaf42cc6a7a --> 5b95806c_6cb8_a9a6_1dd6_709fd3849415
  e967e251_52a9_6dc8_9c8c_4a18ba126272["invokeMethods.ts"]
  a469d907_868c_e1c2_3f7a_7aaf42cc6a7a --> e967e251_52a9_6dc8_9c8c_4a18ba126272
  d53ca642_087e_0a26_5b0f_e0a3d92124ea["InvokeMethods"]
  a469d907_868c_e1c2_3f7a_7aaf42cc6a7a --> d53ca642_087e_0a26_5b0f_e0a3d92124ea
  2fc97643_e8e5_1e4c_d3b6_86dbedccbf1a["InvokeResponseData"]
  a469d907_868c_e1c2_3f7a_7aaf42cc6a7a --> 2fc97643_e8e5_1e4c_d3b6_86dbedccbf1a
  09164238_20c3_8da3_bec2_7caf2e1f3da9["InvokeSendData"]
  a469d907_868c_e1c2_3f7a_7aaf42cc6a7a --> 09164238_20c3_8da3_bec2_7caf2e1f3da9
  7311ee1f_e4d1_bbee_9118_c5b8022c30f0["non-secure"]
  a469d907_868c_e1c2_3f7a_7aaf42cc6a7a --> 7311ee1f_e4d1_bbee_9118_c5b8022c30f0
  ccb8a028_b1ec_3743_cfbe_0ac5315bc7c3["hmrPayload"]
  a469d907_868c_e1c2_3f7a_7aaf42cc6a7a --> ccb8a028_b1ec_3743_cfbe_0ac5315bc7c3
  85908ff5_4d12_826d_8235_531f91538758["client.ts"]
  85908ff5_4d12_826d_8235_531f91538758 --> a469d907_868c_e1c2_3f7a_7aaf42cc6a7a
  29e248d2_9983_1037_00e6_8bcd9ee87840["runner.ts"]
  29e248d2_9983_1037_00e6_8bcd9ee87840 --> a469d907_868c_e1c2_3f7a_7aaf42cc6a7a
  bf48f7e9_65f6_54c3_7dce_f44769180bd7["types.ts"]
  bf48f7e9_65f6_54c3_7dce_f44769180bd7 --> a469d907_868c_e1c2_3f7a_7aaf42cc6a7a
  d14cf24c_f830_6905_0df1_4e9b0f67c84b["serverModuleRunner.ts"]
  d14cf24c_f830_6905_0df1_4e9b0f67c84b --> a469d907_868c_e1c2_3f7a_7aaf42cc6a7a
  56154347_d0e1_1403_ce0e_25508620362c["hmr.ts"]
  56154347_d0e1_1403_ce0e_25508620362c --> a469d907_868c_e1c2_3f7a_7aaf42cc6a7a
  style a469d907_868c_e1c2_3f7a_7aaf42cc6a7a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { nanoid } from 'nanoid/non-secure'
import type { CustomPayload, HotPayload } from '#types/hmrPayload'
import { promiseWithResolvers } from './utils'
import type {
  InvokeMethods,
  InvokeResponseData,
  InvokeSendData,
} from './invokeMethods'

export type ModuleRunnerTransportHandlers = {
  onMessage: (data: HotPayload) => void
  onDisconnection: () => void
}

/**
 * "send and connect" or "invoke" must be implemented
 */
export interface ModuleRunnerTransport {
  connect?(handlers: ModuleRunnerTransportHandlers): Promise<void> | void
  disconnect?(): Promise<void> | void
  send?(data: HotPayload): Promise<void> | void
  invoke?(data: HotPayload): Promise<{ result: any } | { error: any }>
  timeout?: number
}

type InvokeableModuleRunnerTransport = Omit<ModuleRunnerTransport, 'invoke'> & {
  invoke<T extends keyof InvokeMethods>(
    name: T,
    data: Parameters<InvokeMethods[T]>,
  ): Promise<ReturnType<Awaited<InvokeMethods[T]>>>
}

function reviveInvokeError(e: any) {
  const error = new Error(e.message || 'Unknown invoke error')
  Object.assign(error, e, {
    // pass the whole error instead of just the stacktrace
    // so that it gets formatted nicely with console.log
    runnerError: new Error('RunnerError'),
  })
  return error
}

const createInvokeableTransport = (
  transport: ModuleRunnerTransport,
): InvokeableModuleRunnerTransport => {
  if (transport.invoke) {
    return {
      ...transport,
      async invoke(name, data) {
        const result = await transport.invoke!({
          type: 'custom',
          event: 'vite:invoke',
          data: {
            id: 'send',
            name,
            data,
          } satisfies InvokeSendData,
        } satisfies CustomPayload)
        if ('error' in result) {
          throw reviveInvokeError(result.error)
// ... (268 more lines)

Domain

Subdomains

Frequently Asked Questions

What does moduleRunnerTransport.ts do?
moduleRunnerTransport.ts is a source file in the vite codebase, written in typescript. It belongs to the HMRClient domain, WebSocketTransport subdomain.
What functions are defined in moduleRunnerTransport.ts?
moduleRunnerTransport.ts defines 5 function(s): createInvokeableTransport, createWebSocketModuleRunnerTransport, data, normalizeModuleRunnerTransport, reviveInvokeError.
What does moduleRunnerTransport.ts depend on?
moduleRunnerTransport.ts imports 8 module(s): InvokeMethods, InvokeResponseData, InvokeSendData, hmrPayload, invokeMethods.ts, non-secure, promiseWithResolvers, utils.ts.
What files import moduleRunnerTransport.ts?
moduleRunnerTransport.ts is imported by 5 file(s): client.ts, hmr.ts, runner.ts, serverModuleRunner.ts, types.ts.
Where is moduleRunnerTransport.ts in the architecture?
moduleRunnerTransport.ts is located at packages/vite/src/shared/moduleRunnerTransport.ts (domain: HMRClient, subdomain: WebSocketTransport, directory: packages/vite/src/shared).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free