File tree Expand file tree Collapse file tree 15 files changed +167
-108
lines changed Expand file tree Collapse file tree 15 files changed +167
-108
lines changed Original file line number Diff line number Diff line change 1
- import type { ServerFunctionsDump } from '../../shared/types '
1
+ import type { ServerFunctionsDump } from '../../node/rpc '
2
2
import type { Backend } from '../types/backend'
3
3
import { useRuntimeConfig } from '#app/nuxt'
4
4
import { parse } from 'structured-clone-es'
@@ -29,8 +29,8 @@ export function createStaticBackend(): Backend {
29
29
connectionError : error ,
30
30
connect ( ) { } ,
31
31
functions : {
32
- getPayload : ( ) => {
33
- return getDump . then ( dump => dump . getPayload )
32
+ 'vite:get-payload' : async ( ) => {
33
+ return getDump . then ( dump => dump [ 'vite:get-payload' ] )
34
34
} ,
35
35
} ,
36
36
}
Original file line number Diff line number Diff line change 1
- import type { ClientFunctions , ServerFunctions } from '../../shared/types'
1
+ import type { ServerFunctions } from '../../node/rpc'
2
+ import type { ClientFunctions } from '../../shared/types'
2
3
import type { Backend } from '../types/backend'
3
4
import { createBirpc } from 'birpc'
4
5
import { parse , stringify } from 'structured-clone-es'
@@ -86,17 +87,17 @@ export function createWebSocketBackend(options: WebSocketBackendOptions): Backen
86
87
} ,
87
88
isDynamic : true ,
88
89
functions : {
89
- getPayload : async ( ) => {
90
+ 'vite:get-payload' : async ( ) => {
90
91
try {
91
- return await rpc . getPayload ( )
92
+ return await rpc [ 'vite:get-payload' ] ( )
92
93
}
93
94
catch ( err ) {
94
95
error . value = err
95
96
throw err
96
97
}
97
98
} ,
98
- openInEditor : ( filename : string ) => rpc . openInEditor . asEvent ( filename ) ,
99
- openInFinder : ( filename : string ) => rpc . openInFinder . asEvent ( filename ) ,
99
+ 'vite:open-in-editor' : async ( filename : string ) => rpc [ 'vite:open-in-editor' ] . asEvent ( filename ) ,
100
+ 'vite:open-in-finder' : async ( filename : string ) => rpc [ 'vite:open-in-finder' ] . asEvent ( filename ) ,
100
101
} ,
101
102
}
102
103
}
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ const ws = createWsServer({
10
10
} ) . then ( ( ws ) => {
11
11
// Warm up the payload
12
12
setTimeout ( ( ) => {
13
- ws . serverFunctions . getPayload ( )
13
+ ws . serverFunctions [ 'vite:get-payload' ] ( )
14
14
} , 1 )
15
15
return ws
16
16
} )
Original file line number Diff line number Diff line change @@ -4,5 +4,5 @@ import { ref } from 'vue'
4
4
export const rawEvents = ref < any > ( [ ] )
5
5
6
6
export async function fetchData ( backend : Backend ) {
7
- rawEvents . value = await backend . functions . getPayload ( )
7
+ rawEvents . value = await backend . functions [ 'vite:get-payload' ] ( )
8
8
}
Original file line number Diff line number Diff line change 1
1
import type { Ref } from 'vue'
2
- import type { ServerFunctions } from '../../shared/types '
2
+ import type { ServerFunctions } from '../../node/rpc '
3
3
4
4
export type Functions =
5
5
& Partial < ServerFunctions >
6
- & Pick < ServerFunctions , 'getPayload ' >
6
+ & Pick < ServerFunctions , 'vite:get-payload ' >
7
7
8
8
export interface Backend {
9
9
name : string
Original file line number Diff line number Diff line change 1
- import type { ServerFunctionsDump } from '../shared/types '
1
+ import type { ServerFunctionsDump } from './rpc '
2
2
import { existsSync } from 'node:fs'
3
+
3
4
import fs from 'node:fs/promises'
4
5
import process from 'node:process'
5
-
6
6
import c from 'ansis'
7
7
import cac from 'cac'
8
8
import { getPort } from 'get-port-please'
31
31
const cwd = process . cwd ( )
32
32
const outDir = resolve ( cwd , options . outDir )
33
33
34
- const rpc = await import ( './rpc' ) . then ( r => r . createServerFunctions ( {
35
- cwd ,
36
- configFile : options . config ,
37
- mode : 'build' ,
38
- } ) )
34
+ const rpc = await import ( './functions' )
35
+ . then ( async r => await r . createServerFunctions ( {
36
+ cwd ,
37
+ mode : 'build' ,
38
+ } ) )
39
39
const rpcDump : ServerFunctionsDump = {
40
- getPayload : await rpc . getPayload ( ) ,
40
+ 'vite:get-payload' : await rpc [ 'vite:get-payload' ] ( ) ,
41
41
}
42
42
43
43
let baseURL = options . base
89
89
90
90
const { server, ws } = await createHostServer ( {
91
91
cwd : options . root ,
92
- configFile : options . config ,
93
92
mode : 'dev' ,
94
93
} )
95
94
96
95
// Warm up the payload
97
96
setTimeout ( ( ) => {
98
- ws . serverFunctions . getPayload ( )
97
+ ws . serverFunctions [ 'vite:get-payload' ] ( )
99
98
} , 1 )
100
99
101
100
server . listen ( port , host , async ( ) => {
Original file line number Diff line number Diff line change
1
+ import type { ServerFunctions } from './rpc/index'
2
+ import { rpcFunctions } from './rpc/index'
3
+
4
+ export interface CreateServerFunctionsOptions {
5
+ cwd : string
6
+ mode : 'dev' | 'build'
7
+ }
8
+
9
+ export async function createServerFunctions ( options : CreateServerFunctionsOptions ) : Promise < ServerFunctions > {
10
+ const functions = await Promise . all (
11
+ rpcFunctions
12
+ . map ( async fn => [ fn . name , ( await fn . setup ( options ) ) . handler ] ) ,
13
+ )
14
+ return Object . fromEntries ( functions )
15
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { defineRpcFunction } from '../types'
2
+
3
+ export const getPayload = defineRpcFunction ( {
4
+ name : 'vite:get-payload' ,
5
+ type : 'static' ,
6
+ setup : ( ) => ( {
7
+ handler : async ( ) => ( {
8
+ timestamp : Date . now ( ) ,
9
+ } ) ,
10
+ } ) ,
11
+ } )
Original file line number Diff line number Diff line change
1
+ import { defineRpcFunction } from '../types'
2
+
3
+ export const openInEditor = defineRpcFunction ( {
4
+ name : 'vite:open-in-editor' ,
5
+ type : 'action' ,
6
+ setup : ( ) => ( {
7
+ handler : async ( path : string ) => {
8
+ await import ( 'launch-editor' ) . then ( r => r . default ( path ) )
9
+ } ,
10
+ } ) ,
11
+ } )
You can’t perform that action at this time.
0 commit comments