import debug from "debug" ; import type { DebugCallback , ProcessWithPipeMessageTransport , ProcessWithWebSocketUrl , SpawnOptions , Stdio , Transport , } from "../types" ; import newProcessWithPipeMessageTransport from "./newProcessWithPipeMessageTransport" ; import newProcessWithWebSocketUrl from "./newProcessWithWebSocketUrl" ; function spawn ( executable , args , options , transport , debugCallback ? ) ; function spawn ( executable , args , options ? , transport ? , debugCallback ? ) ; function spawn ( executable , args , options = { stdio : "ignore" } , transport = "pipe" , debugCallback = debug ( "@tracerbench/spawn" ) ) { if ( typeof options === "string" ) { options = { stdio : options } ; } switch ( transport ) { case "pipe" : return newProcessWithPipeMessageTransport ( executable , args , options , debugCallback ) ; case "websocket" : return newProcessWithWebSocketUrl ( executable , args , options , debugCallback ) ; default : throw invalidTransport ( transport ) ; } } function invalidTransport ( transport ) { return new Error ( `invalid transport argument "${ String ( transport ) }"` ) ; } export default spawn ;