(appPath: string, runCommand: string, timeoutMs: number = 60_000)
| 39 | private static readonly inFlightStarts = new Map<string, Promise<void>>(); |
| 40 | |
| 41 | async startDevServer(appPath: string, runCommand: string, timeoutMs: number = 60_000): Promise<string> { |
| 42 | const serverKey = makeServerKey(appPath); |
| 43 | const prev = LaunchTool.inFlightStarts.get(appPath); |
| 44 | let resolveThis: () => void; |
| 45 | const thisRun = new Promise<void>(r => { |
| 46 | resolveThis = r; |
| 47 | }); |
| 48 | LaunchTool.inFlightStarts.set(appPath, thisRun); |
| 49 | await prev; |
| 50 | |
| 51 | try { |
| 52 | const entry = LaunchTool.serverManagers.get(serverKey); |
| 53 | if (entry) { |
| 54 | const handle = await entry.manager.restart({ timeoutMs }); |
| 55 | const result: StartDevServerResult = { |
| 56 | success: true, |
| 57 | serverKey, |
| 58 | url: handle.url, |
| 59 | port: handle.port, |
| 60 | pid: handle.child.pid ?? undefined, |
| 61 | outputTail: handle.outputTail(), |
| 62 | }; |
| 63 | return JSON.stringify(result, null, 2); |
| 64 | } |
| 65 | |
| 66 | const manager = new DevServerManager({ appPath, runCommand: runCommand.trim() }); |
| 67 | const handle = await manager.start({ timeoutMs }); |
| 68 | LaunchTool.serverManagers.set(serverKey, { manager, appPath }); |
| 69 | const result: StartDevServerResult = { |
| 70 | success: true, |
| 71 | serverKey, |
| 72 | url: handle.url, |
| 73 | port: handle.port, |
| 74 | pid: handle.child.pid ?? undefined, |
| 75 | outputTail: handle.outputTail(), |
| 76 | }; |
| 77 | return JSON.stringify(result, null, 2); |
| 78 | } catch (error) { |
| 79 | const result: StartDevServerResult = { |
| 80 | success: false, |
| 81 | error: error instanceof Error ? error.message : String(error), |
| 82 | }; |
| 83 | return JSON.stringify(result, null, 2); |
| 84 | } finally { |
| 85 | resolveThis!(); |
| 86 | LaunchTool.inFlightStarts.delete(appPath); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | async stopDevServer(serverKey: string): Promise<string> { |
| 91 | const entry = LaunchTool.serverManagers.get(serverKey); |
nothing calls this directly
no test coverage detected