Skip to content

Commit 8306ccc

Browse files
antfuclaude
andcommitted
refactor: move revokeAuthToken to internal context, add @vitejs/devtools/internal export
- Attach revokeAuthToken as a method on DevToolsInternalContext instead of a standalone exported function - Create @vitejs/devtools/internal sub-export for getInternalContext - Remove getInternalContext and revokeAuthToken from main entry point - Add alias and tsconfig path for @vitejs/devtools/internal - Update self-inspect to import from @vitejs/devtools/internal Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 76b4530 commit 8306ccc

11 files changed

Lines changed: 35 additions & 18 deletions

File tree

alias.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const alias = {
2020
'@vitejs/devtools-kit': r('kit/src/index.ts'),
2121
'@vitejs/devtools-rolldown': r('rolldown/src/index.ts'),
2222
'@vitejs/devtools-self-inspect': r('self-inspect/src/index.ts'),
23+
'@vitejs/devtools/internal': r('core/src/internal.ts'),
2324
'@vitejs/devtools/client/inject': r('core/src/client/inject/index.ts'),
2425
'@vitejs/devtools/client/webcomponents': r('core/src/client/webcomponents/index.ts'),
2526
'@vitejs/devtools': r('core/src/index.ts'),

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"./client/webcomponents": "./dist/client/webcomponents.js",
2828
"./config": "./dist/config.js",
2929
"./dirs": "./dist/dirs.js",
30+
"./internal": "./dist/internal.js",
3031
"./package.json": "./package.json"
3132
},
3233
"types": "./dist/index.d.ts",

packages/core/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
export { revokeAuthToken } from './node/auth-revoke'
21
export { createDevToolsContext } from './node/context'
3-
export { getInternalContext } from './node/context-internal'
42
export type { DevToolsInternalContext, InternalAnonymousAuthStorage } from './node/context-internal'
53
export { DevTools } from './node/plugins'
64
export { createDevToolsMiddleware } from './node/server'

packages/core/src/internal.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { getInternalContext } from './node/context-internal'
2+
export type { DevToolsInternalContext, InternalAnonymousAuthStorage } from './node/context-internal'

packages/core/src/node/auth-revoke.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import type { DevToolsNodeContext } from '@vitejs/devtools-kit'
2+
import type { SharedState } from '@vitejs/devtools-kit/utils/shared-state'
3+
import type { InternalAnonymousAuthStorage } from './context-internal'
24
import type { RpcFunctionsHost } from './host-functions'
3-
import { getInternalContext } from './context-internal'
45

56
/**
67
* Revoke an auth token: remove from storage and notify all connected clients
78
* using this token that they are no longer trusted.
89
*/
9-
export async function revokeAuthToken(context: DevToolsNodeContext, token: string): Promise<void> {
10-
const internal = getInternalContext(context)
11-
const storage = internal.storage.auth
12-
10+
export async function revokeAuthToken(
11+
context: DevToolsNodeContext,
12+
storage: SharedState<InternalAnonymousAuthStorage>,
13+
token: string,
14+
): Promise<void> {
1315
// Remove from persistent storage
1416
storage.mutate((state) => {
1517
delete state.trusted[token]

packages/core/src/node/context-internal.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { DevToolsNodeContext } from '@vitejs/devtools-kit'
22
import type { SharedState } from '@vitejs/devtools-kit/utils/shared-state'
33
import { homedir } from 'node:os'
44
import { join } from 'pathe'
5+
import { revokeAuthToken } from './auth-revoke'
56
import { createStorage } from './storage'
67

78
export interface InternalAnonymousAuthStorage {
@@ -17,21 +18,28 @@ export interface DevToolsInternalContext {
1718
storage: {
1819
auth: SharedState<InternalAnonymousAuthStorage>
1920
}
21+
/**
22+
* Revoke an auth token: remove from storage and notify all connected clients
23+
* using this token that they are no longer trusted.
24+
*/
25+
revokeAuthToken: (token: string) => Promise<void>
2026
}
2127

2228
export const internalContextMap = new WeakMap<DevToolsNodeContext, DevToolsInternalContext>()
2329

2430
export function getInternalContext(context: DevToolsNodeContext): DevToolsInternalContext {
2531
if (!internalContextMap.has(context)) {
32+
const storage = createStorage<InternalAnonymousAuthStorage>({
33+
filepath: join(homedir(), '.vite/devtools/auth.json'),
34+
initialValue: {
35+
trusted: {},
36+
},
37+
})
2638
const internalContext: DevToolsInternalContext = {
2739
storage: {
28-
auth: createStorage<InternalAnonymousAuthStorage>({
29-
filepath: join(homedir(), '.vite/devtools/auth.json'),
30-
initialValue: {
31-
trusted: {},
32-
},
33-
}),
40+
auth: storage,
3441
},
42+
revokeAuthToken: (token: string) => revokeAuthToken(context, storage, token),
3543
}
3644
internalContextMap.set(context, internalContext)
3745
}

packages/core/tsdown.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default defineConfig({
4848
tsconfig: '../../tsconfig.base.json',
4949
entry: {
5050
'index': 'src/index.ts',
51+
'internal': 'src/internal.ts',
5152
'dirs': 'src/dirs.ts',
5253
'cli': 'src/node/cli.ts',
5354
'cli-commands': 'src/node/cli-commands.ts',

packages/self-inspect/src/node/rpc/functions/get-auth-tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getInternalContext } from '@vitejs/devtools'
21
import { defineRpcFunction } from '@vitejs/devtools-kit'
2+
import { getInternalContext } from '@vitejs/devtools/internal'
33

44
export const getAuthTokens = defineRpcFunction({
55
name: 'devtoolskit:self-inspect:get-auth-tokens',

packages/self-inspect/src/node/rpc/functions/revoke-auth-token.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { revokeAuthToken } from '@vitejs/devtools'
21
import { defineRpcFunction } from '@vitejs/devtools-kit'
2+
import { getInternalContext } from '@vitejs/devtools/internal'
33

44
export const revokeAuthTokenRpc = defineRpcFunction({
55
name: 'devtoolskit:self-inspect:revoke-auth-token',
66
type: 'action',
77
setup: (context) => {
8+
const internal = getInternalContext(context)
89
return {
910
handler: async (authId: string) => {
10-
await revokeAuthToken(context, authId)
11+
await internal.revokeAuthToken(authId)
1112
},
1213
}
1314
},

test/exports/@vitejs/devtools.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
createDevToolsContext: function
33
createDevToolsMiddleware: function
44
DevTools: function
5-
getInternalContext: function
6-
revokeAuthToken: function
75
./cli-commands:
86
build: function
97
start: function
@@ -12,3 +10,5 @@
1210
./dirs:
1311
dirClientStandalone: string
1412
dirDist: string
13+
./internal:
14+
getInternalContext: function

0 commit comments

Comments
 (0)