MCPcopy Index your code
hub / github.com/callstack/agent-device / startMetroProcess

Function startMetroProcess

src/metro/client-metro.ts:373–402  ·  view source on GitHub ↗
(
  projectRoot: string,
  kind: ResolvedMetroKind,
  port: number,
  listenHost: string,
  logPath: string,
  env: EnvSource,
)

Source from the content-addressed store, hash-verified

371}
372
373function 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
404async function stopSpawnedMetroProcess(pid: number): Promise<void> {
405 if (!Number.isInteger(pid) || pid <= 0) return;

Callers 1

ensureMetroProcessReadyFunction · 0.85

Calls 2

runCmdDetachedFunction · 0.90
buildMetroCommandFunction · 0.85

Tested by

no test coverage detected