Skip to content

Commit 516d4d4

Browse files
committed
feat: add authId option to DevToolsOptions
1 parent 9840419 commit 516d4d4

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

packages/core/src/node/plugins/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ export interface DevToolsOptions {
99
* @default true
1010
*/
1111
builtinDevTools?: boolean
12+
/**
13+
* Use a fixed auth id for all clients connecting to the devtools.
14+
*/
15+
authId?: string
1216
}
1317

1418
export async function DevTools(options: DevToolsOptions = {}): Promise<Plugin[]> {
1519
const {
1620
builtinDevTools = true,
21+
authId,
1722
} = options
1823

1924
const plugins = [
2025
DevToolsInjection(),
21-
DevToolsServer(),
26+
DevToolsServer({ authId }),
2227
]
2328

2429
if (builtinDevTools) {

packages/core/src/node/plugins/server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ export function renderDockImportsMap(docks: Iterable<DevToolsDockEntry>): string
3434
].join('\n')
3535
}
3636

37-
export function DevToolsServer(): Plugin {
37+
export interface DevToolsServerOptions {
38+
authId?: string
39+
}
40+
41+
export function DevToolsServer(options: DevToolsServerOptions = {}): Plugin {
3842
let context: DevToolsNodeContext
3943
return {
4044
name: 'vite:devtools:server',
@@ -51,6 +55,7 @@ export function DevToolsServer(): Plugin {
5155
cwd: viteDevServer.config.root,
5256
hostWebSocket: host,
5357
context,
58+
authId: options.authId,
5459
})
5560
viteDevServer.middlewares.use(DEVTOOLS_MOUNT_PATH, middleware)
5661
},

packages/core/src/node/ws.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface CreateWsServerOptions {
2020
hostWebSocket: string
2121
base?: string
2222
context: DevToolsNodeContext
23+
authId?: string
2324
}
2425

2526
const ANONYMOUS_SCOPE = 'vite:anonymous:'
@@ -117,6 +118,7 @@ export async function createWsServer(options: CreateWsServerOptions) {
117118
return {
118119
backend: 'websocket',
119120
websocket: port,
121+
...(options.authId ? { authId: options.authId } : {}),
120122
}
121123
}
122124

packages/kit/src/client/rpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export async function getDevToolsRpcClient(
184184
const context: DevToolsClientContext = {
185185
rpc: undefined!,
186186
}
187-
const authId = getConnectionAuthIdFromWindows(options.authId)
187+
const authId = getConnectionAuthIdFromWindows(options.authId ?? connectionMeta.authId)
188188
const clientRpc: DevToolsClientRpcHost = new RpcFunctionsCollectorBase<DevToolsRpcClientFunctions, DevToolsClientContext>(context)
189189

190190
async function fetchJsonFromBases(path: string): Promise<any> {

packages/kit/src/types/vite-plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ export interface DevToolsNodeUtils {
8686
export interface ConnectionMeta {
8787
backend: 'websocket' | 'static'
8888
websocket?: number | string
89+
authId?: string
8990
}

0 commit comments

Comments
 (0)