( projectRoot: string, kind: ResolvedMetroKind, port: number, listenHost: string, logPath: string, env: EnvSource, )
| 371 | } |
| 372 | |
| 373 | function startMetroProcess( |
| 374 | projectRoot: string, |
| 375 | kind: ResolvedMetroKind, |
| 376 | port: number, |
| 377 | listenHost: string, |
| 378 | logPath: string, |
| 379 | env: EnvSource, |
| 380 | ): MetroProcessResult { |
| 381 | const metro = buildMetroCommand(kind, port, listenHost); |
| 382 | fs.mkdirSync(path.dirname(logPath), { recursive: true }); |
| 383 | const logFd = fs.openSync(logPath, 'a'); |
| 384 | let pid = 0; |
| 385 | try { |
| 386 | pid = runCmdDetached(metro.command, metro.installArgs, { |
| 387 | cwd: projectRoot, |
| 388 | env: env as NodeJS.ProcessEnv, |
| 389 | stdio: ['ignore', logFd, logFd], |
| 390 | }); |
| 391 | } finally { |
| 392 | fs.closeSync(logFd); |
| 393 | } |
| 394 | |
| 395 | if (!Number.isInteger(pid) || pid <= 0) { |
| 396 | throw new Error('Failed to start Metro. Expected a detached child PID.'); |
| 397 | } |
| 398 | |
| 399 | return { |
| 400 | pid, |
| 401 | }; |
| 402 | } |
| 403 | |
| 404 | async function stopSpawnedMetroProcess(pid: number): Promise<void> { |
| 405 | if (!Number.isInteger(pid) || pid <= 0) return; |
no test coverage detected