-
-
Notifications
You must be signed in to change notification settings - Fork 277
Expand file tree
/
Copy pathclient-react-devtools-companion.ts
More file actions
62 lines (56 loc) · 1.97 KB
/
Copy pathclient-react-devtools-companion.ts
File metadata and controls
62 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { CompanionTunnelScope } from '@agent-device/contracts/remote';
import {
ensureCompanionTunnel,
stopCompanionTunnel,
type CompanionTunnelDefinition,
type EnsureCompanionTunnelResult,
} from './client-companion-tunnel.ts';
import { REACT_DEVTOOLS_COMPANION_RUN_ARG } from './client-companion-tunnel-contract.ts';
const REACT_DEVTOOLS_LOCAL_BASE_URL = 'http://127.0.0.1:8097';
const REACT_DEVTOOLS_DEVICE_PORT = 8097;
const REACT_DEVTOOLS_REGISTER_PATH = '/api/react-devtools/companion/register';
const REACT_DEVTOOLS_UNREGISTER_PATH = '/api/react-devtools/companion/unregister';
const REACT_DEVTOOLS_COMPANION_TUNNEL: CompanionTunnelDefinition = {
slug: 'react-devtools-companion',
runArg: REACT_DEVTOOLS_COMPANION_RUN_ARG,
displayName: 'React DevTools companion',
};
export type EnsureReactDevtoolsCompanionOptions = {
projectRoot: string;
stateDir?: string;
serverBaseUrl: string;
bearerToken: string;
bridgeScope: CompanionTunnelScope;
session: string;
profileKey?: string;
consumerKey?: string;
localBaseUrl?: string;
devicePort?: number;
env?: NodeJS.ProcessEnv;
};
export type StopReactDevtoolsCompanionOptions = {
projectRoot: string;
stateDir?: string;
profileKey?: string;
consumerKey?: string;
};
export async function ensureReactDevtoolsCompanion(
options: EnsureReactDevtoolsCompanionOptions,
): Promise<EnsureCompanionTunnelResult> {
return await ensureCompanionTunnel({
...options,
definition: REACT_DEVTOOLS_COMPANION_TUNNEL,
localBaseUrl: options.localBaseUrl ?? REACT_DEVTOOLS_LOCAL_BASE_URL,
registerPath: REACT_DEVTOOLS_REGISTER_PATH,
unregisterPath: REACT_DEVTOOLS_UNREGISTER_PATH,
devicePort: options.devicePort ?? REACT_DEVTOOLS_DEVICE_PORT,
});
}
export async function stopReactDevtoolsCompanion(
options: StopReactDevtoolsCompanionOptions,
): Promise<{ stopped: boolean; statePath: string }> {
return await stopCompanionTunnel({
...options,
definition: REACT_DEVTOOLS_COMPANION_TUNNEL,
});
}