From 65c2544ea328750e148e1d345ed50412b1e2695f Mon Sep 17 00:00:00 2001 From: Pavel Pushkarev Date: Thu, 2 Jun 2022 11:12:30 +0300 Subject: [PATCH] Allow for optional args --- src/wrap.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/wrap.ts b/src/wrap.ts index 32fd683..0265455 100644 --- a/src/wrap.ts +++ b/src/wrap.ts @@ -35,10 +35,19 @@ if (cfg.fork) { // too. We also need to relay messages about required files to the parent. const newFork = function ( modulePath: string, - args: string[], - options: ForkOptions - ) { - const child = oldFork(__filename, [modulePath].concat(args), options) + args?: string[] | ForkOptions, + options?: ForkOptions + ) { + + let forkArgs: string[]; + if (args instanceof Array) { + forkArgs = [modulePath].concat(args); + } else { + forkArgs = [modulePath]; + options = args; + } + + const child = oldFork(__filename, forkArgs, options) ipc.relay(child) return child }