This commit is contained in:
Benjamin Toby
2025-02-22 14:55:26 +01:00
parent 85a64f85d6
commit 7bcddc9517
9 changed files with 33 additions and 53 deletions
+8 -5
View File
@@ -14,25 +14,28 @@ export default async function killChild(
if (!childProcess) return false;
try {
const childProcessPID = childProcess.pid;
childProcess.kill();
return true;
} catch (error: any) {
try {
if (typeof port == "object" && port?.[0]) {
for (let i = 0; i < port.length; i++) {
const singlePort = port[i];
await killPort(Number(singlePort), "tcp");
}
childProcess.kill();
return true;
} else if (port) {
await killPort(Number(port), "tcp");
childProcess.kill();
return true;
}
} catch (error) {}
} catch (_err) {}
return true;
} catch (error: any) {
console.log(
`${colors.FgRed}Error:${colors.Reset} Child Process couldn't be killed! ${error.message}`
);
return false;
}
}
+11 -19
View File
@@ -12,16 +12,16 @@ process.title = pTitle;
let timeout: any;
/**
* # Start the process
* @param {object} param0
* @param {string} param0.command
* @param {string[] | string} param0.preflight
* @param {string[] | string} [param0.postflight]
* @param {string} param0.redeploy_file
* @param {string | number | (string | number)[]} [param0.port] - The port to kill on rebuild
* @param {boolean} [param0.first_run] - Whether to run the preflight on first run. Default `false`
*/
type Param = {
command: string;
preflight?: string[] | string;
postflight?: string[] | string;
redeploy_file: string;
port?: string | number | (string | number)[];
first_run?: boolean;
debounce?: number;
};
export default function startProcess({
command,
preflight,
@@ -30,15 +30,7 @@ export default function startProcess({
port,
first_run,
debounce,
}: {
command: string;
preflight?: string[] | string;
postflight?: string[] | string;
redeploy_file: string;
port?: string | number | (string | number)[];
first_run?: boolean;
debounce?: number;
}) {
}: Param) {
const DEBOUNCE = debounce || 1000;
try {