@@ -2,7 +2,6 @@ import { spawn } from "child_process";
22import path from "node:path" ;
33
44import getPort from "get-port" ;
5- import { Result } from "ts-results" ;
65import { v4 } from "uuid" ;
76
87import type { AppInfo } from "../../../reducers/target" ;
@@ -33,67 +32,57 @@ export class LocalTargetAdapter implements TargetAdapter {
3332 }
3433 }
3534
36- async discoverApps ( ) : Promise < Result < AppInfo [ ] , Error > > {
37- return Result . wrapAsync ( async ( ) => {
38- const { adapter } = await importByPlatform ( ) ;
39- const result = await adapter . readAll ( ) ;
40-
41- if ( ! result . ok ) {
42- throw result . val ;
43- }
44-
45- const apps = result . val ;
46-
47- // Return apps with metadata (device context is added by caller)
48- return apps . map ( ( app ) => ( {
49- ...app ,
50- metadata : {
51- platform : process . platform ,
52- } ,
53- } ) ) ;
54- } ) ;
35+ async discoverApps ( ) : Promise < AppInfo [ ] > {
36+ const { adapter } = await importByPlatform ( ) ;
37+ const apps = await adapter . readAll ( ) ;
38+
39+ // Return apps with metadata (device context is added by caller)
40+ return apps . map ( ( app ) => ( {
41+ ...app ,
42+ metadata : {
43+ platform : process . platform ,
44+ } ,
45+ } ) ) ;
5546 }
5647
5748 async launch (
5849 app : AppInfo ,
5950 options : LaunchOptions = { } ,
60- ) : Promise < Result < DebugConnection , Error > > {
61- return Result . wrapAsync ( async ( ) => {
62- if ( ! app . exePath ) {
63- throw new Error ( "App does not have an executable path" ) ;
64- }
65-
66- const nodePort = await getPort ( ) ;
67- const windowPort = await getPort ( ) ;
68-
69- const debugFlags = options . debugFlags ?? [
70- `--inspect=${ nodePort } ` ,
71- `--remote-debugging-port=${ windowPort } ` ,
72- "--remote-allow-origins=devtools://devtools" ,
73- ] ;
74-
75- const sp = spawn ( app . exePath , debugFlags , {
76- cwd : options . cwd ?? ( process . platform === "win32" ? path . dirname ( app . exePath ) : "/" ) ,
77- env : options . env ,
78- } ) ;
79-
80- const connectionId = v4 ( ) ;
81-
82- const connection : DebugConnection = {
83- connectionId,
84- debugPorts : {
85- node : nodePort ,
86- renderer : windowPort ,
87- } ,
88- processHandle : sp ,
89- cleanup : ( ) => {
90- sp . kill ( ) ;
91- return Promise . resolve ( ) ;
92- } ,
93- } ;
94-
95- return connection ;
51+ ) : Promise < DebugConnection > {
52+ if ( ! app . exePath ) {
53+ throw new Error ( "App does not have an executable path" ) ;
54+ }
55+
56+ const nodePort = await getPort ( ) ;
57+ const windowPort = await getPort ( ) ;
58+
59+ const debugFlags = options . debugFlags ?? [
60+ `--inspect=${ nodePort } ` ,
61+ `--remote-debugging-port=${ windowPort } ` ,
62+ "--remote-allow-origins=devtools://devtools" ,
63+ ] ;
64+
65+ const sp = spawn ( app . exePath , debugFlags , {
66+ cwd : options . cwd ?? ( process . platform === "win32" ? path . dirname ( app . exePath ) : "/" ) ,
67+ env : options . env ,
9668 } ) ;
69+
70+ const connectionId = v4 ( ) ;
71+
72+ const connection : DebugConnection = {
73+ connectionId,
74+ debugPorts : {
75+ node : nodePort ,
76+ renderer : windowPort ,
77+ } ,
78+ processHandle : sp ,
79+ cleanup : ( ) => {
80+ sp . kill ( ) ;
81+ return Promise . resolve ( ) ;
82+ } ,
83+ } ;
84+
85+ return connection ;
9786 }
9887
9988 async disconnect ( ) : Promise < void > {
0 commit comments