1- import type { RpcFunctionsHost } from '@vitejs/devtools-kit'
1+ import type { DevToolsNodeContext } from '@vitejs/devtools-kit'
22import type { Nuxt } from 'nuxt/schema'
33
44import type { ModuleOptions , NuxtDevtoolsServerContext , ServerFunctions } from '../types'
@@ -21,15 +21,15 @@ import { setupTimelineRPC } from './timeline'
2121export function setupRPC ( nuxt : Nuxt , options : ModuleOptions ) {
2222 const serverFunctions = { } as ServerFunctions
2323 const extendedRpcMap = new Map < string , Record < string , ( ...args : any [ ] ) => any > > ( )
24- let rpcHost : RpcFunctionsHost | undefined
24+ let devtoolsKitCtx : DevToolsNodeContext | undefined
2525 const pendingBroadcasts : { method : string , args : any [ ] } [ ] = [ ]
2626
2727 function broadcast ( method : string , ...args : any [ ] ) {
28- if ( ! rpcHost ) {
28+ if ( ! devtoolsKitCtx ) {
2929 pendingBroadcasts . push ( { method, args } )
3030 return
3131 }
32- rpcHost . broadcast ( {
32+ devtoolsKitCtx . rpc . broadcast ( {
3333 method : method as any ,
3434 args : args as any ,
3535 event : true ,
@@ -61,12 +61,12 @@ export function setupRPC(nuxt: Nuxt, options: ModuleOptions) {
6161 set ( target , prop , value ) {
6262 ( target as any ) [ prop ] = value
6363 // Also update on RpcFunctionsHost if available
64- if ( rpcHost && typeof prop === 'string' ) {
65- if ( rpcHost . has ( prop ) ) {
66- rpcHost . update ( { name : prop , handler : value } )
64+ if ( devtoolsKitCtx && typeof prop === 'string' ) {
65+ if ( devtoolsKitCtx . rpc . has ( prop ) ) {
66+ devtoolsKitCtx . rpc . update ( { name : prop , handler : value } )
6767 }
6868 else {
69- rpcHost . register ( { name : prop , handler : value } )
69+ devtoolsKitCtx . rpc . register ( { name : prop , handler : value } )
7070 }
7171 }
7272 return true
@@ -86,10 +86,10 @@ export function setupRPC(nuxt: Nuxt, options: ModuleOptions) {
8686 extendedRpcMap . set ( namespace , functions )
8787
8888 // Register on RpcFunctionsHost if already available
89- if ( rpcHost ) {
89+ if ( devtoolsKitCtx ) {
9090 for ( const [ fnName , handler ] of Object . entries ( functions ) ) {
9191 if ( typeof handler === 'function' ) {
92- rpcHost . register ( { name : `${ namespace } :${ fnName } ` , handler : handler as any } )
92+ devtoolsKitCtx . rpc . register ( { name : `${ namespace } :${ fnName } ` , handler : handler as any } )
9393 }
9494 }
9595 }
@@ -106,6 +106,7 @@ export function setupRPC(nuxt: Nuxt, options: ModuleOptions) {
106106 nuxt,
107107 options,
108108 rpc : rpc as any ,
109+ get devtoolsKit ( ) { return devtoolsKitCtx } ,
109110 refresh,
110111 extendServerRpc,
111112 openInEditorHooks : [ ] ,
@@ -131,11 +132,12 @@ export function setupRPC(nuxt: Nuxt, options: ModuleOptions) {
131132 } as ServerFunctions )
132133
133134 /**
134- * Connect to Vite DevTools Kit's RPC host .
135+ * Connect to Vite DevTools Kit context .
135136 * Called from the Vite DevTools plugin setup callback.
136137 */
137- function connectRpcHost ( host : RpcFunctionsHost ) {
138- rpcHost = host
138+ function connectDevToolsKit ( ctx : DevToolsNodeContext ) {
139+ devtoolsKitCtx = ctx
140+ const host = ctx . rpc
139141
140142 // Flush any broadcasts that were queued before connection
141143 for ( const { method, args } of pendingBroadcasts ) {
@@ -183,7 +185,7 @@ export function setupRPC(nuxt: Nuxt, options: ModuleOptions) {
183185 }
184186
185187 return {
186- connectRpcHost ,
188+ connectDevToolsKit ,
187189 ...ctx ,
188190 }
189191}
0 commit comments