| 575 | } |
| 576 | |
| 577 | const spawn = ( |
| 578 | spawnProcess: SpawnProcess, |
| 579 | command: ChildProcess.StandardCommand, |
| 580 | spawnOptions: NodeChildProcess.SpawnOptions, |
| 581 | halfOpen: ReadonlyArray<number> |
| 582 | ) => |
| 583 | Effect.callback< |
| 584 | readonly [SpawnedProcess, ExitSignal], |
| 585 | PlatformError.PlatformError |
| 586 | >((resume) => { |
| 587 | const deferred = Deferred.makeUnsafe<ExitCodeWithSignal, PlatformError.PlatformError>() |
| 588 | const onError = (error: unknown) => { |
| 589 | const err = toError(error) |
| 590 | // Node copies the arguments into `spawnargs`. |
| 591 | if (command.args.some(Redacted.isRedacted)) { |
| 592 | Object.assign(err, { |
| 593 | spawnargs: [command.command, ...command.args.map((arg) => Redacted.isRedacted(arg) ? "<redacted>" : arg)] |
| 594 | }) |
| 595 | } |
| 596 | resume(Effect.fail(toPlatformError("spawn", err, command))) |
| 597 | } |
| 598 | let handle: SpawnedProcess |
| 599 | try { |
| 600 | handle = spawnProcess( |
| 601 | command.command, |
| 602 | command.args.map(unwrap), |
| 603 | spawnOptions, |
| 604 | halfOpen |
| 605 | ) |
| 606 | } catch (error) { |
| 607 | onError(error) |
| 608 | return |
| 609 | } |
| 610 | handle.on("error", onError) |
| 611 | handle.on("exit", (...args: ExitCodeWithSignal) => { |
| 612 | Deferred.doneUnsafe(deferred, Exit.succeed(args)) |
| 613 | }) |
| 614 | handle.on("lost", (error: Error) => { |
| 615 | Deferred.doneUnsafe(deferred, Exit.fail(toPlatformError("exitCode", error, command))) |
| 616 | }) |
| 617 | handle.on("spawn", () => { |
| 618 | resume(Effect.succeed([handle, deferred])) |
| 619 | }) |
| 620 | return Effect.sync(() => { |
| 621 | handle.kill("SIGTERM") |
| 622 | }) |
| 623 | }) |
| 624 | |
| 625 | const killProcessGroup = ( |
| 626 | command: ChildProcess.StandardCommand, |