From 87f575b19077a466ec6085d21237c40f2859e14d Mon Sep 17 00:00:00 2001 From: InNoobWeTrust Date: Tue, 27 Feb 2024 18:21:08 +0700 Subject: [PATCH] feat(nitro-node): add default event handlers for nitro process --- nitro-node/src/nitro.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/nitro-node/src/nitro.ts b/nitro-node/src/nitro.ts index f31fbe284..97a7d5339 100644 --- a/nitro-node/src/nitro.ts +++ b/nitro-node/src/nitro.ts @@ -1,5 +1,6 @@ import fs from "node:fs"; import path from "node:path"; +import net from "node:net"; import stream from "node:stream"; import { ChildProcessWithoutNullStreams, spawn } from "node:child_process"; import tcpPortUsed from "tcp-port-used"; @@ -54,7 +55,29 @@ const getNitroProcessInfo = (subprocess: any): NitroProcessInfo => ({ }); const getCurrentNitroProcessInfo = () => getNitroProcessInfo(subprocess); // Default event handler: do nothing -let processEventHandler: NitroProcessEventHandler = {}; +let processEventHandler: NitroProcessEventHandler = { + close: (code: number, signal: string) => { + log(`[NITRO]::Debug: Nitro process closed with code ${code} and signal ${signal}`); + }, + disconnect: () => { + log("[NITRO]::Debug: Nitro process disconnected"); + }, + error: (e: Error) => { + log(`[NITRO]::Error: Nitro process error: ${JSON.stringify(e)}`); + }, + exit: (code: number, signal: string) => { + log(`[NITRO]::Debug: Nitro process exited with code ${code} and signal ${signal}`); + }, + message: ( + message: object, + sendHandle: net.Socket | net.Server | undefined, + ) => { + log(`[NITRO]::Debug: Nitro process message: ${JSON.stringify(message)}`); + }, + spawn: () => { + log("[NITRO]::Debug: Nitro process spawned"); + }, +}; // Default stdio handler: log stdout and stderr let processStdioHandler: NitroProcessStdioHanler = { stdout: (stdout: stream.Readable | null | undefined) => {