File tree Expand file tree Collapse file tree 2 files changed +41
-17
lines changed
Expand file tree Collapse file tree 2 files changed +41
-17
lines changed Original file line number Diff line number Diff line change 1+ import type { DevToolsNodeContext } from '@vitejs/devtools-kit'
2+ import type { SharedState } from '@vitejs/devtools-kit/utils/shared-state'
3+ import { join } from 'pathe'
4+ import { createStorage } from './storage'
5+
6+ export interface InternalAnonymousAuthStorage {
7+ trusted : Record < string , {
8+ authId : string
9+ ua : string
10+ origin : string
11+ timestamp : number
12+ } >
13+ }
14+
15+ export interface DevToolsInternalContext {
16+ storage : {
17+ auth : SharedState < InternalAnonymousAuthStorage >
18+ }
19+ }
20+
21+ export const internalContextMap = new WeakMap < DevToolsNodeContext , DevToolsInternalContext > ( )
22+
23+ export function getInternalContext ( context : DevToolsNodeContext ) : DevToolsInternalContext {
24+ if ( ! internalContextMap . has ( context ) ) {
25+ const internalContext : DevToolsInternalContext = {
26+ storage : {
27+ auth : createStorage < InternalAnonymousAuthStorage > ( {
28+ filepath : join ( context . workspaceRoot , 'node_modules/.vite/devtools/auth.json' ) ,
29+ initialValue : {
30+ trusted : { } ,
31+ } ,
32+ } ) ,
33+ } ,
34+ }
35+ internalContextMap . set ( context , internalContext )
36+ }
37+ return internalContextMap . get ( context ) !
38+ }
Original file line number Diff line number Diff line change 11import * as p from '@clack/prompts'
22import { defineRpcFunction } from '@vitejs/devtools-kit'
33import c from 'ansis'
4- import { join } from 'pathe'
5- import { createStorage } from '../../storage'
4+ import { getInternalContext } from '../../context-internal'
65
76export interface DevToolsAuthInput {
87 authId : string
@@ -14,25 +13,12 @@ export interface DevToolsAuthReturn {
1413 isTrusted : boolean
1514}
1615
17- interface AnonymousAuthStorage {
18- trusted : Record < string , {
19- authId : string
20- ua : string
21- origin : string
22- timestamp : number
23- } >
24- }
25-
2616export const anonymousAuth = defineRpcFunction ( {
2717 name : 'vite:anonymous:auth' ,
2818 type : 'action' ,
2919 setup : ( context ) => {
30- const storage = createStorage < AnonymousAuthStorage > ( {
31- filepath : join ( context . cwd , 'node_modules/.vite/devtools/auth.json' ) ,
32- initialValue : {
33- trusted : { } ,
34- } ,
35- } )
20+ const internal = getInternalContext ( context )
21+ const storage = internal . storage . auth
3622
3723 return {
3824 handler : async ( query : DevToolsAuthInput ) : Promise < DevToolsAuthReturn > => {
You can’t perform that action at this time.
0 commit comments